Double-edge triggered PWM
This notebook will be with information about a simple double-edge triggered PWM scheme.
By using double-edge triggered PWM it is possible to trigger one output for a specific time and then wait a while and then again trigger another output, and doing this again and again. I did this simply as I needed a PWM based H-bridge for my constant-current driver.
Have a look at the LPC1768 user manual for the registers http://www.nxp.com/documents/user_manual/UM10360.pdf
The code:
#include "mbed.h" PwmOut myled(p23); PwmOut myled2(p25); int main() { myled.period(1); // Includes enables and magic stuff from the mbed side. // 24000 pr. ms in mr0 ie. 24 counts pr. uS in MR0 register. - Register manipulation LPC_PWM1->MR0 = 24*100; // 100 usek routine / 10khz LPC_PWM1->MR1 = 0; // set the pwm2 output high at this count LPC_PWM1->MR2 = 24*50; // set the pwm2 output low at this count LPC_PWM1->MR3 = 24*50; // set the pwm4 output high at this count LPC_PWM1->MR4 = 24*100; // set the pwm4 output low at this count LPC_PWM1->MR5 = 24*66; // Set PWM6 output high at this count LPC_PWM1->MR6 = 24*41; // Set PWM6 output low at this count LPC_PWM1->PCR |= 0x14; // 0x54 to include PWM6 output - PCR controls if the PWMs are single or double edge triggered LPC_PWM1->LER |= 0x1e; // 0x7E to include PWM6 output for control - LER Latch enable register for latches between PWM outputs // Hereafter we do nothing at all with but while forever. while(1) { wait_ms(20); } }
This code will output a 50 percent square wave on pins p23 and p25. This can be changed with the registers. Look at the comments, you will get the idea (Phoo)....
If anyone want a library, and I have the time, I will go ahead and write one.
Lerche
Please log in to post comments.