Jump to content


  • Content Count

  • Joined

  • Last visited

Reputation Activity

  1. Like
    Santosh333 reacted to bobnova in analogWrite() precision question   
    @@altineller not really, no. It's something of a hidden function.
    You have to include wiring_analog.c (#include <wiring_analog.c>) to kick things off. That includes the PWMWrite function.
    Then you can call it thusly:   PWMWrite(PIN,numberOfSteps,dutyCycle,frequency);
    For example:   PWMWrite(PD_1,500,250,6000);
    Would start PWM on pin PD_1, 500 steps from 0 to 100%, 50% duty cycle (500 / 2 = 250), 6000Hz frequency.
    It's worth noting that the function call does glitch when you call it on a pin already putting PWM out. It's not enough to hear driving a speaker, but it could cause you issues if you're calling it a lot. There's a thread around here somewhere on that subject.
    The frequency cap is very high, if I recall correctly I'd tested it to work >1MHz. I could be thinking about a different MCU, I've tested sort of a lot of them.
  • Create New...