to make your back and forth stuff, if your motor don't need much current, it will be easier to use a H-Bridge driver IC like NJM2670 or else.
By using 2 i/o, you'll be able to do it easy...
will look something like this
Code:
TRISA = 255 ' set PORTA as input
TRISB=0 ' set PORTB as output
Motor1_a var PORTB.0
Motor1_b var PORTB.1
PushButtonForward var PORTA.0 ' Push button connected
PushButtonReverse var PORTA.1 ' between vcc and PIC pin
PushButtonStop Var PORTA.2
PORTB=0
Start:
If PushButtonForward then
Motor1_a = 1
Motor1_b = 0
endif
If PushButtonReverse then
Motor1_a = 0
Motor1_b = 1
endif
If PushButtonStop then
Motor1_a = 0
Motor1_b = 0
endif
goto start
to measure the distance you'll have to use rotary encoder, opto devices or something who will provide you some pulses when motor/wheel is turning. By counting those pulse in background (on RA4 pin using internal Timer/Counter module) you'll have some numbers to do your maths
For the speed...it's up to you... some will use PWM, some will vary the voltage accross the motor and probably there's many other way to do it... food for brain cells ;o]
Last edited by mister_e; - 12th February 2005 at 16:06.
Steve
It's not a bug, it's a random feature.
There's no problem, only learning opportunities.
Bookmarks