TJHJ
03-20-2012, 02:50 PM
Hi,
So I have been out of the game a bit, but what should work is running me up a wall....
I cant seem to get a value to update from one cog to another using a global var, in the peakknock value. Help please.
Ok simple knock sensor,
Wiring - GND ----- Piezo ----- 1 MOhm ----- LTC1298
I have checked the ADC and it is reading correctly.
this works
CON
_clkmode = xtal1 + pll16x
_xinfreq = 5_000_000
' lcd connections
LED = 5
MOSI = 4
SCK = 3
DC = 2
SCE = 1
RST = 0
' ADC Connections
ADCcpin = 9
ADCdpin = 10
ADCspin = 11
OBJ
ADC : "LTC1298"
lcd : "jm_nokia_5110_fast"
VAR
Long PeakKnock, KnockYes, CurrentValue
Long Stack1[100]
Pub Main
lcd.start(RST, LED) 'Cog 1 ' start lcd
ADC.Start(ADCcpin) 'Cog 2 'Start ADC 1TC298
cognew(Sense, @Stack1)
repeat
lcd.clear
writeDec(0,0,Getknock) 'Get the current ADC Value and update the peakKnock value, and KnockYes
WriteDec(0,1,PeakKnock) 'print the peak knock value
if knockyes == true 'if a Knock has happened Print knock to the screen
LCD.Goto_XY(0,2)
LCD.STR(String("KNOCK"), lcd#NORMAL)
if ina[press] == 1 'if the button is pressed
waitpne(|<press, |<press,0) 'freeze the screen so it no longer flikers (I know I could have a delay im trying to make sure I dont miss a knock yet)
PeakKnock := 0 'Reset the peakKnock Value
KnockYes := false
Pub GetKnock | t
t := ADC.GetADC(1) ' Get the current ADC value
if t > 20 'If the value is greater than the threshold Set the knock happened flag to try
KnockYes := true
if t > PeakKnock 'if the current ADC value is greater than the old value in peakknock
PeakKnock := t 'replace the peak knock value with the current
return t 'return the current ADC Value
OK so this works as expected, a value quiet around 5, a knock gives a peak from 40-150.
Now if I move the get knock function to its own cog I get a constant 8192 in the peakKnock value. What is going on here???
Pub Main
lcd.start(RST, LED) 'Cog 1 ' start lcd
ADC.Start(ADCcpin) 'Cog 2 'Start ADC 1TC298
cognew(Sense, @Stack1)
repeat
lcd.clear
'Removed the update from the main function
WriteDec(0,1,PeakKnock) 'print the peak knock value
if knockyes == true 'if a Knock has happened Print knock to the screen
LCD.Goto_XY(0,2)
LCD.STR(String("KNOCK"), lcd#NORMAL)
if ina[press] == 1 'if the button is pressed
waitpne(|<press, |<press,0) 'freeze the screen so it no longer flikers (I know I could have a delay im trying to make sure I dont miss a knock yet)
PeakKnock := 0 'Reset the peakKnock Value
KnockYes := false
Pub Sense
repeat
GetKnock
Pub GetKnock | t
t := ADC.GetADC(1) ' Get the current ADC value
if t > 20 'If the value is greater than the threshold Set the knock happened flag to try
KnockYes := true
if t > PeakKnock 'if the current ADC value is greater than the old value in peakknock
PeakKnock := t 'replace the peak knock value with the current
return t 'return the current ADC Value
I dont understand why I am getting a junk value if I move the function into its own cog.
I have also tried this with the same results
Pub Sense
ADC.Start(ADCcPin)
repeat
GetKnock
Thank you for your help
So I have been out of the game a bit, but what should work is running me up a wall....
I cant seem to get a value to update from one cog to another using a global var, in the peakknock value. Help please.
Ok simple knock sensor,
Wiring - GND ----- Piezo ----- 1 MOhm ----- LTC1298
I have checked the ADC and it is reading correctly.
this works
CON
_clkmode = xtal1 + pll16x
_xinfreq = 5_000_000
' lcd connections
LED = 5
MOSI = 4
SCK = 3
DC = 2
SCE = 1
RST = 0
' ADC Connections
ADCcpin = 9
ADCdpin = 10
ADCspin = 11
OBJ
ADC : "LTC1298"
lcd : "jm_nokia_5110_fast"
VAR
Long PeakKnock, KnockYes, CurrentValue
Long Stack1[100]
Pub Main
lcd.start(RST, LED) 'Cog 1 ' start lcd
ADC.Start(ADCcpin) 'Cog 2 'Start ADC 1TC298
cognew(Sense, @Stack1)
repeat
lcd.clear
writeDec(0,0,Getknock) 'Get the current ADC Value and update the peakKnock value, and KnockYes
WriteDec(0,1,PeakKnock) 'print the peak knock value
if knockyes == true 'if a Knock has happened Print knock to the screen
LCD.Goto_XY(0,2)
LCD.STR(String("KNOCK"), lcd#NORMAL)
if ina[press] == 1 'if the button is pressed
waitpne(|<press, |<press,0) 'freeze the screen so it no longer flikers (I know I could have a delay im trying to make sure I dont miss a knock yet)
PeakKnock := 0 'Reset the peakKnock Value
KnockYes := false
Pub GetKnock | t
t := ADC.GetADC(1) ' Get the current ADC value
if t > 20 'If the value is greater than the threshold Set the knock happened flag to try
KnockYes := true
if t > PeakKnock 'if the current ADC value is greater than the old value in peakknock
PeakKnock := t 'replace the peak knock value with the current
return t 'return the current ADC Value
OK so this works as expected, a value quiet around 5, a knock gives a peak from 40-150.
Now if I move the get knock function to its own cog I get a constant 8192 in the peakKnock value. What is going on here???
Pub Main
lcd.start(RST, LED) 'Cog 1 ' start lcd
ADC.Start(ADCcpin) 'Cog 2 'Start ADC 1TC298
cognew(Sense, @Stack1)
repeat
lcd.clear
'Removed the update from the main function
WriteDec(0,1,PeakKnock) 'print the peak knock value
if knockyes == true 'if a Knock has happened Print knock to the screen
LCD.Goto_XY(0,2)
LCD.STR(String("KNOCK"), lcd#NORMAL)
if ina[press] == 1 'if the button is pressed
waitpne(|<press, |<press,0) 'freeze the screen so it no longer flikers (I know I could have a delay im trying to make sure I dont miss a knock yet)
PeakKnock := 0 'Reset the peakKnock Value
KnockYes := false
Pub Sense
repeat
GetKnock
Pub GetKnock | t
t := ADC.GetADC(1) ' Get the current ADC value
if t > 20 'If the value is greater than the threshold Set the knock happened flag to try
KnockYes := true
if t > PeakKnock 'if the current ADC value is greater than the old value in peakknock
PeakKnock := t 'replace the peak knock value with the current
return t 'return the current ADC Value
I dont understand why I am getting a junk value if I move the function into its own cog.
I have also tried this with the same results
Pub Sense
ADC.Start(ADCcPin)
repeat
GetKnock
Thank you for your help