Need help with (what should be) simple Spin code
Hello All,
I cannot for the life of me figure out why this is not working. All I'm trying to do is get successive readings from a thermocouple and display the current reading as well as the average reading over the last 4 samples. The current reading portion is working, but somehow the portion that adds up the measurements is not. The readings are all around 75 degrees F, but somehow the total only shows up as around 109 after 4 samples (should be in the range of 300). This should be simple, but it's been annoying me for some time now.
Anyone have a suggestion? I'm sure it is something simple that I am not seeing (as usual).
Thanks.
Greg
I cannot for the life of me figure out why this is not working. All I'm trying to do is get successive readings from a thermocouple and display the current reading as well as the average reading over the last 4 samples. The current reading portion is working, but somehow the portion that adds up the measurements is not. The readings are all around 75 degrees F, but somehow the total only shows up as around 109 after 4 samples (should be in the range of 300). This should be simple, but it's been annoying me for some time now.
Anyone have a suggestion? I'm sure it is something simple that I am not seeing (as usual).
Thanks.
Greg
{{TC_Manager.spin}}
CON
_clkmode = xtal1 + pll16x
_xinfreq = 5_000_000
num_samples = 4
OBJ
TC : "DS2760"
Table : "type_t"
VAR
BYTE counter
LONG devices_found
LONG current_cj_temp
LONG current_tc_voltage
LONG cj_compensation_voltage
LONG final_temp
LONG final_temp_f
LONG TC_Stack[noparse][[/noparse]10]
LONG total
PUB Start (OW_Pin,temperature_pointer,average_pointer)
devices_found := TC.Start(OW_Pin)
cognew(Main(temperature_pointer,average_pointer),@TC_Stack)
RETURN
PUB Main (temperature_pointer,average_pointer)
REPEAT
total := 0
REPEAT counter from 1 to num_samples
current_cj_temp := tc.get_cj_temp
current_tc_voltage := tc.get_tc_voltage
cj_compensation_voltage := Table.get_comp_voltage(current_cj_temp)
final_temp := Table.lookup_voltage(current_tc_voltage + cj_compensation_voltage)
final_temp_f := tc.c_to_f(final_temp)
total += final_temp_f
long[noparse][[/noparse]temperature_pointer] := final_temp_f
waitcnt(180_000_000 + cnt)
long[noparse][[/noparse]average_pointer] := (total / num_samples)

Comments
Does your long [noparse][[/noparse]temperature pointer ]show 75 where you are reading it?
Thank you! I changed the stack size to 30 and it's working now.
How can I determine what the stack size needs to be in advance? Is it a function of how many levels of subroutine are being called?
Thanks again for the help, this was a highly annoying problem.
Greg
Anyway, you usually guess a stack size, then add a fudge factor to account for unforseen details.
It shouldn't be that hard to add a right-click mouse-button option on any method label to allow stack usage to be calculated. That's got to be better than guessing, 10, 100, maybe a 1000 and never being sure if one's being marginal or far too excessive.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Caught in the PropWash