Beginner button problem
Cyruss
Posts: 19
Hi everybody!
I'm really new to the prop chip. I have been doing some of the Educations labs from the site.
I'm having some problems with the button example. It acts as if the button is always pressed...
Please, i would really appreciate some help!
Have it connected like this:
3.3 V
|
v
button --> 10 kohm --> GND
|
---> P5
Code:
PUB Testtest
waitcnt(80_000_000 + cnt)
lcd.cls
lcd.gotoxy(0,0)
lcd.str(string("Waiting for switch!"))
repeat until ina[5]
lcd.gotoxy(0,1)
lcd.str(string("Switch activated!"))
I'm really new to the prop chip. I have been doing some of the Educations labs from the site.
I'm having some problems with the button example. It acts as if the button is always pressed...
Please, i would really appreciate some help!
Have it connected like this:
3.3 V
|
v
button --> 10 kohm --> GND
|
---> P5
Code:
PUB Testtest
waitcnt(80_000_000 + cnt)
lcd.cls
lcd.gotoxy(0,0)
lcd.str(string("Waiting for switch!"))
repeat until ina[5]
lcd.gotoxy(0,1)
lcd.str(string("Switch activated!"))
Comments
You have P5 pulled high to 3.3v and when the button is pressed it is brought to ground. Therefore the signal at P5 is always high until the button is pressed then its low. Unless I am mistaken high is classed as TRUE and the low as FALSE.
Your command"repeat until ina[5]" will drop through. I think you need the command "repeat while ina[5]" so it will stay at the command until you press the button.
I have it connected as you wrote in your reply. My little "drawing" didn't come out as i wanted it too. The thing is when i measure the volt on P5 when the switch isn't pressed i shows 0.07 V and then drops on the "Multimeter".
I'm attaching a picture of the switch "button" that i'm using. Connected to the BN (Brown) and BU (Blue)
Do i have to set the Dir of the P5 or something?
Tried the Repeat While command instead. The same thing happens though. Like it just jumps past it right away.
You will need to rework the circuit to solve this.
Try a .1uf cap from P5 to common?
I'm attaching some pics to try to explain how all is connected.
Today i set up a separate power supply for the Prop, to see if it would be any different reaction. Sadly there was no change. Well, ruled that out...
These filter capacitor that you mentioned in your reply is that the same that you where supposed to use when to setup the 9-pin com port connection to the BS2? If that is the case then i have some left over from that experiment. The symbol looks like this |-| ??
Noticed that even if i don't have any cables from the stepper driver connected to the prop board, it still gives me trouble. As long as it's powered and the cable from the stepper driver is connected to the stepper.
I also attached 2 pics when i'm measuring the volt on P5, one where the driver is turned on and one where it is turned off. Get the value of 0.03 - 0.02 V. (It toggled as i took the picture so it looks like a 9 that is upside down).
Let's see if i understood you correct. I'm to attach a 0.1uF between 3.3V and GND as close to the chip as possible, on both of them? Also attach a bigger nearby and on the power supply inlet, that also between 3.3V and GND?
Many thanks again!
/Lars
(good thing this automatic spell checker, gets my spelling a bit better)
The voltage spikes getting to your P5 are very short.
You need a good oscilloscope to see it.
The long leads going to your switch is acting like an antenna .
To prove this, use a switch located very close to your terminal strip.
Use short wires.
To solve your problem, I would try a .01 uf capacitor at the terminal strip.
Graham
Seems like the input gets a lot noise.
Thinking about installing shielded cables tomorrow. Read up a bit on Electrical noise and it is stated that it could be one of the problems i'm facing.
What i could not find while reading was if i'm to connect the shielding material in the cable to GND anywhere, on one side or on both. Anyone know this?
The electrolytic capacitor that Mike Green replied about earlier, the 10uF. The picture i'm attaching, is that the right kind. It says 50V, is that ok?
There are 2 of those attached to the prop board allready, but those are 6.3V 1000uF. They are hocked up between the power converters( >5V to 5V and 5V to 3.3V) and GND, I think.
Many questions, hope you have answers for some of them! Otherwise i'm going to get bald from all the headscratching. :blank:
Many thanks you all!
Only that ones cant help You.
You need to have at last 2x100nF Ceramic capacitors on both sides of Propeller.
Good practice are to have even one 100nF as near every IC as possible. That means EEProm AND REGULATOR IC's.
If You post Yours SCH I can Show You on it what places need 100nF capacitors. And as You RUN Stepper Motors You even need one 100nF and that one You show in last post As near stepper connector as possible.
Vart in Sweden bor ?
edit: like this one? http://www.elfa.se/elfa3~se_sv/elfa/init.do?item=65-656-59&toc=18793
I have drawn my board in CAD and i have only the routes and dots marked up. :frown: Can i post that?
Thanks for the reply! I will look in to that tomorrow after work. The 100nF that you wrote, is 100uF the same?? And does the V matter here or is that just the maximum V you can use on it?
About shielding the cables, should i give that a go or is it a waste of time?
Will post the code, if i've done something wrong there.
Don't give me to much of a beating for the code, beginner on this stuff :cool:
[code]
CON
_clkmode = xtal1 + pll16x
_xinfreq = 5_000_000
LCD_PIN = 13 ' for Parallax 4x20 serial LCD on P13
LCD_BAUD = 19_200
LCD_LINES = 4
INTERRUPT = 5 ' Switch on pin 5, connected width 1kohm in serie
sBasePin = 0 ' Base pin till stepper 0,1,2
Out = %1
In = %0
High = 1
Low = 0
OBJ
lcd : "debug_lcd"
kb : "keyboard"
Axis : "AxisDriver"
VAR
byte power
' byte break
byte diod
byte flash
long number
long talet
long talet2
long summa
long stack0[20]
long count
long avbryt
byte cog1
long temp
PUB start | i
dira[0] := Out ' pin 0,1,2 to out
dira[1] := Out ' to stepper
dira[2] := Out
dira[5] := In ' Pin 5 to switch
'Start stepper
Axis.Start(SBasePin) ' Start stepperdriver
power := 12 ' Start Power diod
DirA[power] := Out
OutA[power] := High
'Start LCD
lcd.init(LCD_PIN, LCD_BAUD, LCD_LINES) ' start lcd
lcd.cursor(0) ' cursor off
lcd.backLight(true) ' backlight on
lcd.cls ' clear the lcd
lcd.gotoxy(0,0)
waitcnt(40_000_000 + cnt) ' Waiting for lcd to start
lcd.str(string("Starting system...",13))
waitcnt(80_000_000 + cnt)
lcd.gotoxy(0,0)
lcd.cls
waitcnt(80_000_000 + cnt)
lcd.str(string("Press enter to start"))
lcd.cursor(3)
kb.start(16, 17) 'start the keyboard, pin 26 & 27
temp := 0
repeat 'V
Jag i Landskrona.
If You can post that ACAD drawing as Picture -- That is OK.
Yes it was that CAPACITORS 100nF. 100nF and 100uF are very big difference. V stands for maximum Voltage them can be used width.
"About shielding the cables, should i give that a go or is it a waste of time?" can give some help but not to much without Decoupling capacitors -- Many times that cables NEED even Ferrite-beds to CUT all parasitic transients.
It would take almost 5 seconds to install this Hardware solution.
A software solution would be to add a small loop in your program to ensure your switch signal stays high for .5 seconds before the main program accepts that signal.
Of to work!!! and looking for capacitors :cool:
Are the two in the upper left corner the same type? both 100nF Capacitors?
/Lars
NO
One are Ceramic -- that little disc
Second are that one You have in post #13 -- and be carefully as this ones are Polarity sensitive.
Time to do some soldering....
let you know later how it works out.
/Lars
Thank you!
You need start EDIT-Advanced Yours First post.
Only in it You can change status.