Welcome! Log In Create A New Profile

Advanced

New firmware: temperature correction, absolute extruder moves

Posted by dc42 
New firmware: temperature correction, absolute extruder moves
March 17, 2014 07:57AM
I have just released version 057u-dc42 of my Duet firmware, available via [github.com]. Changes this time round are:

1. I have added optional parameters L and H to the M301 (set hot end PID parameters) and M304 (set bed PID parameters) commands. These allow the offset and gain errors inherent in the SAM3X ADC to be corrected. The values you set are stored to flash memory, so they survive power down cycles and resets, but not re-flashing the firmware (which sets both values to zero). You can use positive or negative values, integer or fractional. The H parameter affects mostly the low-temperature readout, and the L parameter affects mostly the high-temperature readout. To determine the correct values for your Duet board:

(a) Simple method: with the hot end at room temperature and a thermometer to tell you the temperature, send command M301 Hnn for various values of nn until you discover the value of nn that gives the correct temperature readout. Do not set the L parameter.

(b) More accurate method: replace the hot end thermistor by a 100K 1% resistor and adjust the H parameter to get a reading as close to 25C as possible (you probably won't manage exactly 25.0C because the DAC quantum is about 0.6C at this temperature). Then substitute a 220 ohm 1% resistor and adjust the L parameter to get a reading of 260.1C. Then change the resistor back to 100K, check you are still getting a reading close to 25C, and fine-tune the H parameter if necessary.

The parameters you use for the hot end should also be correct for the bed, so when you have determined the correct hot end parameters, send an M304 command with the same H and L parameters. However, you can use different M301 and M304 parameters if you wish.

EDIT: the values you end up with should be between about -100 and +100. For my own Duet I am using H18.2 L-14.

EDIT 2: changed above to use a 100K resistor instead of 220K.

2. I have added untested code to fix the problem when absolute extruder distances are used and a G92 command to set the extruder position is received.

3. A shorted hot end thermistor now reads 2000C instead of a negative temperature.

Edited 7 time(s). Last edit at 03/17/2014 11:53AM by dc42.



Large delta printer [miscsolutions.wordpress.com], Robotdigg SCARA printer, Crane Quad and Ormerod

Disclosure: I design Duet electronics and work on RepRapFirmware, [duet3d.com].
Re: New firmware: temperature correction/absolute extruder moves
March 17, 2014 08:08AM
Good stuff dc42 - especially the simplicity of calibration - I'll give it a go and will feedback asap.

I'll also have a go at testing fix 2

Cheers

Ray
Re: New firmware: temperature correction/absolute extruder moves
March 17, 2014 10:46AM
Hi dc42 - this seems to work fine except for one caveat - if the offset is high, the ADC outputs it's maximum reading when using a 220K resistor, so you get a reading of -273.15 no matter what correction is added my offset is around 50, Ben's is around 60-65 so would also not be able to use the 220k - I substituted a 100k resistor and adjusted M301 Hxx until it read 25.3. I'd already calculated my offset to be around 50, plugging in M301 H48 got me bang on for the cold reading. Although calibrating past the useful range is generally a good idea, with the offset being as it is, I think you should modify your instructions to use a 100k and aim for 25.3°C.

Running with a 220ohm resistor initially read 261.4°C, using M301 L-22 brought the readout to 260.2°C, re-running with the 100k res gave a reading of 25.4 so no need to repeat adjustment at the cold end for me. [edit I just measured the 220 ohm resistor and it's more like 218, so in fact the initial 261.4 was the correct readout in my case - nonetheless I'm leaving in that part as an example of using M301 L /edit]

Hot end thermistor reading at room temp (measured at 21.7) : corrected = 24.3°C, uncorrected = 4.6°C definite improvement smiling smiley

Cheers

Ray

Edited 1 time(s). Last edit at 03/17/2014 10:57AM by rayhicks.
Re: New firmware: temperature correction/absolute extruder moves
March 17, 2014 12:07PM
Quote
dc42
2. I have added untested code to fix the problem when absolute extruder distances are used and a G92 command to set the extruder position is received.
Absolute extrusion also seems to work - tested by restarting a print sliced by Cura without Frank's plugin, this used to provoke the rewind to E=0 on attempting the second run, it no longer does.

Ray

Edited 1 time(s). Last edit at 03/17/2014 12:09PM by rayhicks.
Re: New firmware: temperature correction/absolute extruder moves
March 17, 2014 12:41PM
Ray, many thanks for your feedback on both. I have amended the ADC offset calibration instructions to suggest a 100K resistor instead of 220K as per your previous post.



Large delta printer [miscsolutions.wordpress.com], Robotdigg SCARA printer, Crane Quad and Ormerod

Disclosure: I design Duet electronics and work on RepRapFirmware, [duet3d.com].
Re: New firmware: temperature correction, absolute extruder moves
March 17, 2014 02:11PM
If you don't do any calibration etc does this upgrade function or is the calibration mandatory?

I.e. Does it come with built in defaults?


Another RS Ormerod Mk1 meets the world smiling smiley

Also supplier of...
CNC Machined Mk1 aluminium bed support plates - no more sagging heat bed. [ddmetalproducts.co.uk]
CNC machined X-plates and ribs for Mk1 & Mk2 Ormerods - no more bendy acrylic. [ddmetalproducts.co.uk]
CNC machined bed support arms for the Mk2 Ormerod.
Dual Hot-End heatsink blocks.
Re: New firmware: temperature correction, absolute extruder moves
March 17, 2014 02:26PM
DaveK, it defaults to zero - which gives the same behaviour as before if you don't calibrate. There are some boards that badly need calibration to get printing going (otherwise they read as -273 when the room temperature drops in some cases, or don't reach a temperature high enough for extrusion in others) - if it's all working for you, just ignore the M301 L and H parameters.


