lol alright thanks. I really apreciate your help mister_e. I must have missed your post about the resistors when I was responding. I'll try it in the morning. Thanks again.
lol alright thanks. I really apreciate your help mister_e. I must have missed your post about the resistors when I was responding. I'll try it in the morning. Thanks again.
No problem. Good night !!!
Steve
It's not a bug, it's a random feature.
There's no problem, only learning opportunities.
In conventional design, you would never apply your +5v to your switch. The +5v should NEVER leave your PCB, or be connected to any unnescessary component. It's valuable, you don't want to corrupt it, or add noise to it, because it could affect the operation of your PIC.
A better connection would be to have the COMMON of your switch going to Vss (0v), with either side to your PIC pins as before. You then only need a SINGLE Pull-UP resistor on each pin going to +5v. 10K is a good value.
The control logic is then INVERTED... ie the pin goes LOW when there's a switch on it... eg...
TRISB.5=1
TRISB.7=1
Loop:
If PortB.5=0 then goto DriveForward
If PortB.7=0 then goto DriveReverse
Goto Loop
Since you're experimenting, why not dispsense with the external Resistors and invoke the INTERNAL WEAK PULL-UPS that exist on PortB?
TRISB.5=1
TRISB.7=1
OPTION_REG.7=0
Loop:
If PortB.5=0 then goto DriveForward
If PortB.7=0 then goto DriveReverse
Goto Loop
Look in the PICs Datasheet to find the OPTION Register to see what that instruction does.
A better connection would be to have the COMMON of your switch going to Vss (0v), with either side to your PIC pins as before. You then only need a SINGLE Pull-UP resistor on each pin going to +5v. 10K is a good value.
On the switch its three prong. The middle prong is going to ground. The one side of it is going to PORTB.5 and the other side is going towards PORTB.7. You said put a Pull-UP resisor on the ones going to PORTB.5 and PORTB.7. That makes sense, but you said going to +5v? I don't understand that... Can you please clairfy, thanks.
This is my current code
@ DEVICE pic16F628, INTRC_OSC_NOCLKOUT ' system clock options
@ DEVICE pic16F628, WDT_ON ' watchdog timer
@ DEVICE pic16F628, PWRT_ON ' power-on timer
@ DEVICE pic16F628, MCLR_OFF ' master clear options (internal)
@ DEVICE pic16F628, BOD_ON ' brown-out detect
@ DEVICE pic16F628, LVP_OFF ' low-voltage programming
@ DEVICE pic16F628, CPD_OFF ' data memory code Protect
@ DEVICE pic16F628, PROTECT_OFF ' program code protection
include "modedefs.bas"
UP VAR PORTB.5
DOWN var PORTB.7
FM VAR PORTB.2
POSITION var word 'Position value
VELOCITY var word 'Average velocity value
FUNCTION var word 'Function register
I var byte 'Loop variable
T9600 con 2
LF con 10 'Linefeed ASCII value
TRISB.5 = 1
TRISB.7 = 1
'OPTION_REG.7 = 0
'WRITE command to FUNCTION register, and enable velocity limit mode
'
serout FM, T9600, ["W01 03 64", CR, LF] 'Enable velocity limit mode
pause 100
serout FM, T9600, ["R01 03", CR, LF]
pause 20
MAIN:
IF UP = 0 THEN
serout FM, T9600 ,["W01 01 200", CR, LF] 'Write velocity limit value
serout FM,T9600,["P01 270000", CR, LF] 'Send MOVETO_ABSOLUTE command
ENDIF
IF DOWN = 0 THEN
serout FM, T9600 ,["W01 01 200", CR, LF] 'Write velocity limit value
serout FM,T9600,["P01 0", CR, LF] 'Send MOVETO_ABSOLUTE command
ENDIF
goto MAIN
End
I am not using the internal resistors. I am using external 10k ones on the PORTB.5 and PORTB.7 lines
P.S. Will someone teach me how to do the code tag!
Each side of the switch goes to the Port pin. There is a Resistor, one end on the Port pin, the other is nailed to +5v. That's why they are called Pull-UP - they pull UP to +5v when the pin is unused. When you close the switch, it drops the pin voltage to 0v.
Melanie,
I am sorry for my newby-ness (new word). I am not an Electrical Engineer just a highschool student working on a summer project.
Right now i have the center of the switch going to ground. Then the sides of the switch going through a 10k ohm resistor, then to PORTB.5 and PORTB.7 respectively. I also have a 5 volt bus. Does anything have to be connected to it? Like a jumper from PORTB.5|7 to 5 volt as well?
Bookmarks