Revisting old project (Converting from spin to C)
Greg LaPolla
Posts: 320
I have an old project that I did several years ago. I am in the process of converting from spin to C and a new PCB layout..
I am having a bit on an issue getting my thermistor to work. When I hold the thermistor in my hand, I can see the ADCVal go down and the ohms go up. however the temperature reading also goes down as I heat up the thermistor.
I think this is backwards.
I used a tlv2543C previously, but am swapping it out for a MCP3204 to save a little space on the pcb as I only use 3 channels.
The thermistor is Negative Temperature Coefficient. I have a 10K Resister and a .01uf capacitor between the two wires from the thermistor ( See attached image). There is also a 1k resistor between the thermistor and the ADC.
I am using some code I found on the forum to drive the 3204 it is here: http://forums.parallax.com/showthread.php/157659-SimpleIDE-C-sample-code-for-ADC-MCP3204
Here is the code and formulas I converted from spin.
I am having a bit on an issue getting my thermistor to work. When I hold the thermistor in my hand, I can see the ADCVal go down and the ohms go up. however the temperature reading also goes down as I heat up the thermistor.
I think this is backwards.
I used a tlv2543C previously, but am swapping it out for a MCP3204 to save a little space on the pcb as I only use 3 channels.
The thermistor is Negative Temperature Coefficient. I have a 10K Resister and a .01uf capacitor between the two wires from the thermistor ( See attached image). There is also a 1k resistor between the thermistor and the ADC.
I am using some code I found on the forum to drive the 3204 it is here: http://forums.parallax.com/showthread.php/157659-SimpleIDE-C-sample-code-for-ADC-MCP3204
Here is the code and formulas I converted from spin.
#include "simpletools.h" // Include simple tools #include "mcp3204.h" // Include ADC Driver #include <math.h> #define ADC_cs 24 // ADC CS pin #define ADC_clk 27 // ADC CLK pin #define ADC_do 26 // ADC Data out #define ADC_di 25 // ADC Data in #define Coeff1 0.0009461261 // Steinhart Constant #define Coeff2 0.00022226704 // Steinhart Constant #define Coeff3 0.000000105745286 // Steinhart Constant #define R1 10000.0 int main() // Main function { int ADCVal; ADCVal = 0; double temp; double ohms; double volts; volts = 0; ohms = 0; temp = 0; while(1) { pause(1000); ADCVal = readADCAverage(0, ADC_di, ADC_do, ADC_clk, ADC_cs, 10); print("adcval = %d%c\n",ADCVal, CLREOL); ohms = ((4096.0 * R1) / ADCVal) - R1; print("ohms = %.1f\n", ohms, CLREOL); volts = ADCVal * 3.3 / 4096.0; print("volts = %f\n", volts, CLREOL); temp = 1 / ( Coeff1 + ( Coeff2 * log(ohms) ) + ( Coeff3 * pow(log(ohms),3)) ); temp = temp - 273.15; temp = temp * 1.8 + 32.0; print("Temp = %.1f\n", temp, CLREOL); print("%c", HOME); pause(100); } }
Comments
https://code.google.com/p/spin2cpp/
Another option - one that I'd love to help you with - is using PropWare. I use a MCP3008 for my own tinkering and recently modified my object to be compatible with the entire MCP3xxx range of ADCs. I don't have a built-in "readADCAverage" function. But a rolling-average buffer is something I've been very keen on creating so I'd be happy to get that knocked out for you.
If this piques your interest, feel free to poke at the links in my signature and send me any questions.
It's better just to convert code by hand.
If people really need to use spin2cpp, the current github repository should be used. Spin2cpp forum thread.
Another option is to use the spin code "as is" in propeller-gcc with spinwrap. Spinwrap forum thread.
Propeller libraries propware and libpropeller are viable options that don't get enough attention.
-Tor