Shop OBEX P1 Docs P2 Docs Learn Events
Beginner button problem — Parallax Forums

Beginner button problem

CyrussCyruss Posts: 19
edited 2011-03-06 04:38 in Propeller 1
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!"))

Comments

  • Mike GreenMike Green Posts: 23,101
    edited 2011-02-28 12:18
    You've got your button hooked up wrong! Connect P5 to the point between the button and the 10K resistor. Leave the other end of the button connected still to 3.3V.
  • Clive WakehamClive Wakeham Posts: 152
    edited 2011-02-28 12:27
    Cyruss wrote: »
    Hi everybody!

    repeat until ina[5]

    lcd.gotoxy(0,1)
    lcd.str(string("Switch activated!"))

    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.
  • CyrussCyruss Posts: 19
    edited 2011-02-28 12:59
    Hi Mike Green

    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?
    1024 x 683 - 91K
  • CyrussCyruss Posts: 19
    edited 2011-02-28 13:06
    Hi Clive!

    Tried the Repeat While command instead. The same thing happens though. Like it just jumps past it right away.
  • CyrussCyruss Posts: 19
    edited 2011-02-28 13:16
    Got it working! But only when i plugged out the Stepper motor controller. Any suggestions as to why? Does the stepper create alot of "crawling current"? (do not know what it's called in english) Attaching some pics, if that is any help.
    1024 x 1536 - 142K
    1024 x 683 - 98K
  • PliersPliers Posts: 280
    edited 2011-03-01 11:34
    If it works without the stepper connected, then you are having noise problems.
    You will need to rework the circuit to solve this.
    Try a .1uf cap from P5 to common?
  • Mike GreenMike Green Posts: 23,101
    edited 2011-03-01 11:44
    Yes, the stepper can create a lot of electrical noise. It's difficult to tell from the information you have provided how you have things wired and laid out. Clearly you have high power leads very close to the Propeller and its circuitry and I don't see any filtering on the supply voltage to the Propeller. There are two 3.3V and two ground connections on the Propeller package. You must have at least one 0.1uF filter capacitor across each pair of 3.3V / ground pins as close as possible to the chip socket. You also need a larger electrolytic capacitor nearby. Something like 10uF should be adequate, also across the 3.3V supply.
  • CyrussCyruss Posts: 19
    edited 2011-03-02 13:25
    Hi, thanks for all the replies!
    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) :)
    1024 x 683 - 91K
    1024 x 683 - 74K
    1024 x 683 - 64K
  • PliersPliers Posts: 280
    edited 2011-03-02 17:21
    The volt meter will not show your problem.
    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 StablerGraham Stabler Posts: 2,510
    edited 2011-03-03 03:14
    You could write a little program to count pulses on the pin and output to a terminal window, if it is noisy you are going to get a lot of pulses measured. The various capacitors should help.

    Graham
  • CyrussCyruss Posts: 19
    edited 2011-03-03 10:18
    Hi there Graham Stabler, i tried that i while ago width a keypad program. I must say that width the stepper controller on i have a nice randomizer :thumb:
    Seems like the input gets a lot noise.
  • CyrussCyruss Posts: 19
    edited 2011-03-03 12:56
    Tried to attach these between 3.3V and GND on both sides on the prop chip. No, difference on the symptoms though. Are these the right kind to use? http://octopart.com/ck06bx104k-kemet-971698

    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!
    1024 x 683 - 38K
  • SapiehaSapieha Posts: 2,964
    edited 2011-03-03 13:12
    Hi Cyrus.

    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 ?

    Cyruss wrote: »
    Tried to attach these between 3.3V and GND on both sides on the prop chip. No, difference on the symptoms though. Are these the right kind to use? http://octopart.com/ck06bx104k-kemet-971698

    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!
  • CyrussCyruss Posts: 19
    edited 2011-03-03 13:36
    Bor i Sundsvall :)

    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
  • SapiehaSapieha Posts: 2,964
    edited 2011-03-03 14:07
    Hi Cyruss.

    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.


    Cyruss wrote: »
    Bor i Sundsvall :)

    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
  • PliersPliers Posts: 280
    edited 2011-03-03 15:23
    Have you tried adding a small capacitor (.1uf or .01uf) at the terminal block where your switch leads are?
    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.
  • CyrussCyruss Posts: 19
    edited 2011-03-03 21:49
    Attaching The Board layout. Top view.

    Of to work!!! and looking for capacitors :cool:
    1024 x 819 - 55K
  • PliersPliers Posts: 280
    edited 2011-03-04 03:19
    my mistake.
  • SapiehaSapieha Posts: 2,964
    edited 2011-03-04 06:37
    Hi Cyruss..

    propboard2.jpg


    Cyruss wrote: »
    Attaching The Board layout. Top view.

    Of to work!!! and looking for capacitors :cool:
    819 x 603 - 68K
  • CyrussCyruss Posts: 19
    edited 2011-03-04 09:14
    Thanks for the drawing Sapieha!

    Are the two in the upper left corner the same type? both 100nF Capacitors?

    /Lars
  • SapiehaSapieha Posts: 2,964
    edited 2011-03-04 09:19
    Hi Cyruss.

    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.


    Cyruss wrote: »
    Thanks for the drawing Sapieha!

    Are the two in the upper left corner the same type? both 100nF Capacitors?

    /Lars
  • CyrussCyruss Posts: 19
    edited 2011-03-05 00:02
    Ok!

    Time to do some soldering....

    let you know later how it works out.

    /Lars
  • CyrussCyruss Posts: 19
    edited 2011-03-05 07:40
    IT WORKS!!! :D

    Thank you!
  • CyrussCyruss Posts: 19
    edited 2011-03-06 03:15
    How do you change the thread so it lists as solved?
  • SapiehaSapieha Posts: 2,964
    edited 2011-03-06 04:38
    Hi Cyruss.

    You need start EDIT-Advanced Yours First post.
    Only in it You can change status.


    Cyruss wrote: »
    How do you change the thread so it lists as solved?
Sign In or Register to comment.