Microseconds are not ticks
Arduino C++setPWM(ch, on, off) takes ticks, not microseconds: at 50 Hz one tick is 20000 / 4096 µs. The starter sends 1500 as if it were µs, and forgets setPWMFreq(50) too. Write ticksFor() so 1500 µs becomes about 307 ticks, 600 about 123 and 2400 about 492, and set the frame to 50 Hz.
Checks
- Not run yetRuns
- Not run yetSets the frame to 50 Hz with setPWMFreq(50)
- Not run yet1500 µs comes out as 306-308 ticks
- Not run yet600 µs comes out as 122-124 ticks
- Not run yet2400 µs comes out as 490-493 ticks
- Not run yetChannel 0 sends a 1500 µs pulse in a 50 Hz frame
Hints
- ticks = us x 4096 / 20000. Multiply first, then divide, or the fraction is lost.
- 1500 x 4096 is over 6 million, too big for an int on a Nano: cast to uint32_t first.
- pwm.setPWMFreq(50); goes right after pwm.begin();