Checking Inputs with a seperate cog
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[noparse][[/noparse]9], Temp
·
OBJ
·DELAY: "Clock"
·DATA: "FullDuplexSerial"
.......................................................................................................
PUB Main
·cognew(Button_Down(21), @Stack)········'Start new cog to handle the
······························································'Button_Down Method
·dira[noparse][[/noparse]7]~
·dira[noparse][[/noparse]21]~~
·dira[noparse][[/noparse]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[noparse][[/noparse]7]
·repeat While Temp := 0
·· !outa[noparse][[/noparse]Pin]········································ 'Toggle Pin 21
·· waitcnt(40_000_000 + cnt)
·repeat While Temp :=·1
···!outa[noparse][[/noparse]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[noparse][[/noparse]16]~~
····· outa[noparse][[/noparse]16]~~
······· waitcnt(3_000_000 + cnt)
········· outa[noparse][[/noparse]16]~
·········· waitcnt(3_000_000 + cnt)
··········· data.rxflush
············ Recieve
....................................................................................................
············
PUB Data_Recieved_4
· dira[noparse][[/noparse]23]~~
····· outa[noparse][[/noparse]23]~~
······· waitcnt(3_000_000 + cnt)
········· outa[noparse][[/noparse]23]~
·········· waitcnt(3_000_000 + cnt)
·········· data.rxflush
············ Recieve
....................................................................................................
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[noparse][[/noparse]9], Temp
·
OBJ
·DELAY: "Clock"
·DATA: "FullDuplexSerial"
.......................................................................................................
PUB Main
·cognew(Button_Down(21), @Stack)········'Start new cog to handle the
······························································'Button_Down Method
·dira[noparse][[/noparse]7]~
·dira[noparse][[/noparse]21]~~
·dira[noparse][[/noparse]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[noparse][[/noparse]7]
·repeat While Temp := 0
·· !outa[noparse][[/noparse]Pin]········································ 'Toggle Pin 21
·· waitcnt(40_000_000 + cnt)
·repeat While Temp :=·1
···!outa[noparse][[/noparse]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[noparse][[/noparse]16]~~
····· outa[noparse][[/noparse]16]~~
······· waitcnt(3_000_000 + cnt)
········· outa[noparse][[/noparse]16]~
·········· waitcnt(3_000_000 + cnt)
··········· data.rxflush
············ Recieve
....................................................................................................
············
PUB Data_Recieved_4
· dira[noparse][[/noparse]23]~~
····· outa[noparse][[/noparse]23]~~
······· waitcnt(3_000_000 + cnt)
········· outa[noparse][[/noparse]23]~
·········· waitcnt(3_000_000 + cnt)
·········· data.rxflush
············ Recieve
....................................................................................................
Comments
You need to move the "DIRA[noparse][[/noparse] Pin ]~~" to the start of the "Button_Down" method.
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
Thanks,
JMLStamp2p
·"repeat while ina[noparse][[/noparse]7] == 0"
This will continually scan pin 7 also note the use of == when testing for equality(not :=)
Regards
Gerry
JMLStamp2p