Tuesday, 17 March 2015

arduino - Use PWM and ISR at same time on AVR


Is it possible to use AVR PWM outputs and ISR interrupts at the same time? I've got a project I'm trying to do on an ATMega328P and I need 3 PWM outputs but ALSO need to be able to use ISR interrupts from two different timers to do some other multiplexing and button handling (oh yeah, also need to use INT0 and INT1 external interrupts).


Is there a way to do both?


Update for clarification: Here's the full setup. I have 3 RGB LEDs for which I need PWM for each of their channels. This PWM can run at the same frequency but needs independent duty cycles for each channel so that I can create any color I need. Since the ATMega328P doesn't have 9 independent PWMs I need to fake it. So my plan was to use multiplex the PWM. Basically, set PWM for RGB1, switch to RGB2, and then RGB3 all at > 400 Hz. That way I only need 3 PWM channels on the chip and can just toggle which LED is being grounded (they are common cathode). So, I need an ISR interrupt to handle the multiplexing itself and then I usually use a lower frequency (~ 100 Hz) ISR interrupt to handle button presses (basically my way of doing debouncing, I find it quite effective). So, as you can see, I need 3 PWM channels and 2 ISRs.




No comments:

Post a Comment

arduino - Can I use TI's cc2541 BLE as micro controller to perform operations/ processing instead of ATmega328P AU to save cost?

I am using arduino pro mini (which contains Atmega328p AU ) along with cc2541(HM-10) to process and transfer data over BLE to smartphone. I...