[vc_row][vc_column width=”1/1″][vc_tour][vc_tab title=”Introduction ” tab_id=”1394169112-1-4″][vc_column_text]Pulse-width modulation (PWM), or pulse-duration modulation (PDM), is a modulation technique that conforms the width of the pulse, formally the pulse duration, based on modulator signal information. Although this modulation technique can be used to encode information for transmission, its main use is to allow the control of the power supplied to electrical devices, especially to inertial loads such as motors. In addition, PWM is one of the two principal algorithms used in photovoltaic solar battery chargers,[1] the other being MPPT.
The average value of voltage (and current) fed to the load is controlled by turning the switch between supply and load on and off at a fast pace. The longer the switch is on compared to the off periods, the higher the power supplied to the load is.
The PWM switching frequency has to be much faster than what would affect the load, which is to say the device that uses the power. Typically switchings have to be done several times a minute in an electric stove, 120 Hz in a lamp dimmer, from few kilohertz (kHz) to tens of kHz for a motor drive and well into the tens or hundreds of kHz in audio amplifiers and computer power supplies.
The term duty cycle describes the proportion of ‘on’ time to the regular interval or ‘period’ of time; a low duty cycle corresponds to low power, because the power is off for most of the time. Duty cycle is expressed in percent, 100% being fully on.
The main advantage of PWM is that power loss in the switching devices is very low. When a switch is off there is practically no current, and when it is on, there is almost no voltage drop across the switch. Power loss, being the product of voltage and current, is thus in both cases close to zero. PWM also works well with digital controls, which, because of their on/off nature, can easily set the needed duty cycle.
PWM has also been used in certain communication systems where its duty cycle has been used to convey information over a communications channel.
[/vc_column_text][/vc_tab][vc_tab title=”Demo code” tab_id=”1394169112-2-4″][vc_column_text]
/****************************************** * * * * * * * * *******************************************/ #include <pthread.h> #include"gpio.h" #include"delay.h" #include"typedef.h" #define LED_PIN 1 #define PWM_PIN 0 #define SIGNAL_CYCLE 200//uS pthread_t ntid_pwm0; volatile unsigned char duty0; void GenerateOnePuls(int fd,bool High,float duty) { int timeLow; int timeHigh; if(duty >= 100)duty = 100; timeHigh = (int)(duty/100*SIGNAL_CYCLE); timeLow = SIGNAL_CYCLE - timeHigh; if(!High) { timeHigh = timeLow; timeLow = SIGNAL_CYCLE - timeHigh; } SetGpio(fd,HIGH); delay_us(timeHigh); SetGpio(fd,LOW); delay_us(timeLow); } void * Pwm0_thread_fun(void * arg) { int fd_pin_pwm0; int fd_mode_pwm0; GpoiInitial(&fd_pin_pwm0,&fd_mode_pwm0,PWM_PIN,OUTPUT); SetGpio(fd_pin_pwm0,LOW); while (1) { GenerateOnePuls(fd_pin_pwm0,TRUE,duty0); } return (void *)0; } int main(int argc,char **argv) { int err; BOOL led_on; int fd_pin_led; int fd_mode_led; duty0 = 1; GpoiInitial(&fd_pin_led,&fd_mode_led,LED_PIN,OUTPUT); err = pthread_create(&ntid_pwm0, NULL, Pwm0_thread_fun, NULL); if (err != 0) { printf("%s\n", strerror(err)); } while(1) { delay_ms(100); duty0 += 1; if(duty0 >= 100)duty0 = 1; led_on = !led_on; SetGpio(fd_pin_led,led_on); } return 1; }
The source files can be downloaded from here.
[/vc_column_text][/vc_tab][/vc_tour][/vc_column][/vc_row]
Leave a Reply
You must be logged in to post a comment.