Module CCP1 as PWM signal generator

This  example  illustrates  the  use  of  CCP1  module  in  PWM  mode.  To  make  things  more interesting,   the  duration   of  the  P1A  output  pulses  (PORTC,2)   may  be  changed  using pushbuttons  symbolically  marked as ‘DARK’ and ‘BRIGHT’,  while the set duration is seen as binary combination on port B. The operation of this module is under control of the functions belonging to the specialized PWM Library. Three of them are used here:
1.               PWM1_init has                 the                 prototype: void Pwm1_Init(long freq);
Parameter  freq  sets  the  frequency  of  PWM  signal  expressed  in  herz.  In  this  example  it amounts to 5kHz.
2.               PWM1_Start has the prototype: void Pwm1_Start(void);
3.               PWM1_Set_Duty  has           the           prototype: void Pwm1_Set_Duty(unsigned short duty_ratio);
Parameter duty_ratio sets pulse duration in pulse sequence.
The  PWM  library  also  contains  the PWM_Stop function   used  to  disable  this  mode.  Its prototype is: void Pwm1_Stop(void);

In order to make this example work properly, it is necessary to tick off the following libraries in the Library Manager prior to compiling:

§                    PWM
§                    Button



0 komentar: