Điều khiển động cơ bằng PWM
Mình thử làm 1 mạch dk động cơ trên Proteus để test thử hoạt động của PWM.
Không rõ code sai ở đâu mà khi chạy thử, dù đã set duty cho pwm1 = 0 mà chân C2 vẫn có tín hiệu ra và động cơ vẫn quay.
Nếu mình thay 0 bằng 1 giá trị khác tốc độ quay động cơ vẫn không thay đổi.
Mọi người xem giúp thử với. Thanks.
void main()
{
setup_adc_ports(NO_ANALOGS);
setup_adc(ADC_OFF);
setup_psp(PSP_DISABLED);
setup_spi(SPI_SS_DISABLED);
setup_timer_0(RTCC_INTERNAL|RTCC_DIV_1);
setup_timer_1(T1_DISABLED);
setup_timer_2(T2_DISABLED,0,1);
setup_comparator(NC_NC_NC_NC);
setup_vref(FALSE);
output_low(PIN_C2); // Set CCP1 output low
output_low(PIN_C3); // Set CCP2 output low
output_high(PIN_C4); // Enable ENA
output_low(PIN_C5); // Disable ENB
setup_ccp1(CCP_PWM); // Configure CCP1 as a PWM
setup_ccp2(CCP_PWM); // Configure CCP2 as a PWM
setup_timer_2(T2_DIV_BY_16, 255, 1);
while(1){
set_pwm1_duty(0);
}
}
|