Shop OBEX P1 Docs P2 Docs Learn Events
Parallax Propeller for a time — Parallax Forums

Parallax Propeller for a time

HobbyCoderHobbyCoder Posts: 8
edited 2009-01-11 19:23 in Propeller 1
Greetings,

I have been using a Parallax Propeller for a time, however... I have encountered an issue with determining the state of a push button. I am pretty sure this is a software issue at this point, not a hardware issue. The push button is called INT.

'                                             EMS
'
'                                   Energy Management System
'**************************************************************************************
'Summary: This is a home energy management system.
'**************************************************************************************
'File: EMS.spin
'**************************************************************************************
'Correct Function: This system should control energy distribution
'**************************************************************************************
'
CON
  _clkmode = xtal1 + pll16x
  _xinfreq = 5_000_000
  High = 1
  Low  = 0
  Out = %1
  In = %0
'
VAR
  Byte INT 'Interrupt Pin
  Byte Q1  'Quandrant 1 Pin
  Byte Q2  'Quandrant 2 Pin
  Byte Q3  'Quandrant 3 Pin
  Byte Q4  'Quandrant 4 Pin
  Byte A1  '(TEMP) Arg 1
  Byte A2  '(TEMP) Arg 2
  Byte A3  '(TEMP) Arg 3
'
PUB Start
  INT := 1
  Q1 := 2
  Q2 := 3
  Q3 := 4
  Q4 := 5
  A1 := 0
  A2 := 0
  A3 := 0
  'DirA[noparse][[/noparse]INT] := In
  DirA[noparse][[/noparse]Q1] := Out
  DirA[noparse][[/noparse]Q2] := Out
  DirA[noparse][[/noparse]Q3] := Out
  DirA[noparse][[/noparse]Q4] := Out
  Repeat 500
    if (InA[noparse][[/noparse]INT] = 1)
      DirA[noparse][[/noparse]17] := Out
      OutA[noparse][[/noparse]17] := High
    WaitCnt(5_000_000 + Cnt) 'ONE-HALF SECOND WAIT
  End
'

PRI End

'
'INDENTION IS IMPORTANT IN SPIN: There are no ENDIFs, END REPEATs, END SUB, etc.



How do I make sure that it only turns on pin 17 when the button is down?
EDIT: to specify, the issue is that the code believes that the button is always down.

Post Edited By Moderator (Joshua Donelson (Parallax)) : 10/23/2009 4:51:13 AM GMT

