Re: Some questions on motor speed control

Originally Posted by
joseph Degorio
Hi everyone,
I'm starting to explore on motors specifically on 12v DC motor. Basically first I want to make it stop, turn it half speed and full speed using 10K resistor on PortA.0. Can I apply the following code from markedwards?
Code:
ADCIN 1,AD1 'read channel 1...AN1
AD1 = AD1 >> 6 'justify data
ADJUSTFAN:
IF AD1 < 2 then FANSPEED = 153 '60% min speed
IF AD1 >= 3 then SPEED = 178 '70%
IF AD1 >= 5 then SPEED = 204 '80%
IF AD1 >= 7 then SPEED = 229 '90%
IF AD1 >= 9 then SPEED = 255 '100%
IF SPEED > SPD THEN SPD = SPD + 1 'accelerate
IF SPEED < SPD THEN SPD = SPD - 1 'de-accelerate
hpwm 2,SPD,32760 ' PWM 20,000 Hz
As I understand I need a pic that support HPWM, please forgive me if this may sound very basic but how I connect the assigned port pin to the motor?
I have tried using L298N, which I can stop, turn cwise and ccwise the motor, can I also control the speed and can anyone show simple code how to do this?
Thanks in advance,
joe
I am not sure about the logic of the code.
But a very easy way of having the control of a motor by analog pin (with a pot) should be like:
Code:
ADCIN 0, CCPR1L ' Read Pot, and put the result directly to PWM register. Assuming 8-bit adc reading.
Why don't you first try to see the result of this one line of code and then go on?
"If the Earth were a single state, Istanbul would be its capital." Napoleon Bonaparte
Bookmarks