All the pwm-pins on my Uno are occupied and I would like to use timer 1 or 2 to set up a timer interrupt to resolve some timing issues. I have learned that using timers cause losing pwm-pins, since the timers are also used for generating pwm-signals by the analogWrite function.
Does using a timer indeed results in loosing pwm-pins?
Or is the pwm-functionality disturbed?
Are there any workarounds (red something on adjusting pwm-frequencies)?
Note 1: At this moment I use the PWM-pins for controlling
the speed of my four Rover motors (all independently controlled for mecanum purposes
an URM37 (US distance sensor)
a serial servo contrtoller
Note 2: All the other digital pins at the Uno are occupied as well.
Note 3: I have expanded my project with a pin expander MCP23016 on which some digital pins are still available. Can I use them for example "to generate my own PWM", or is that unwise?
Neither the US sensor, nor, the serial servo controller require PWM. Move them the the expander, rearrange things so you can free up a timer, and, viola. Smart people will reply to you soon enough.
You are right about the You are right about the serial controller but the URM needs a pwm pin on the Uno for reading it’s output.
I also have some analog pins available. I consider using one of them for the URM. Fed URM pwm signal to a low pass RC filter and attach the filter output to an analog input on the Uno. Could that work?
When I looked over the manual for the URM sensor, I saw a pin that was PWM out. The PWM pins on the arduino are also output. If you are reading from the PWM pin, you don’t need to use a PWM pin on the microcontroller. I can imagine requiring some form of interrupt to read it properly in a non blocking way.
I could be completely off base on what I think I read and understood. By all means set me straight.
You are correct. Arduino PWM pin is an output function
The URM37 supplies a PWM IN which can be read on any Digital pin (analog pins as well in digital mode) using the pulseIn() function.
It appears though that MOST implementations use the Serial interface of the URM37… apparently there is more funtionality like temperature readings that can be used this way…
Thanks for your comments. I thought I had a challenge, but there is less damage than expected. I will rearrange my pins so that the “URM incomming pin” and the “serial servo controller output pin” are #3 and #11 (the pins whose PWM capabilities are killed by timer2). It appears that neither pin needs to be a PWM pin, so no problem there.
It is my understanding that timers only affects the “PWM features” and that the I can use the concerning pins as “a normal” digital pin. Is that correct?
I have the servo controller running at digital pin #3 (and stays there and uses the SoftwareSerial library to enabale serial communication (hardware serial interface is used for the remote of the Rover)