Asadkh21
Junior Member level 1
- Joined
- Oct 13, 2013
- Messages
- 16
- Helped
- 1
- Reputation
- 2
- Reaction score
- 1
- Trophy points
- 3
- Activity points
- 119
Follow along with the video below to see how to install our site as a web app on your home screen.
Note: This feature may not be available in some browsers.
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.I am using ATmega 32. Can you help with the sample code ? C or Assembly ?
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.
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: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.