Cheers

Ray
Re: New firmware: temperature correction/absolute extruder moves
March 17, 2014 02:31PM
No problem dc42 - I'd suggested or nagged that you could maybe address these problems, so the least I could do was try out the fixessmiling smiley Out of interest, my other duet (which reported more accurately the low end temperature) needed the following to calibrate it: M301 H3 L-20. The effect of calibration on this one is rather subtle - measured and reported temperatures agree pretty fully over the measured range - I haven't hooked up the board that really needs calibrating to a working hotend, though I did calibrate it and check against a cold hotend thermistor and I'm confident it will cure the low-end underread that Ben bought his hairdrier to workaround. Hopefully the L parameter will fix the problem for those who have extrusion difficulties.

Ray
Re: New firmware: temperature correction, absolute extruder moves
March 17, 2014 02:48PM
Quote
rayhicks
DaveK, it defaults to zero - which gives the same behaviour as before if you don't calibrate. There are some boards that badly need calibration to get printing going (otherwise they read as -273 when the room temperature drops in some cases, or don't reach a temperature high enough for extrusion in others) - if it's all working for you, just ignore the M301 L and H parameters.


Cheers

Ray

Thanks, that makes sense, sounds good.


Another RS Ormerod Mk1 meets the world smiling smiley

Also supplier of...
CNC Machined Mk1 aluminium bed support plates - no more sagging heat bed. [ddmetalproducts.co.uk]
CNC machined X-plates and ribs for Mk1 & Mk2 Ormerods - no more bendy acrylic. [ddmetalproducts.co.uk]
CNC machined bed support arms for the Mk2 Ormerod.
Dual Hot-End heatsink blocks.
Re: New firmware: temperature correction, absolute extruder moves
March 17, 2014 05:58PM
Great work dc. I'd been bugging Adrian to do something similar, but once again, you read my mind and beat us to it...
I've pointed Adrian at this, too. At the moment, if people get -273 on the hot end thermistor at 15C ambient, I swap their board, so having a thermistor calibration routine is great. Just need to get him to pull it into the master...

Though I still don't understand what advantage there is saving the values in EEPROM, over writing them to config.g? My understanding is that the EEPROM management on the ARM is pretty nasty. But I'm no expert!

Ian
RepRapPro tech support.
Re: New firmware: temperature correction, absolute extruder moves
March 17, 2014 06:45PM
Hi Ian,