Comments

  • grasshoppergrasshopper Posts: 438
    edited 2009-01-10 22:42
    Well depending on whether your button has a pull up or a pull down resistor you'll need to make the input read the change.

    Con 
      On_Off_Switch = Pin 19 'what ever pin the switch is on
    
    Pub main 
     dira[noparse][[/noparse]On_Off_Switch]~  ' Make it an Input
     CheckButton               ' Check button pub
    
    
    Pub CheckButton | Button
     
      Button~                       'Clear button variable
      Button := Ina[noparse][[/noparse]On_Off_Switch] 'Store the state of the button as the variable "Button"
             
      IF (Button == 1)       ' This will have to change if you haev a pull up or pull down 
            {{do someting here}}     
            {{Like}}
            Reboot
    
    
    



    Hope this helps.
  • Paul RowntreePaul Rowntree Posts: 49
    edited 2009-01-10 22:59
    Grasshopper is right, you have to say how the switch is wired. Note that the 5_000_000 is the crystal frequency, but the clock is running at 80_000_000/sec because of the PLL16x. A waitcnt(5_000_000+cnt) is going to wait for less than 0.1 second, not 0.5sec. Plus, the comparison operator is ==, not =. If you want Pin17 to reflect the switch, then you must wait for INT to drop back to 0, then make pin17 match it.

    Or why not just continually copy the input of INT out to Pin17 (or the logical inverse, depending on how the switch is wired)?

    Cheers!
    Paul Rowntree
  • HobbyCoderHobbyCoder Posts: 8
    edited 2009-01-10 23:09
    At the moment, I am using pin 17 to light an LED for logic testing. Later on it will interrupt the entire code and begin a totally different task then it will complete otherwise. But, thanks for the info... I will be testing it momentarily
  • grasshoppergrasshopper Posts: 438
    edited 2009-01-10 23:10
    Let us know if it is Pulled high or pulled low. I can make your code work if I know what it is.
  • HobbyCoderHobbyCoder Posts: 8
    edited 2009-01-10 23:25
    Ok, I have modified the code to the following. The issue persists.
    '                                             EMS
    '
    '                                   Energy Management System
    '**************************************************************************************
    'Summary: This is a home energy management system.
    '**************************************************************************************
    'File: EMS.spin
    '**************************************************************************************
    'Correct Function: This system should control energy distribution
    '**************************************************************************************
    '
    CON
      _clkmode = xtal1 + pll16x
      _xinfreq = 5_000_000
      High = 1
      Low  = 0
      Out = %1
      In = %0
    '
    VAR
      Byte INT 'Interrupt Pin
      Byte Q1  'Quandrant 1 Pin
      Byte Q2  'Quandrant 2 Pin
      Byte Q3  'Quandrant 3 Pin
      Byte Q4  'Quandrant 4 Pin
      Byte A1  '(TEMP) Arg 1
      Byte A2  '(TEMP) Arg 2
      Byte A3  '(TEMP) Arg 3
    '
    PUB Start
      INT := 1
      Q1 := 2
      Q2 := 3
      Q3 := 4
      Q4 := 5
      A1 := 0
      A2 := 0
      A3 := 0
      DirA[noparse][[/noparse]INT]~
      DirA[noparse][[/noparse]Q1] := Out
      DirA[noparse][[/noparse]Q2] := Out
      DirA[noparse][[/noparse]Q3] := Out
      DirA[noparse][[/noparse]Q4] := Out
      Repeat 500
        if (InA[noparse][[/noparse]INT] == 1)
          DirA[noparse][[/noparse]17] := Out
          OutA[noparse][[/noparse]17] := High
        WaitCnt(40_000_000 + Cnt) 'ONE-HALF SECOND WAIT
      End
    '
    
    PRI End
    
    '
    'INDENTION IS IMPORTANT IN SPIN: There are no ENDIFs, END REPEATs, END SUB, etc.
    



    Since this is an interrupt button, i want it to be high when pushed. I think that is how I have it set up. I have attached a relatively high resolution image of the current configuration.

    Post Edited (HobbyCoder) : 1/10/2009 11:34:40 PM GMT
    2304 x 1728 - 1M
  • John AbshierJohn Abshier Posts: 1,116
    edited 2009-01-10 23:35
    Int = 1 but the switch is wired to pin 0. You don't need wires to both VDD and VSS.

    I would read the propeller education labs. These lessons wire up switches and read them.

    John Abshier
  • grasshoppergrasshopper Posts: 438
    edited 2009-01-10 23:35
    Try this
    CON
      _clkmode = xtal1 + pll16x
      _xinfreq = 5_000_000
      
      High = 1
      Low  = 0
    
    VAR
      Byte INT 'Interrupt Pin
      Byte Q1  'Quandrant 1 Pin
      Byte Q2  'Quandrant 2 Pin
      Byte Q3  'Quandrant 3 Pin
      Byte Q4  'Quandrant 4 Pin
      Byte A1  '(TEMP) Arg 1
      Byte A2  '(TEMP) Arg 2
      Byte A3  '(TEMP) Arg 3
    '
    PUB Start
    
      INT := 1
      Q1 := 2
      Q2 := 3
      Q3 := 4
      Q4 := 5
      A1 := 0
      A2 := 0
      A3 := 0
      
      DirA[noparse][[/noparse]INT]~ ' Make an Input
      DirA[noparse][[/noparse]17]~~ ' Make an output 
      DirA[noparse][[/noparse]Q1]~~ ' Make an output
      DirA[noparse][[/noparse]Q2]~~ ' Make an output
      DirA[noparse][[/noparse]Q3]~~ ' Make an output
      DirA[noparse][[/noparse]Q4]~~ ' Make an output
      
      Repeat 500
        IF(InA[noparse][[/noparse]INT] == 0) 'Since it is already high look for a low      
            !OutA[noparse][[/noparse]17]
            WaitCnt(40_000_000 + Cnt) 'ONE-HALF SECOND WAIT
        
    
    



    Make sure your switch is right looks strange.
  • HobbyCoderHobbyCoder Posts: 8
    edited 2009-01-10 23:51
    Ok, thank you for all the help. It appears that the issue was in fact, at the software level (although i did make one modification to the circuitry.) I had forgotten to add a statement to disable the led if the button was not depressed. Again, thank you for trying to help.
  • Paul BakerPaul Baker Posts: 6,351
    edited 2009-01-11 00:01
    Don't use 2 resistors, that creates a voltage divider. Instead have a resistor to ground to supply the unpressed voltage and straight to Vdd for when the button is pressed.

    PS. edit your first post and add a subject liine.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Paul Baker
  • Bob Lawrence (VE1RLL)Bob Lawrence (VE1RLL) Posts: 1,720
    edited 2009-01-11 00:26
    You can download this PDF (PE labs fun Book) and go to page 33 to view the schematic for wiring a button.

    www.parallax.com/Portals/0/Downloads/docs/prod/prop/Web-PELabsFunBook-v1.0.pdf

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Aka: CosmicBob
  • StefanL38StefanL38 Posts: 2,292
    edited 2009-01-11 19:23
    Hello Hobbycoder,

    as you seem to have to learn about electronics I recommend before connecting a circuit to the propeller
    to check it with a digi-multimeter voltages AND current flowing through the circuit.

    Especially flowing to that wire that is connected to the Propeller-IO-Pin.
    You have to connect it to +3.3V and check it AND to connect it to ground=0V

    If you define an input-pin accidently as an output pin the output could be switched to HIGH= 3.3V and Ground=0V
    In both cases the current should stay below 30mA. Otherwise you are in danger to fry your propellerchip

    best regards

    Stefan
Sign In or Register to comment.