PDA

View Full Version : simple newb question



PICMAN
- 4th February 2005, 04:31
ok, i designed a circut with a bs2, now im converting to a pic 16f84a,, originally i hoped to learn to use this programer i got online, with suplied ic prog, programing in hex, then i found pic basic,

ive managed to do every thing i need to basically except designate up to 4 input lines, basically im taking a signal sent to a servo,, jumping it onto a pic 16f84a,, apon an imput going high, it will cause the pic to run a sub routine till the servo is zero'd,

i need to know how to designate an io line to input,, and if im runining this input off of one of the servos wires, will i need to do any thing so the signal sent to activate the servo doesnt fry the chip,,
AND if i used the signal that causes movement in the servo,, will it draw enough curent off the servo to effect its operation,

if you havent guessed it im designing a pair of digitally activated turn signals for a remote controll car, to get away from switch activated ones that rarley work, 2 io lines for turn signals, and 2 for the brake lights, ( steering has a servo , as does the carborator) a few months ago i breadboarded this on a bs2, had it all programed,, just never actually made the conection betwen the servo and the bs2, can any of you veteran pic basic buffs tell me if my therory is sound and how to designate a pin to be input

Acetronics2
- 4th February 2005, 15:46
Hippicman,

Have a look here :

http://www.rcgroups.com/forums/forumdisplay.php?f=199


You could get all the hardware info you need.

See i.e. Mr CAM's projects.

I already saw what you intend to realise ... very good help !!!

Alain

mister_e
- 4th February 2005, 16:56
i need to know how to designate an io line to input,, and if im runining this input off of one of the servos wires, will i need to do any thing so the signal sent to activate the servo doesnt fry the chip,,
AND if i used the signal that causes movement in the servo,, will it draw enough curent off the servo to effect its operation,


To set the pin direction (input or output) you can use TRIS or INPUT & OUTPUT statement

TRIS:
=====
TRISB=%11110000 ' Set PORTB<7:4> as input. PORTB<3:0> as output

TRISB.0=1 ' Set PORTB.0 as input

INPUT & OUTPUT :
===============
INPUT PORTB.0 ' Set PORTB.0 as input

OUTPUT PORTB.1 ' Set PORTB.1 as output

IMHO, it's quicker to use TRIS in one shot and place comment on the right edge

If you need to monitor the signal from the motor, be sure the voltage is bellow 5 volt.

You'll need a external chip driver, MOSFETs, Transistor to drive your Motor. PIC can drive/sink a maximum of 25ma.

Welcome to the PICmicro world. Smart move from you guy!

PICMAN
- 4th February 2005, 20:07
thats the exact line i needed steve thnx man, since im reverse engenering this, it helps me to have the comand, then i research it, with out having the comand theres simly too much to look threw to find the right comand, appreaciate the replies, thnx for your time :)

PICMAN
- 4th February 2005, 20:27
ok this code is checking how to check if servo input is high or low, and assumes ill need only one wire input ( which i know i will need 2,, but is this how i call an if then sttement off that input?)

do

trisb.0=1 ' sets input for servo signal
symbol rled = PORTB.1 ' BIND OUTPUT TO RB1

if b.0 = 1 then ' if servo input is high
rled = 1 ' right side led on
pause 250 ' pause 1/4 second
rled = 0 ' right side led off
pause 250 'pause off

if b.0 = 0 then ' if servo signal is low
lled = 1 'left side led on
pause 250 'pause 1/4 sec
lled = 0 ' left led off
pause 250 'pauses off for 1/4 sec

else

rled = 0 ' right leds off
lled = 0 ' left leds off

endif

loop

PICMAN
- 4th February 2005, 20:41
just relized the botom of your post mr, ,

its a gas truck,, no motor, i plan to run this same deal off the throttle servo,, if its pos, ( or giving the carb gass) no brake lights, the same servo also runs a ceramic brake disc and caliper,, so if its negitive the brake is engaged,,, and jualla brake ights come on, my ocncerns for ma rating,, was drawing a splice off two of the three servo wires coming from the reciever box, i think im corect in saying a simple resistor on the input line should cause no more curent then needed to go hi or low will be taken off the servo line enabling the servo to still work with a minute amount of its current drawn off to actualize the signals,, both the reciever and all servos and ic board will be run off a nicad pack,, so i assume the physics of this will alow the signal to be read off the pic,,
as i said i built it and tested operation with out cuting into the actual servo,, wasnt wiling to pay 50 bucks for a bs2 to prouduce it, so i waited to test till i build the prototype for this model, my dad a seasond electronics major said my therories work, so i wasnt to woried about testing it b 4 proceding, at worst ,, ill build a reciever around it and negate the one in the car :P