Unfortunately, if people get -273 at an ambient temp of +15 when using one of my recent firmware versions, then the calibration facility I have added won't help, because we still need to detect the difference between a disconnected thermistor and a low temperature. However, just running one of my firmware versions instead of 0.57a may be enough to fix that problem in some cases, because I am using the ADC in 12-bit mode instead of in 10-bit mode. So the disconnected threshold in my firmware is 4095/4096 instead of 1023/1024.

The reason why I decided to store values in flash memory is this. Whenever I made any adjustments to the print head that required G31 calibration, or I changed the PID parameters, I was having to update config.g if I wanted the values preserved. This is a lengthy procedure:

1. Try to remember what values I am currently using (in particular, the G31 parameters, which I can't retrieve if I have forgotten them);

2. Edit those values into the config.g file on my PC;

3. Connect to the Duet using Pronterface (normally, I use only Matt's web interface);

4. Try to upload config.g;

5. If that fails, remove the SD card, put it in the USB adapter, plug it into the PC, copy the file across, unplug it, and put it back in the Duet.

This was so tedious that I wasn't always doing it - then I lost the settings if a print went wrong and I had to do an emergency stop. By storing the values in flash, I need only store them in a file or manually reset them when I am upgrading the firmware. Atmel provides a library for writing flash memory on the SAM3X, so it wasn't hard to code.

What I'd really like to do is to save parameters to EEPROM memory that survives firmware upgrades, such as is possible on the Atmega processors used in previous RepRaps. Unfortunately, the SAM3X on the Duet doesn't have any EEPROM. So I've just added an item to my Duet wish list: add a small serial EEPROM chip (cost about 10p) to store these parameters.



Large delta printer [miscsolutions.wordpress.com], Robotdigg SCARA printer, Crane Quad and Ormerod

Disclosure: I design Duet electronics and work on RepRapFirmware, [duet3d.com].
Re: New firmware: temperature correction, absolute extruder moves
March 17, 2014 08:19PM
Wouldn't saving them to file on the SD by the Duet have the same effect? Effectively treating the file as the equivalent of the Flash. It could either be update of the actual config.sys or a separate parameter file if you wanted to keep it independent. Either way it avoids a separate update from PC and doesn't use the Flash. Plus it survives a firmware update.
Re: New firmware: temperature correction, absolute extruder moves
March 18, 2014 03:52AM
@dc42 by using latest iamburny web interface, it should be possible to upload config.g directly via browser.
I will try it this morning and if it works I will say goodbye to pronterface ad sd card adapter.

Roberto


RS Ormerod #117
Re: New firmware: temperature correction, absolute extruder moves
March 18, 2014 04:30AM
Quote
gammasistemi
..I will try it this morning and if it works I will say goodbye to pronterface ad sd card adapter.

Roberto

You can do the same with dc42's firmware and the uncompiled version of pronterface - and print via USB directly

Erik
Re: New firmware: temperature correction, absolute extruder moves
March 18, 2014 05:11AM
Yes, but my pc is at over 10m from the printer.
So the cable lenght limits and also some hangs during the prints (probably electrical noises) conviced me to use the useful iamburny web interface.
I use the local version with a minimal xammp http server and all my prints are from SD (so i can use the pc for all what i need, and i can also poweroff or set the standby mode).

Roberto


RS Ormerod #117
Re: New firmware: temperature correction, absolute extruder moves
March 18, 2014 05:11AM
Quote
bobtidey
Wouldn't saving them to file on the SD by the Duet have the same effect? Effectively treating the file as the equivalent of the Flash. It could either be update of the actual config.sys or a separate parameter file if you wanted to keep it independent. Either way it avoids a separate update from PC and doesn't use the Flash. Plus it survives a firmware update.

Yes, saving the parameters to SD card would be an alternative. I think config.g should be a file that is either managed by the system, or managed by the user, but not both - because systems that try to store parameters in files that the user can also store other stuff in get very messy and tend to suffer form obscure bugs. So the system should either save parameters to a separate file, or an additional file should be available for storing other commands that the user wants to run on start up.

Roberto, yes the feature to upload config.g via the web interface will certainly help. However, in my opinion it should not be necessary for me to edit and upload a file every time I want to change a parameter that ought to be nonvolatile. Sending the G or M command should be enough.



Large delta printer [miscsolutions.wordpress.com], Robotdigg SCARA printer, Crane Quad and Ormerod

Disclosure: I design Duet electronics and work on RepRapFirmware, [duet3d.com].
Re: New firmware: temperature correction, absolute extruder moves
March 18, 2014 06:56AM
Quote
dc42
Unfortunately, if people get -273 at an ambient temp of +15 when using one of my recent firmware versions, then the calibration facility I have added won't help,

Rats - I'd overlooked that the calibration is post-acquisition, this won't fix Ben's problem when his room temperature drops (he had -273 with a resistance of 141000 which should readout as around 17°C, nor mine which hits the limit at nearer 15°C) - so the answer would probably be to have a DC offset on the reference voltage (or a variable reference - what's the DAC on the chip used for presently I wonder?), or to pretest the ADC and reject chips that have an offset of greater than (say) [email protected] (which would let them operate down to ambients of 9°C) prior to assembly - both of these are design or manufacturing changes and may be impractical- or to use a different thermistor (finding the right one could be a pita).

Ray
Re: New firmware: temperature correction, absolute extruder moves
March 18, 2014 07:39AM
Ray, I think the long term solution is to replace the 1k series resistor on the Duet board by a higher value. Somewhere around 5.1K would be optimum in the sense of providing the same resolution at 10C as at 300C.

Is Ben using my firmware already?

Edited 1 time(s). Last edit at 03/18/2014 07:40AM by dc42.



Large delta printer [miscsolutions.wordpress.com], Robotdigg SCARA printer, Crane Quad and Ormerod

Disclosure: I design Duet electronics and work on RepRapFirmware, [duet3d.com].
Re: New firmware: temperature correction, absolute extruder moves
March 18, 2014 07:45AM
You can just change the cut-off temperature, currently at -30, to something higher. There should still be data points below the measured temperature, so it should still be able to pick up a disconnection.

Change the series resistor for a 4.7k ohm resistor, which is the commonly used value.

Ian
RepRapPro tech support
Re: New firmware: temperature correction, absolute extruder moves
March 18, 2014 08:01AM
As I understand it, the problem that Ray and Ben are getting is that the readout is -273C at temperatures as high as 15C in one case and 17C in another. The Duet hardware they have can't distinguish between a cold day and a disconnected thermistor, because the ADC gives its maximum reading in both cases. If it were just a matter of changing the cutoff temperature, they could instead adjust the ADC offset using my firmware.

The best solution to get those boards working well would be to change the series resistor. If they are capable of SMD soldering/desoldering and change the 1K resistor for the 4.7K that Ian suggests, then they could change the R parameter in the M301 command to (100K * 1K/4.7K) = 21277 to get the correct temperature readings.

Maybe I should add an S parameter to the M301 command to allow the series resistor to be set, or more simply redefine the R parameter to be the ratio of thermistor 25C resistance to series resistance.

Edited 1 time(s). Last edit at 03/18/2014 08:03AM by dc42.



Large delta printer [miscsolutions.wordpress.com], Robotdigg SCARA printer, Crane Quad and Ormerod

Disclosure: I design Duet electronics and work on RepRapFirmware, [duet3d.com].
Re: New firmware: temperature correction, absolute extruder moves
March 18, 2014 08:27AM
If it is only the hotend that has the low temperature problem, putting it in contact with the heated bed for a few minutes should raise the temperature enough to get it working again. Not an ideal workaround, but it prevents the issue being a show-stopper.

Dave
(#106)
Re: New firmware: temperature correction, absolute extruder moves
March 18, 2014 08:53AM
...and after warming the hot end up that way, you can send M562 P1 to reset the temperature fault.



Large delta printer [miscsolutions.wordpress.com], Robotdigg SCARA printer, Crane Quad and Ormerod

Disclosure: I design Duet electronics and work on RepRapFirmware, [duet3d.com].
Re: New firmware: temperature correction, absolute extruder moves
March 18, 2014 08:58AM
I just realised you said you've used M301 for hot end PID, and M304 for bed PID? Does that mean you're using PWM for your bed, rather than bang/bang? Not really a problem, but...

Though there is no convention for the gcode values, suggested uses are here (which I see you've already updated!) [reprap.org]

In the RepRapPro version of Marlin, we use M301 for hot end PID, and never implemented bed PID - bang/bang has always worked sufficiently well, and we feel PWM on the bed will cause a lot of electrical noise, with no real improvement. We used M304 to set thermistor values, with the following format:
Thermistor settings: M304 Hh Bb Rr Tt, H0=Bed, H1..n=nozzle, b=thermistor beta value, r=series resistor, t=thermistor resistance as 25C
eg: M304 H1 B3960 R4700 T100000

Most other firmware uses pre-generated thermistor tables embedded in firmware, requiring flashing updated firmware to change the thermistor values. We can change the thermistor values on the fly, as they are calculated by the firmware. I think splitting thermistor settings out from PID settings (M301) is advisable, or the M301 command becomes rather unwieldy, particularly if you're going to add other thermistor values. I suggest using M305, as this is currently unused.

Also, to avoid code replication, M301 could include the H0, H1 etc for each (H)eater and the bed, but you'd have to change the current use of H, or use an alternative. M304 could be deprecated. There isn't any particular reason that the bed is a special case; it's just another heater, and other heaters may be needed eg print chamber heater/control or additional beds. It would be advisable to keep the hot ends named T0, T1, etc, as this IS more of convention.

I say the above more to provoke discussion about how to implement these features, certainly not to lay down the law! Adrian is in agreement with this, and aiming in this direction, having just spoken to him about it.

Ian
RepRapPro tech support
Re: New firmware: temperature correction, absolute extruder moves
March 18, 2014 09:02AM
Re the temperature fault, if you connect very quickly after a reset (you'll need the ethernet connected), you can set the hot end heater before the temperature cut out kicks in. Within about 10 seconds!

Ian
RepRapPro tech support
Re: New firmware: temperature correction, absolute extruder moves
March 18, 2014 09:18AM
Hi,

I am using DC42s new firmware, but haven't had a chance to do the calibration steps yet. I was having issues when the weather was cold, but now that it has warmed up a bit it's working ok. At around 20°C my hot end reads ~-18°C, but when hot the temperature seems to be reasonably accurate (I tested with a thermocouple in the hot end).

Unfortunately I don't have the skill to solder a new surface mounted resistor on. I bought a very cheap hairdryer, which now lives with the printer to warm it up on a cold day, so I think that seems like the easiest solution to keep things working.

Apart from the cold start issues the Ormerod is a fantastic printer, and I've been really pleased with the quality of the prints.

Ben
Re: New firmware: temperature correction, absolute extruder moves
March 18, 2014 09:18AM
I plugged in different series R values before my earlier post into your excel spreadsheet dc42, for an offset the size of Ben's, changing the series to quite large numbers didn't affect the NaN result (maybe the series R isn't meant to be used that way in the spreadsheet, I'm not sure) which is why I suggested changing the reference voltage or the thermistor-

Ben's offset looks to be around 65LSB @13bits which, presuming the reference voltage is 3.30,equates to 26mV - my offset is 48 or 19mV. Focussing on my board, the signal will be offscale above 3.28V. Using a 1K series resistor with a 3.3V reference, this means it will be offscale for thermistor resistance over 165k [3.30*Rt/(Rt+Rs)] equating to an actual temperature of 14.7°C but reading as -55 if uncalibrated -this accords with your spreadsheet (as modified by me to add the offset). Changing the series resistor to 4.7k would indeed drop the signal into a useful range (in my case it would drop the voltage , but makes for unhappy looking readouts in your spreadsheet (as I say, this may not be an intended use of the spreadsheet). Originally the duet was designed with a 2k resistor which was subsequently dropped to 1k for high temperature accuracy - the 2k resistor would work fine for me as far as the voltage divider goes, and for Ben (with a 26mV offset), but the reported temperature at top of scale on your spreadsheet would
drop to 216.4 for 220ohm as opposed to 260.1 with the 1k series resistor, and presumably the same would be true of the algorithm used in the firmware - though calibration may be able to fix this. For Ben, presuming his offset IS 65, and he gets -273 when his thermistor is at 141k, the calculation in the spreadsheet still gives a NaN even for very high resistances (over 100k) - the modification I made to your spreadsheet is to add the offset to the ADC output in column H (or an eighth of it in column G) - this may not be correct but works for my board in that it predicts the readout for known resistors in place of the thermistor.
I'd prefer an S parameter to keep the interface clean (keeping R for thermistor alone)
I'll solder in a 2K resistor and feedback the result - I'll have to hook the duet up to a heat source and measure the actual versus readout temperature with the 1k and the 2k (calibrated and uncalibrated) to test so it won't be instant feedback

Cheers

Ray
Re: New firmware: temperature correction, absolute extruder moves
March 18, 2014 09:22AM
Quote
droftarts
Most other firmware uses pre-generated thermistor tables embedded in firmware, requiring flashing updated firmware to change the thermistor values. We can change the thermistor values on the fly, as they are calculated by the firmware. I think splitting thermistor settings out from PID settings (M301) is advisable, or the M301 command becomes rather unwieldy, particularly if you're going to add other thermistor values. I suggest using M305, as this is currently unused.

why didn't you suggest this two months ago when the issue was raised? [forums.reprap.org] or at some time over the last week when we were discussing calibration and temperature reading issues?

Edited 1 time(s). Last edit at 03/18/2014 09:24AM by rayhicks.
Re: New firmware: temperature correction, absolute extruder moves
March 18, 2014 09:28AM
Quote
droftarts
I just realised you said you've used M301 for hot end PID, and M304 for bed PID? Does that mean you're using PWM for your bed, rather than bang/bang? Not really a problem, but...

I didn't want to add any new gcodes, so I used the existing ones listed at [reprap.org], and added extra parameters to the commands where it seemed reasonable. There is no mention in that document of using M304 to set thermistor parameters, which is why I added them to M301. The M301 command will obviously need a heater parameter to handle multiple extruders with independent heaters (unless we assume the same parameters for all extruders), and I agree that M304 is then superfluous. The M301 command is only unwieldy if you send all or most of the parameters, but I've written it so that any parameters you don't supply retain their previous values. So you wouldn't normally use it to set both PID and thermistor parameters. If you would rather use M304 or M305 to pass the thermistor parameters, that's fine by me, but it needs to be documented.

The H and L parameters in theory relate to the ADC as a whole rather than to specific heaters, so they could even be moved to a different gcode completely.

Re PID vs. bang-bang for the bed heater, what I've done in the firmware is to use a negative value for the P term as an indication that bang-bang control should be used instead of PID. I've left the default P term for the bed as -1 so that it uses bang-bang as before, but can be changed to PID by setting the P, I and D parameters via M304.

Edited 2 time(s). Last edit at 03/18/2014 09:32AM by dc42.



Large delta printer [miscsolutions.wordpress.com], Robotdigg SCARA printer, Crane Quad and Ormerod

Disclosure: I design Duet electronics and work on RepRapFirmware, [duet3d.com].
Re: New firmware: temperature correction, absolute extruder moves
March 18, 2014 09:43AM
I think it's eminently workable as-is, but indeed the adc calibration parameters could have their own GCode, since they affect all of the analog inputs together - although not visibly in the case of the heated bed using the stock 10k thermistor, or presumably the Z-probe, since it's a linear parameter.

I think you've done a great job of not treading on other gcodes' toes while shoehorning in a lot of extra functionality dc42 (hence my terse reply to Ian above, since back in January he mentioned M304 NOT being used on the duet for this very reason, and just mentioned there were lots of available gcodes)

Ray
Re: New firmware: temperature correction, absolute extruder moves
March 18, 2014 09:45AM
Quote
hornbyben
At around 20°C my hot end reads ~-18°C,

Hi Ben, what did you enter for M301 Hxx ? I think from your previous postings a value of M301 H65 should get you in the right ball park,

Ray
Sorry, only registered users may post in this forum.

Click here to login