Hi,
I'm playing with a project that uses the Ardino Nano to drive a couple of independent PWM signals along with some periodic serial communications for monitoring of the remaining digital pins.
To start with I set up the monitoring loop for digital pins as this looked like the easiest thing to do, and everything worked as expected. I then commented out the code and started work on the timers.
First I set up Timer 2 to create drive Pin D3 at 4KHz at 50% duty. After much tinkering I got everything to work as expected
After that it was fairly easy to set up Timer 0 to drive Pin D5 at 100Hz at 5% duty.
Thinking everything was working as expected, I uncommented the code for the monitoring loop, but for some reason the polling loop is now running very slowly (the serial comms baud rate is uneffected). Commenting out the code for Timer 0 returns the monitoring loop to its usual speed.
My monitoring loop does have a couple of delay statements just to sync things up. I'm left wondering if setting up the timer has effected them.
I should also say that I'm not keen on using Timer 1 for the PWM output because I'm using pins D6 to D13 (specifically including D9 and D10) for digital input.
Timer 0 is used to generate the interrupt for the millis() counter, which is used by delay() and various other code. < edit > looks like delay uses micros
A quick experiment show me that a '500ms' delay is now taking a curious amount of time. Some times it's 5 seconds, sometimes it about a second. I'm guessing this is because of duty cycle I've got on that pin.
Is there a way of re-routing that ISR to use Timer1 for delay or should I try to use D9 for the PWM output?
You would need to re-write the code for millis() and micros(), and possibly other code.
That doesn't sound fun!
I was planning on using D3 and D5 for PWM output, the remaining digital pins for input and the analog pins for digital out.
I'm now thinking that I might have either use an external PWM source, or more likely use Timer 1 for PWM out and swap over D5 and D9. Is that reasonable? Does timer 1 have a special purpose (the documentation I found only described timers 0 and 2)
Hi David, B707,
Thank you so much for the info - without it I wouldn't have known what to do. I'm going to have to do some juggling with the digital pins on my project, which is a bit of a shame. I have 8 signals I want to read into a byte, but the PWM output is going to have to sit right in the middle of those pins. Still the software can be flexible.