- Código:
//motor CD con PWM
int16 vel;
void main()
{
setup_adc_ports(AN0);
setup_adc(ADC_CLOCK_INTERNAL|ADC_TAD_MUL_0);
setup_timer_2(T2_DIV_BY_4,124,1); //500 us overflow, 500 us interrupt
setup_ccp1(CCP_PWM|CCP_PWM_FULL_BRIDGE|CCP_SHUTDOWN_AC_L|CCP_SHUTDOWN_BD_L);
set_pwm1_duty((int16)248);
while(TRUE)
{
vel=(int16)(read_adc());
set_pwm1_duty(vel);
if(input(PIN_B0))
setup_ccp1(CCP_PWM|CCP_PWM_FULL_BRIDGE); //CW clock wise
else
setup_ccp1(CCP_PWM|CCP_PWM_FULL_BRIDGE_REV); //CCW clock contrary wise
}
}
- Simulación en Proteus:
- Armado y ejecución:
No hay comentarios:
Publicar un comentario