-
In the Arduino Servo library, all of the PWM pins are controlled through TC1. The stepper library uses TC2. In examples/uno-manual-servo.rs, one controls pin D9 through its register, as depicted in the atmega328p datasheets. See https://github.com/Rahix/avr-hal/blob/main/examples/arduino-uno/src/bin/uno-manual-servo.rs. and attached image. is it possible to control all PWM pins only using TC1? |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 3 replies
-
There is a fundamental difference between our PWM implementation and the one in the Arduino Servo library: While we use hardware PWM where the timer directly drives the output pin, the Servo library implements a software variant: A timer triggers an interrupt and the interrupt routine then toggles pins as needed. This is what allows them to control arbitrary pins as PWM signals (but limits the PWM frequency, which isn't a problem for Servo control). You could implement this by hand using However, in the long run, it would of course be nice to provide a library/crate similar to the Arduino Servo one which takes care of all the underlying details behind this. It's a bit tricky to implement such a library due to the need of defining an interrupt routine and due to |
Beta Was this translation helpful? Give feedback.
There is a fundamental difference between our PWM implementation and the one in the Arduino Servo library: While we use hardware PWM where the timer directly drives the output pin, the Servo library implements a software variant: A timer triggers an interrupt and the interrupt routine then toggles pins as needed. This is what allows them to control arbitrary pins as PWM signals (but limits the PWM frequency, which isn't a problem for Servo control).
You could implement this by hand using
avr-hal
, by manually setting up the timer and interrupt as needed. See https://github.com/Rahix/avr-hal/blob/main/examples/arduino-uno/src/bin/uno-millis.rs for some timer code.However, in the long run, …