PDA

View Full Version : Checking Inputs with a seperate cog



JMLStamp2p
01-30-2008, 04:29 AM
Good Evening,
I am trying to start a new cog to constantly look at inputs and run certain Methods contingent upon with Pin went High. I am working with Pin-7
at the moment and also have it pulled Low through a resistor and a push button to send it high. For some reason I can't get both cogs "Full_Duplex_Serial" and the "Button_Down" cog to Blink the LED's at the same time. With the code as is, Pins 16 & 23·are Blinking and it appears that my code is not correct in my Botton_Down Method. Could someone gve me some advise ?
.................................................. ...............................................
CON
·_CLKMODE = XTAL1 + PLL8X····
·_CLKFREQ = 40_000_000········

VAR
·long Stack[9], Temp
·
OBJ
·DELAY: "Clock"
·DATA: "FullDuplexSerial"
.................................................. .................................................. ...
PUB Main
·cognew(Button_Down(21), @Stack)········'Start new cog to handle the
·················································· ············'Button_Down Method
·dira[7]~
·dira[21]~~
·dira[19]~~

·data.Stop········· ·'Stop any outside process using the Full_Duplex_Serial Cog
·data.start(1,0,2,9600)····················· 'Set up Serial through FullDuplexSerial
·Recieve·········································· ············ ·'Call to my Recieve Method
.................................................. ..................................................
·································
PUB Button_Down(Pin)

·Temp := INA[7]
·repeat While Temp := 0
·· !outa[Pin]········································ 'Toggle Pin 21
·· waitcnt(40_000_000 + cnt)

·repeat While Temp :=·1
···!outa[Pin]········································ 'Toggle Pin 21
·· waitcnt(40_000_000 + cnt)

.................................................. ..................................................

PUB Recieve | rxbyte··································

· repeat
··· rxbyte := data.rx

··· if rxbyte == 1················································· ·····
····· Data_Recieved_1
····
··· if rxbyte == 4············
····· Data_Recieved_4
.................................................. .................................................. ..
·········
PUB Data_Recieved_1
· dira[16]~~
····· outa[16]~~
······· waitcnt(3_000_000 + cnt)
········· outa[16]~
·········· waitcnt(3_000_000 + cnt)
··········· data.rxflush
············ Recieve
.................................................. ..................................................
············
PUB Data_Recieved_4
· dira[23]~~

····· outa[23]~~
······· waitcnt(3_000_000 + cnt)
········· outa[23]~
·········· waitcnt(3_000_000 + cnt)
·········· data.rxflush
············ Recieve
.................................................. ..................................................

Mike Green
01-30-2008, 04:41 AM
When you start a separate cog, you also get a separate DIRA register which is initialized to zero (inputs).
You need to move the "DIRA[ Pin ]~~" to the start of the "Button_Down" method.

Nick Mueller
01-30-2008, 06:01 AM
And this code:



repeat While Temp := 0



certainly doesn't do what you intended.


Nick

▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Never use force, just go for a bigger hammer!

The DIY Digital-Readout for mills, lathes etc.:
YADRO (http://www.yadro.de)

JMLStamp2p
01-30-2008, 06:33 AM
Thank You Mike for your help, and Nick could you give me an example of what would. New to the Prop :>)
Thanks,
JMLStamp2p

Gerry Keely
01-30-2008, 06:44 AM
I think what you need is

·"repeat while ina[7] == 0"

This will continually scan pin 7 also note the use of == when testing for equality(not :=)



Regards



Gerry

JMLStamp2p
01-30-2008, 08:06 PM
Thanks Gerry...
JMLStamp2p