Hi, I'm currently using analogWrite to control DC motor speed, however, when applied PID to control more precise, the default 8bit PWM is not enough, so I need to use at least 10 bit PWM. As i'm using pin6, pin 7 and pin 8 on arduino mega 2560 to control, I believe that they are all on the same timer 4 and available of up to 16bit PWM. Are there any examples and tutorial online about this ? Thanks.
Excellent tutorial here: https://gammon.com.au/timers
CTC mode allows you to choose the bit depth.
I'd choose any 16 bit PWM mode and, if required, use ICR for the TOP value (0xFFFF). Then the 3 related PWM channels are free for use on a Mega. Please note that the duty cycle always ranges from 0 to TOP, not 0 to 100%.
1 Like
This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.