Imagine a dial that you turn to control the duty cycle you talked about and the dial is just a potentiometer with resistance mapped to AnalogWrite range (0-255). Now imagine the analog range mapped to percentage duty cycle so "0" is min and "255" is max.
The analogWrite argument is just a value within a range that is later converted to a duty cycle percentage by the uC.
Ok.. The 255 steps from the fact that 0 counts as one of the allowed values which total to 256?
And.. is this correct that each step is 2.55% , or do you mean 100%/255 steps =0.392%/step
What about the frequency? It is lock at 980 Hertz.. And there are a lot of instruction going on in the microcontroller. Therefore, isn't a 1 step just getting too close to the device clocking limits?
Sorry about the line of questionings. But I am building an optical device engine 100% with Arduino. It need a lot of precision and will like to understand that the realistic limitations are between the memory latency , speed and instruction.
jecalderon:
Ok.. The 255 steps from the fact that 0 counts as one of the allowed values which total to 256?
And.. is this correct that each step is 2.55% , or do you mean 100%/255 steps =0.392%/step
0.392%/step
What about the frequency? It is lock at 980 Hertz.. And there are a lot of instruction going on in the microcontroller. Therefore, isn't a 1 step just getting too close to the device clocking limits?
The analogWrite function is utilizing one of the three internal hardware timers in the AVR 328P chip, so once a duty cycle value is sent to the function the actual PWM is all done continuously and independently of the program, so no real effect on the rest of program performance.
Sorry about the line of questionings. But I am building an optical device engine 100% with Arduino. It need a lot of precision and will like to understand that the realistic limitations are between the memory latency , speed and instruction.
jecalderon:
Ok.. The 255 steps from the fact that 0 counts as one of the allowed values which total to 256?
The values total to 256, so as zero is included, you only have 255 steps "on". So the counter must be counting 255 steps, not 256. Each one of those 255 steps might be on or off, a zero PWM value means all are off, and a 255 PWM value means all are on. But there cannot be a 256th step in the count.
raschemmel:
It sounds like you could benefit from reading this .
Tells you about which timers do what, but not how they count. That would be in the 328 datasheet.
The frequency of the PWM signal on most pins is approximately 490 Hz. On the Uno and similar boards, pins 5 and 6 have a frequency of approximately 980 Hz. Pins 3 and 11 on the Leonardo also run at 980 Hz.