Understanding temperature code

I am modifying my firmware with an extra temperature reading to be used for a temperature compensation later.

Currently I have managed to modify configuration.h so extruder 2 has a thermistor input defined (and a fudge fix in repetier.h so it would actually add it in the array, despite numextruders being unchanged). I have further modified the M105 command so "M105 P2" will report the raw value of that thermistor as stored in osAnalogInputValues. So far so good. The rest of the code still works. (I also ended up fixing some errors in pins.h for my megatroincs v3 board)

I am currently stuck trying to get the thermistor raw->degreeC conversion extracted from extruder.cpp so I can do the same for my M105 P2 output. I am hoping for a hint here, ;;) please ?

(I think a feature request is some other internal structure to define "arbitrary" temperature inputs - which could be used for thermal shutdown, expansion compensation or whatever. The current temperature inputs are tightly tied to regulating heaters. Another day and post)


  • At least in 0.92.2 you can do M105 X0 to get raw values as well. So easiest would be to check that code in commands.cpp I guess.
  • Ah, but it only prints the values from a datastructure of the Extruder class, what I find hard to follow is the transforms of the analog input data gathered by the interrupt routine ISR(PWM_TIMER_VECTOR) that fills up a aggregation array, through to an averaged (ie. noise reduced) temperature. Besides the print of "raw" values is a cheat - it converts the temperture back to "raw", which means it isn't raw at all.

    More help, please ;;)
  • I assume you mean this line:

                Com::printF(Com::tColon,(1023 << (2 - ANALOG_REDUCE_BITS)) - extruder[i].tempControl.currentTemperature);

    That is not converting from from temperature. That is the raw value used to compute temperature normalized to 12 bit precision. Subtraction is done because we normally need ascending values for the raw->temp conversion. 12 bit because other hardware supports more then 10 bits which avr uses.

    The ISR does simply add x raw values and then builds a mean value which is stored in resulting array. Nothing special.
  • Hi "Repetier", OK, I conceed that point  - I did not notice that one variable is "currentTemperature"and "currentTemperatureC". :\">

    Yes, I understood the function of the ISR,

    Module extruder.cpp, class TemperatureController, method updateCurrentTemperature() seems where the temperature gets converted. Lets assume I have a "sensortype"=1. There are two switch statements (with lots of old leftover types?). The first one at "case 99" I have copied the code to do the same for my thermistor value (remember, I have only defined the sensor, it is not part of an extruder, and thus will not be touched by any extruder-code) and it gives me a printable raw value.

    the 2nd switch at case 12 does what I see as a linear interpolation(?) of values in what "temptables_num" points to, where the sensortype has selected the table followed by another bit compensation.

    Somehow these structure is used for the bedthermistor, too. At the Extruder::getHeatedBedTemperature it is output, but how/when could I add my thermistor to this? I can see the clue around line 1300 i extruder.cpp with the #define NUM_TEMPERATURE_LOOPS .... but feel most uncertain on the consequences of adding 1 to it, and where code would transfer osAnalogInputValues[my index] to the structure. ...

    we can take this discussion offline/pm/mail if you want to.
Sign In or Register to comment.