Step 3Driving the SMPS with a Microcontroller
We already know the required rise time from our previous calculations: 13.5uS. TB053 suggests that rise time be 75% of the period. I determined my period value by multiplying the rise time by 1.33: 17.9uS. This is consistent with the suggestion in TB053 and ensures that the inductor stays in discontinuous mode – discharging completely after each charge. It is possible to calculate a more exact period by adding the calculated rise time to the calculated fall time, but I have not attempted this.
Now we can determine the actual duty cycle and period values to enter into the microcontroller to get the desired time intervals. In the Microchip PIC Mid-range manual we find the following equations (http://ww1.microchip.com/downloads/en/DeviceDoc/33023a.pdf ):
PWM Duty Cycle uS =(10 bit Duty Cycle Value) * (1/ oscillator Frequency) * Prescaler
If we set prescaler to 1 and beat this equation with an algebra stick we get:
10 bit Duty Cycle Value = PWM Duty Cycle uS * Oscillator Frequency
Substitute the Duty Cycle uS for calculated rise time, and assume a 8 Mhz oscillator frequency:
107 = 13.5uS * 8Mhz
107 is entered into the PIC to get a duty cycle of 13.5uS.
Next, we determine the PWM Period Value. From the Mid-Range Manual we get the following equation:
PWM period uS = ((PWM period value) + 1) * 4 * (1/oscillator frequency) * (prescale value)
Again, we set prescaler to 1 and harass the equation for PWM period value, giving us:
PWM period value = ((PWM Period uS/(4/Oscillator frequency))-1)
Substitute Period uS for (1.33*rise time), and assume a 8 Mhz oscillator frequency:
35= ((17.9/(4/8))-1)
35 is entered into the PIC to get a period of 17.9uS. But wait! Isn't the period shorter than the duty cycle? No - PICs have a 10 bit duty cycle register and a 8 bit period register. There is more resolution for the duty cycle value, thus its value will sometimes be larger than the period value - especially at high frequencies.
All of these calculations are implemented in "Table 2. PWM Calculations" of the spreadsheet included with this instructable. Several example coils are entered.
| « Previous Step | Download PDFView All Steps | Next Step » |
![]() |
Add Comment
|











































