PIC12F683 has a built-in PWM module. The PWM output (CCP1 pin) is multiplexed with GPIO.2 (pin 5). So the TRISIO<2> bit must be cleared to make the CCP1 pin an output.
The objective of this experiment is to control the speed of a DC motor with an input from a potentiometer. This will be achieved in two steps:
- Read analog value (potentiometer output) through AN0 channel and generate a PWM wave at CCP1 pin (5) with duty cycle proportional to the analog value.
- Feed the PWM to motor driver transistor and observe the speed.
mikroC library routines for PWM
PWM1_Init
PWM1_Set_Duty
PWM1_Start
PWM1_Stop
Since PWM1_Set_Duty library function takes duty cycle input as an 8-bit integer, the digital value of analog signal, which is 10-bit, must be converted to 8-bit first. This will give 256 speed levels (0-255).
Experimental Setup
Connect POT2 output to pin 7 (AN0) of PIC12F683 and pin 5 (CCP1) to the input of motor driver transistor.