mister_e
- 4th February 2005, 21:03
I change some things in your code




trisb.0=1 ' sets input for servo signal
ServoInput VAR PORTB.0

trisb.1 = 0 ' Set RB1 as output
rled VAR PORTB.1 ' BIND OUTPUT TO RB1

trisb.2 = 0 ' set RB2 as output
lled VAR PORTB.2

' PS : we can also define TRIS in one shot
' TRISB = 1
' in the above, only B0 is an input

Start:

rled = 0 ' right leds off
lled = 0 ' left leds off

Select Case ServoInput
Case 1
rled = 1 ' right side led on
pause 250 ' pause 1/4 second
rled = 0 ' right side led off
pause 250 'pause off

Case 0
lled = 1 'left side led on
pause 250 'pause 1/4 sec
lled = 0 ' left led off
pause 250 'pauses off for 1/4 sec
end select

goto start

mister_e
- 4th February 2005, 21:07
ORRRRRRR




TRISB = 1

ServoInput VAR PORTB.0
rled VAR PORTB.1 ' BIND OUTPUT TO RB1
lled VAR PORTB.2

PORTB=0 ' turn leds off

Start:

if ServoInput then ' same as If ServoInput=1 then
rled = 1 ' right side led on
pause 250 ' pause 1/4 second
rled = 0 ' right side led off
pause 250 'pause off
Else
lled = 1 'left side led on
pause 250 'pause 1/4 sec
lled = 0 ' left led off
pause 250 'pauses off for 1/4 sec
endif
goto start

mister_e
- 4th February 2005, 21:12
And now for your input stuff, you can use a simple 10K - 22K resistor in serie for sure. OR use a 7.5K in serie + 5.1K resistor to the ground as a voltage divider. It ensure to have a better "ground" or "0" reading.

In another hands, i still don't understand why those BasicStamp are still on the market. To Expensive for what we can do with...

PICMAN
- 4th February 2005, 21:21
so is there a benifit to using select case rather then if then, i mean like less words used etc. im gonna go ahead and study how you wrote it,, im guessing since you chose that way , theres a reason ,,,

mister_e
- 4th February 2005, 21:32
I just reedit both code .. i did mistakes .. O.K now.

Well USUALLY SELECT CASE is use when you have multiple condition. In this case only two. The IF THEN will take less code space and do the same job.

PICMAN
- 4th February 2005, 21:56
awsome man , again thank you for your time,,

PICMAN
- 5th February 2005, 03:10
ok just thought of this,,

the circut this is all goin on is in a remote controll truck, when i toggle the switch to the on position for the radio equipment and servos, theres a bit of a spike threw the system sending the servo arm to jerk a bit , ( if you toggle it back and forth about 5 times the arm is in full to one extreme, ie all the way right)

now im wondering,, is it actually a spike in curent,, or just noise,,

in either case,, the pic needs a boot time if im correct,, perhaps an immediate jolt wouldnt be a good idea,, (since the servo curent is directly to b.0,,) to fix boot time, i could just put ic circut b4 switch,, but again ,, im still wondering if the reciever sends out a spike,, or just noise causeing movement


in electric cars,, the same occurs, and can prouduce a slight jerk outta the car,, keep in mind this is a pretty hevy curent draw motor,, but again could be noise outta the reciever,,, causeing the speed controll to ive out a short burst,

mister_e
- 5th February 2005, 03:16
mmmm.. let's assume that the "noise" will be less than 1 seconde



TRISB = 1

ServoInput VAR PORTB.0
rled VAR PORTB.1 ' BIND OUTPUT TO RB1
lled VAR PORTB.2

PORTB=0 ' turn leds off
PAUSE 1000 'boot delay
Start:

if ServoInput then ' same as If ServoInput=1 then
rled = 1 ' right side led on
pause 250 ' pause 1/4 second
rled = 0 ' right side led off
pause 250 'pause off
Else
lled = 1 'left side led on
pause 250 'pause 1/4 sec
lled = 0 ' left led off
pause 250 'pauses off for 1/4 sec
endif
goto start


And the time you do the LED blink (500ms) can be enough to avoid some glitchs from servo motor.