Skip to content

LED driver forward control PWM

Pekka Nikander edited this page Jun 3, 2013 · 4 revisions

The buck converter used in the design requires a minimum PWM frequency of 50 kHz. You can freely use lower frequencies, but you must also use lower duty percentages. If you have a too long duty period, it will cause the coil to burn, or perhaps the power LED. (In the present design, it is relatively hard to burn any other components but the coil and perhaps the power LED.) As higher frequencies are harder to control with software, we recommend to use the 50 kHz as the initial frequency, and consider using higher frequencies once the software works and there is some understanding of the CPU load and interrupt latencies.

This example code assumes the following ELL-i pin assignments:

  • PWM output on [Arduino D5](Expansion headers) (STM32F051 PA7), Timer 14 Channel 1

This pin was selected in order to have an independent Timer/Counter channel, thereby causing the least amount of interference with possible other functions.

static const int PWM = 5;

setup() {
   setPWMFrequency(PWM, 50000, 8);  // 50 kHz frequency, 8 bits resolution
}

/*
 * Alter the duty periodically from zero to 5% and back
 */ 
loop() {
   for (int i = 0; i < 13; i++) {
      analogWrite(PWM, i);
      delay(10);
   }
   for (int i = 13; i > 0; i--) {
      analogWrite(PWM, i);
      delay(10);
   }
}

Clone this wiki locally