PDA

View Full Version : Parallax Propeller for a time



HobbyCoder
01-11-2009, 05:32 AM
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[INT] := In
DirA[Q1] := Out
DirA[Q2] := Out
DirA[Q3] := Out
DirA[Q4] := Out
Repeat 500
if (InA[INT] = 1)
DirA[17] := Out
OutA[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

grasshopper
01-11-2009, 05:42 AM
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[On_Off_Switch]~ ' Make it an Input
CheckButton ' Check button pub


Pub CheckButton | Button

Button~ 'Clear button variable
Button := Ina[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 Rowntree
01-11-2009, 05:59 AM
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

HobbyCoder
01-11-2009, 06:09 AM
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

grasshopper
01-11-2009, 06:10 AM
Let us know if it is Pulled high or pulled low. I can make your code work if I know what it is.

HobbyCoder
01-11-2009, 06:25 AM
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[INT]~
DirA[Q1] := Out
DirA[Q2] := Out
DirA[Q3] := Out
DirA[Q4] := Out
Repeat 500
if (InA[INT] == 1)
DirA[17] := Out
OutA[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

John Abshier
01-11-2009, 06:35 AM
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

grasshopper
01-11-2009, 06:35 AM
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[INT]~ ' Make an Input
DirA[17]~~ ' Make an output
DirA[Q1]~~ ' Make an output
DirA[Q2]~~ ' Make an output
DirA[Q3]~~ ' Make an output
DirA[Q4]~~ ' Make an output

Repeat 500
IF(InA[INT] == 0) 'Since it is already high look for a low
!OutA[17]
WaitCnt(40_000_000 + Cnt) 'ONE-HALF SECOND WAIT





Make sure your switch is right looks strange.

HobbyCoder
01-11-2009, 06:51 AM
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 Baker
01-11-2009, 07:01 AM
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 (mailto:pbaker@parallax.com)

Bob Lawrence (VE1RLL)
01-11-2009, 07:26 AM
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 (http://www.parallax.com/Portals/0/Downloads/docs/prod/prop/Web-PELabsFunBook-v1.0.pdf)

▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Aka: CosmicBob

StefanL38
01-12-2009, 02:23 AM
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