Configured to generate a pwm using a sine function. For the complementary pwm for h-bridge you may invert it by hardware and connect it to a IR2110 in order to provide a dead time on turn on
Fork of Inverter_epusalle by
main.cpp
00001 /* Power electronics usalle*/ 00002 00003 #include "mbed.h" 00004 00005 00006 #ifndef M_PI 00007 #define M_PI 3.14159265358979323846 00008 #endif 00009 00010 // Number of samples to generate sine pattern 00011 #define SINE_STEPS 100 00012 // Pwm period in us 00013 #define PWM_PERIOD 20 00014 00015 00016 DigitalOut myled(LED1); 00017 PwmOut CH1(PWM_OUT); 00018 00019 00020 00021 // dc : duty cycle 00022 // n: a sample 00023 // T: Time in microsecond the sine_dc function is evaluated 00024 // 1/PWM_PERIOD defines the conmutation frequency (default 50kHz) 00025 // T divided by PWM_PERIOD defines the number of pwm cycles for each sine term sample (default 8.3) 00026 // T times SINE_STEPS defines sine modulation period 00027 00028 /* This program calculates values of a sine 00029 function and splits them up in 100 points, these points are then written 00030 to the duty cycle of the pwm signals. 00031 */ 00032 Ticker interrupt; 00033 InterruptIn button(USER_BUTTON); 00034 int n; 00035 double dc_min = 0.0, dc_max = 1.0; 00036 void sine_dc() { 00037 double dc, sine_term; 00038 n = n + 1; 00039 if(n == SINE_STEPS) n = 0; 00040 sine_term = sin(2*M_PI*n/SINE_STEPS); 00041 // Convert sine term to duty cycle: if sine_term == 0, then dc = 0.5 00042 if (sine_term > 0) dc = 0.5 + (sine_term * (dc_max - 0.5)); 00043 if (sine_term < 0) dc = 0.5 + (sine_term * (0.5 - dc_min)); 00044 if (sine_term == 0) dc = 0.5; 00045 CH1.write(dc); 00046 } 00047 00048 int main() { 00049 int T = 166; 00050 n = 0; 00051 CH1.period_us(PWM_PERIOD); 00052 CH1.write(0.5); 00053 00054 00055 00056 // 00057 interrupt.attach_us(&sine_dc, T); 00058 00059 while(1) { 00060 myled = !myled; 00061 wait(1); 00062 } 00063 } 00064
Generated on Sat Aug 20 2022 13:07:29 by 1.7.2