Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

help with the waveform generation

Status
Not open for further replies.

Asadkh21

Junior Member level 1
Junior Member level 1
Joined
Oct 13, 2013
Messages
16
Helped
1
Reputation
2
Reaction score
1
Trophy points
3
Visit site
Activity points
119
CN0125_01_1024.gif

I need help with the waveform generation at the two LEDs using any code/IC/MCU or anything. Need details


Untitled.png


What could possibly be the circuit that results in the following timing...
 

This waveform could be generated by almost any MCU. My favorite is the Microchip PIC line. I would use a PIC 12F1822, using the internal oscillator, assuming the timing requirements are not ultra-strict. Use instruction timing to generate the appropriate delays between output changes. With this MCU, each instruction takes exactly one instruction cycle, except for transfer of control instructions, which take two cycles. It would be easy to measure out the 250 usec. between output changes using NOP instructions or small time-wasting loops.
 
I am using ATmega 32. Can you help with the sample code ? C or Assembly ?
 

Your code should be a timer - then 4 stages of number comparison, so if number = 0, first red led is on, if number = 2 IR led is on, if number = 4 start again. . . Fiddle with the timer constants to get your speed correct.
Frank
 
I am using ATmega 32. Can you help with the sample code ? C or Assembly ?
ATmega32 is overkill for this task, unless you already need an MCU for other functions, in which case this function will have to be implemented in a timer interrupt service routine, along the lines of what chuckey suggested. You would have to have the timer interrupt firing every 250 usec., which might be a problem if your other functions in this MCU require disabling interrupts for more than a few usec, or if you already have an interrupt service routine that takes a considerable length of time.

My idea was to dedicate an MCU to this one waveform-generation function, doing nothing else. Then the in-line code could generate the waveforms quite easily, using instruction timing. If you prefer Atmel products, use a 6-pin tinyAVR instead of an ATmega32.
 
My idea was to dedicate an MCU to this one waveform-generation function, doing nothing else. Then the in-line code could generate the waveforms quite easily, using instruction timing. If you prefer Atmel products, use a 6-pin tinyAVR instead of an ATmega32.

Thank you for the help. I would like to implement your idea of using another separate microcontroller. Atmel products do not bound me so I am free to use anything what is handy and easy to program. I am new to C language but have experience with Assembly. Please offer me a suggestion with microcontroller whose circuit is minimum to build on Vero Board and also easy to program again and again on assembly (or probably C).
Any more help with the minimum circuit schematic (with USB ISP programmer configuration) would save my time.
 

Thank you for the help. I would like to implement your idea of using another separate microcontroller. Atmel products do not bound me so I am free to use anything what is handy and easy to program. I am new to C language but have experience with Assembly. Please offer me a suggestion with microcontroller whose circuit is minimum to build on Vero Board and also easy to program again and again on assembly (or probably C).
Any more help with the minimum circuit schematic (with USB ISP programmer configuration) would save my time.
If you are going to follow my suggestion and use instruction timing to generate these waveforms, then you probably want to do it in assembly, not C. If you use C there is less certainty about the number of actual instructions that are generated by any particular C statement. Also, the job is so simple, there is no need for C. The program is so simple:

Set Output 1 High
waste some time
Set Output 1 Low
waste some time
Set Output 2 High
waste some time
Set Output 2 Low
waste some time
go back to the top

The "waste some time" lines can be either a series of NOOP instructions, or a loop that wastes some time using a downcounter. If you want real duty cycle precision you should take all instruction times into account, including the ones that set the outputs and the jump and the end that goes back up to the top.

As for which micro to use, I think just about any of the small ones would work. It helps if they are simple so that every instruction takes the same length of time (except possibly for jumps which probably take longer because of flushing the instruction fifio). If you want minimal circuitry and can tolerate a frequency error of about 1%, then look for micros that have an option to run on an internal RC oscillator - no crystal needed. The PIC micro that I suggested needs no circuitry around it all, except for the usual power supply bypass cap and maybe a reset generator chip if the power might turn on slowly. Some micros have built-in brown-out reset that makes the reset generator chip unnecessary.
 
If you are going to follow my suggestion and use instruction timing to generate these waveforms, then you probably want to do it in assembly, not C. If you use C there is less certainty about the number of actual instructions that are generated by any particular C statement. Also, the job is so simple, there is no need for C. The program is so simple:

Set Output 1 High
waste some time
Set Output 1 Low
waste some time
Set Output 2 High
waste some time
Set Output 2 Low
waste some time
go back to the top

The "waste some time" lines can be either a series of NOOP instructions, or a loop that wastes some time using a downcounter. If you want real duty cycle precision you should take all instruction times into account, including the ones that set the outputs and the jump and the end that goes back up to the top.

As for which micro to use, I think just about any of the small ones would work. It helps if they are simple so that every instruction takes the same length of time (except possibly for jumps which probably take longer because of flushing the instruction fifio). If you want minimal circuitry and can tolerate a frequency error of about 1%, then look for micros that have an option to run on an internal RC oscillator - no crystal needed. The PIC micro that I suggested needs no circuitry around it all, except for the usual power supply bypass cap and maybe a reset generator chip if the power might turn on slowly. Some micros have built-in brown-out reset that makes the reset generator chip unnecessary.

Well after some work I constructed this Code.
KIndly guide me how close I am to the desired waveform.
The delay subroutine wasts around 230us. ( I am close)
Please make corrections to the code as one of the LED is not lighting up while the other is quite ok.


INCLUDE "TN13DEF.INC"
LOOP:
LDI R16,0xFF
OUT DDRB,R16
LDI R16,Ob00001000
OUT PORTB,R16

CALL DELAY

LDI R16,0xFF
OUT DDRB,R16
LDI R16,Ob00000100
OUT PORTB,R16

CALL DELAY

JMP LOOP

DELAY:
LDI R17,0xFF

AGAIN:
NOP
NOP
NOP
NOP
NOP
NOP
DEC R17
BRNE AGAIN
RET
 

int AuxCounter = 0;
//
// this function should be called each 250ms
// , suppose you have 2 functions available : redled(value) and irled(value) , where value can be LED_ON or LED_OFF
//
void timer250ms(void)
{
AuxCounter = (AuxCounter + 1)%9; // loopint from 0 to 8
switch(AuxCounter)
{
case 0:
case 4:
LedRed(LED_ON);
break
case 1:
case 5:
redled(LED_OFF);
break;
case 2:
case 6:
irled(LED_ON);
break;
case 3:
case 7:
irled(LED_OFF);
break;
}
}
 

Status
Not open for further replies.

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top