I'm trying to drive a 12V LED with an arduino acting as an encoder: a PWM signal with 80% duty cycle ("1" symbol is +5v for the 80% of the time, 0v for 20% of the bit-time) . Testing the maximum frequency supported by the cricuit/driver/led, I get a bit-time of 1/1500 sec-1 with a cyclic message 101010... Above that frequency the led begins to blink. I wonder what should be improved to get a bit-time of 1/5000 = 200 nano sec. The circuit from Joost Damad is attached. Arduino LED Driver
I found two issues that were affecting the response of the circuit: - The CSHUNT (capacitor in parallel with the LED) that should act as ripple filter didn't allow to follow correctly the PWM. So I removed and now works as I was expecting: - While encoding with digitalWrite() and delayMicroseconds() I was printing the iteration Serial.println(): this was making extra delays that were also affecting the output PWM. - I tested now in the range of my requirements and it works fine: Bit_time= 166 usec, including a 95% duty cycle. That means 8 usec RTZ and the circuit responds fine
When using the Arduino analogWrite() method, the PWM signal generated by an Arduino Uno on pins 5 or 6, for example, has a period of a little more than a ms (1.02048ms).
This quote from here describes this in detail:
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.
Changes in the PWM duty cycle by calling the Arduino's analogWrite() method near, at the same speed or exceeding the speed of the PWM signal will likely cause unexpected results.