This is a little demonstration of how to use the pwm library to controle the speed motor (but you can use it in many different ways).
the task:
Read an analogic commande from a potentiometre and transform it to commande the speed motor.
the code:
unsigned int commande=0;//the value delivred by the poteintiometre
unsigned int controle=0;//the puls width that commands the motor speed
void main() {
adc_init();//analogic to digital converter module initialisation
pwm1_init(10000);//Puls width modulation module initialisation with 10KHz
pwm1_set_duty(controle);//the motor is stopped
pwm1_start();
while(1){
commande=adc_read(0);//read anaolgic value from channel number 0
controle=(commande/4);//adapt the value of the control to the commande
pwm1_set_duty(controle);//update the value of the pulse width
}
}
simulation:
the task:
Read an analogic commande from a potentiometre and transform it to commande the speed motor.
the code:
unsigned int commande=0;//the value delivred by the poteintiometre
unsigned int controle=0;//the puls width that commands the motor speed
void main() {
adc_init();//analogic to digital converter module initialisation
pwm1_init(10000);//Puls width modulation module initialisation with 10KHz
pwm1_set_duty(controle);//the motor is stopped
pwm1_start();
while(1){
commande=adc_read(0);//read anaolgic value from channel number 0
controle=(commande/4);//adapt the value of the control to the commande
pwm1_set_duty(controle);//update the value of the pulse width
}
}
simulation:
enjoy :))
barak Allahou fik! :)
RépondreSupprimer