Incorrect heater bed readings using adc_temperature section

Basic Information:

Printer Model: Cetus 3D
MCU / Printerboard: custom RP2040 CPU
klippy.log (2.8 MB)

Describe your issue:

I’m endeavouring to get a custom MCU to run Klipper on an otherwise stock Cetus 3D (previously running a TinyFab MCU with Marlin)

I have the steppers working but have gotten stuck on the temperature sensors. I’ve started with the bed sensor (because I figured it would be easier/safer)

I’m using an adc_temperature section in my config - the relevant sections included below

My problem is that when I query the ADC reading, it seems sensible, but the reported temperature doesn’t appear to be interpolated from my table. I can’t figure out how it is getting 70 deg from an ADC value of 0.070757 V based on that table??

I suspect it is a dumb mistake/misunderstanding on my part. Any help greatly appreciated!

*get_bed_temp is a macro:

[gcode_macro get_bed_temp]
gcode:
  M118 {printer.heater_bed.temperature}

Relevant section of config file:

[adc_temperature my_bed]
temperature1: 0
voltage1: 0
temperature2: 20
voltage2: 0.09992674
temperature3: 25
voltage3: 0.124908425
temperature4: 30
voltage4: 0.14989011
temperature5: 35
voltage5: 0.174871795
temperature6: 40
voltage6: 0.19985348
temperature7: 45
voltage7: 0.224835165
temperature8: 50
voltage8: 0.24981685
temperature9: 55
voltage9: 0.274798535
temperature10: 60
voltage10: 0.29978022

[heater_bed]
heater_pin: gpio23
sensor_type: my_bed
sensor_pin: gpio27
control: pid
pid_Kp: 54.027
pid_Ki: 0.770
pid_Kd: 948.182
min_temp: 0
max_temp: 100```

You say you are using a “custom RP1040” controller board - what value is the pull up on the thermistor interface?

I believe that it should be 4k7, but when I look in the Klipper reference for [heater_bed]:

https://www.klipper3d.org/Config_Reference.html#heater_bed

There is no reference to the pull up value nor is there the pullup_resistor argument in the [extruder] parameter.

There was a fairly extensive discussion about the weirdness around this control board and it’s thermistor circuitry here : https://github.com/Klipper3d/klipper/issues/2077. I’ve only replaced the MCU - the rest of the main board is stock

What I’m trying to do is use an adc_temperature section and set that as my sensor type (instead of a thermistor). My understanding is specifying a pullup_resistor is only applicalble if the sensor type is a thermistor

Thanx for the link - if I’m reading it correctly, there isn’t a strong understanding of how the ADC circuit is wired nor what devices it is designed for. I tried looking for schematics but couldn’t find any - can you supply some/point me to a link?

How are you driving in your ADC voltage? Is it a chip/power supply output or a pot acting as a voltage divider (with a DMM for checking the voltage)? I’m asking because a straight pot with this circuit will never work as the resistances of the pot will become part of the resistor network and give you an unexpected voltage value (you could figure it out but I think that would be a waste of time).

Personally, I would recommend driving the ADC signal into the board using an OpAmp wired as a unity gain amplifier to make sure that the impedance(s) of the pot or DAC chip isn’t part of the circuit.

Anyway, there needs to be a lot more information available before a determination of what the issue is. The best place to start is to provide:

  • Schematics of your board
  • Explanation of how you are creating your ADC voltages and providing them to the circuit

Thanks Myke!

Perhaps in trying to provide some background I obfuscated my main question/issue…

If you look at the screenshot you can see the result of QUERY_ADC NAME=heater_bed is 0.070757 (presumably volts)

Using the look up table for ‘my_bed’, this should translate to something between 0 and 20 degrees (approx 15 degrees), which would be very reasonable

However, looking at the screenshot again you can see mainsail (and printer.heater_bed.temperature) report a temperature of 70 degrees

I am trying to figure out how 0.070757 is being converted to 70 degrees?

It doesn’t appear to be using my look up table - have I specified this in my config file correctly?

This is why I asked for a schematic of the board you’re working with along with how you are driving the ADC. Also, have you measured the voltage at the board input pin and at the MCU pin to see what kind of difference there is?

When I read the link that you provided, there is confusion as to whether or not the temperature sensor for the board is a PT100 or an NTC thermistor. In fact, I don’t think the question is ever answered - do you know what sensor is used on the board?

I think with an understanding of the input circuitry (and resistor network) we can suss out what’s happening here.

I think I might have figured it out, but won’t have a chance to test until tomorrow…

I suspect the ADC value I’m querying is fractional (adc_count / adc_max) and needs to be multiplied by 3.3 to give ADC voltage. Also I think I need to specify ‘’’adc_voltage: 3.3’’’ in the heater section

And… I think I converted my Marlin lookup table incorrectly - thought it was based on a 12 bit ADC instead of 10 bits

Will report back if this resolves my issue

Good stuff.

After we sorted out what the input circuits look like, I was going to suggest we try to understand what the numeric values that you have really mean. The number of ADC bits shouldn’t be that relevant unless the values are at an extreme (ie very high or very low).

Let me know what you find out.

Thanks again @mykepredko

All good now! A couple of mistakes, mostly due to wrong assumptions, on my end

In case anyone else stumbles across this post, the solution was:

  • Make sure your voltage/temperature table is correct
  • If you have a 3.3V ADC, make sure you set adc_voltage: 3.3 in the appropriate heater section
  • If using the QUERY_ADC command, it appears to return a normalised (between 0 and 1) ADC value. Multiply by your ADC voltage (i.e. 3.3 V here) to get your ADC pin voltage

My updated config sections (I also removed most of the temp/volt points since the profile was linear):

[adc_temperature my_bed]
temperature1: 0
voltage1: 0
temperature2: 165
voltage2: 3.3

[heater_bed]
heater_pin: gpio23
sensor_type: my_bed
sensor_pin: gpio27
adc_voltage: 3.3
control: pid
pid_Kp: 54.027
pid_Ki: 0.770
pid_Kd: 948.182
min_temp: 0
max_temp: 100
3 Likes

Good job!

I’m glad to hear you figured things out.