I'm doing a project and I need the microcontroller (ATmega328) to do these two things:
- Generate a rectangular wave to be filtered and obtain a DC voltage (that varies linearly with the duty cycle)
- Generate a square wave (50% duty cycle) with a certain period
The micro will be reading its input pins constantly because the DC voltage and the period needed can change at any moment.
I had thought of doing the first one with PWM and the second one manually setting an output pin or clearing it, counting the period with a timer. However, my question is: can these two things be done together?
I'm thinking that in the code, the microcontroller will be able to follow a routine at a time. So how could I generate these two waves simultaneously (if possible)? If it can be done, could two different PWMs output be used to generate two different signals instead of using a timer and generating the second one manually?