How long can a task run?

I am working on getting the ADS1118 ADC working in order to support the mightyboard rev g and h (replicator 2(x)). This ADC has 3 channels (2 thermocouples and a cold junction reference temperature) that must be set up and read sequentially, i.e. send the command to do a conversion for channel one, then then next time the task runs check if the conversion is ready, read channel one and send the command to read channel 2, etc.

Once the cold junction and one or both channels are read the temperature must be calculated from the k-type thermocouple and the cold junction temperature. Right now I am attempting to do this in the MCU - I have the code set up to read a single channel on each task wake and store the cold junction temperature in the spi structure.

When I read channel one I am attempting to use a lookup table to calculate the temperature in the MCU and send it back to the host. For some reason that seemed to be the way to do it as I was getting used to how Klipper is set up. However, I think that may be too much to do in a single task and the correct way would be to simply send each raw value back to the host and have the host compute the actual temperature.

Apart from any direction as to how to approach this I have a general question about what happens if a task runs too long - and what techniques can be used to time tasks as they are developed?

Thanks!

I’m not aware of any “hard faults” that will occur if a task runs too long. In general, though, it’s preferable to keep each task to within a few microseconds. The primary way to do this is to not run any unbounded loops (and certainly not any busy loops). If a particular task runs for more than a few milliseconds, it could result in retransmits to/from the host. If a task ran for 100+ms then the hardware watchdog may trigger.

In contrast, timers, irq handlers, and code that runs with irqs disabled will cause a larger issue if they run for more than a microsecond or so. It’d likely result in “rescheduled timer in the past” type errors along with errors listed above.

Separately, if mcu code is needed, it’s generally preferable to just gather the raw data and pass on to the host for processing.

-Kevin

dockterj Did you manage to get ADS1118 running? I’m trying to run klipper on GuiderIIs and looks like I’m not gonna do this by myself.
I found the ADS1118 library for arduino and FlashForge/Dremel Marlin
But with my level of knowledge, this is unfortunately not enough.

Pavulon, I need a couple of hours uninterrupted to finish something that can be used. I’d like to make sure the config will work with your guideriis. Is it a single or dual extruder and Is the ads1118 only used for the extruder? Does it use a k-type thermo couple? Do you know how the ads1118 is connected and what micro does it use?

My config is okay, but not calibrated because i’m trying to run ADS1118. Steppers are moving, fans are spinning, bed is heating. There is single extruder and only one thermocouple connected. PIN 6 and PIN 7 of ADS1118 (AIN2 and AIN3) are not soldered to anything. Guider IIs is using STM32F103RCT6.
I started to understand a bit of SPI communication thanks to Logic Analyzer but I definitely need more time.