ExtruderIO

From RepRap
Revision as of 05:45, 24 January 2007 by SimonMcAuliffe (talk) (version migrated from twiki)
Jump to: navigation, search

Extruder I/O

The temperature sensor

The temperature sensor is a thermistor. The resistance of the thermistor is dependent on temperature, so measuring the resistance is sufficient to calculate the temperature. Measuring resistance with a microcontroller is usually accomplished with an A/D converter.

The PIC16F628 doesn't have a true A/D converter. It does have a voltage reference generator and a voltage comparator that can be used as a poor-mans A/D converter but since it only has 16 levels on the voltage generator, it isn't useful for any real degree of accuracy. A common way to implement A/D conversion on the low end PIC microcontrollers is to use a slope converter. The basic approach used in the extruder module is to charge a capacitor of known value through the unknown value resistor (the thermistor). By measuring the time it takes to charge the capacitor, the resistance can be determined and therefore also the temperature.

For calibration purposes, the implementation also includes a resistor of known value. Through software control, the capacitor can be charged through either the known resistor or through the thermistor. The known value measurement provides a calibration point that can be used to correct any errors in the measurements of the thermistor. Note: the calibration resistor is not currently used, and the temperature is calculated with a good degree of accuracy from first principles knowing the CPU clock rate etc. In future it may be useful to use the calibration resistor as a double check. Taking advantage of the calibration resistor is just a software change.

Firmware details

In general complexity is offloaded to the host software so that the firmware can be kept simple. The firmware does not perform any final temperature calculations, it just makes raw timing measurements and passes them to the host controller to finally determine the actual temperature.

Timing the capacitor charge involves first discharging the capacitor and then starting the capacitor charge. The number of ticks of a timer is counted until the capacitor is charged.

The complicated part of the sampling the resistance is getting the timing correct. If the capacitor charges too quickly, the number of ticks elapsed will always be very low and since it is an integer value it will have very little accuracy. To maximize accuracy, it is important that the timer counts as high as possible during the sampling period. However if it counts too high, it will overflow and the sample becomes useless.

Capacitor charging is exponential so it never quite charges fully, so rather than waiting for a 100% charge, the firmware only waits until it reaches a particular percentage of full charge. The voltage comparator is used to determine when the capacitor reaches the appropriate level. The voltage comparator threshold is the first important parameter for the timing. The PIC voltage comparator works by comparing the input voltage to the voltage reference module output. The voltage reference is set by two parameters, a 4 bit VR value and a high/low range flag. The firmware always uses the high range, so the voltage reference output is determined by the following equation:

 VREF = 1.25 + 5 * VR / 32

At powerup, by default VR is 3 however this can be changed by the host at any point in time.

The time measurement is accomplished using an 8 bit timer TMR0 which counts at an adjustable rate. The rate is specified by an 8 bit prescaler. The watchdog prescaler is assigned to the timer, which is a value 1:1, 1:2, 1:4, 1:8, ..., 1:128 (ie a power of 2). This parameter (PS) can also be adjusted under control from the host software. At powerup, it is initially set to 1:128.

The two parameters VR and PS together define the timing behaviour. It is intended that the host controller software will dynamically adjust these parameters to keep the timer values as close to 255 as possible, without overflowing. If an overflow occurs the timing should be slowed down (or VR increased) so that overflow stops. If the timer values are too low, the timing should be sped up (or VR decreased) to increase the timer values. At any stage, with the knowledge of the current PS and VR values and the charge time, the host software can calculate the resistance and therefore the temperature.

This automatic ranging behaviour allows for the most accuracy possible throughout the desired temperature range. To make the most of auto-ranging capability, the capacitor value should be matched to the thermistor range. The capacitor value is currently assumed to be 1μF and is hard coded. Since ideally this depends on the thermistor used, the capacitor value should be stored in the application preferences. 1μF will not be suitable for all thermistors. The ideal capacitor value can be calculated:

[todo] determine optimal capacitor value for electronics based on thermistor values and desired temperature range, using Vc = 5(1-exp(-t/RC)) vs the VREF. Probably the most sensible way to do this is specify the max temperature and desired error size. Then the capacitor can be calculated, as well as the lowest temperature that can be measured.

To verify the correct and optimal operation of the measurement, the poke utility can be used. Check that the returned timer values are as close as possible to 255 for low temperatures. As the temperature rises the value should drop. This naturally leads to less accurate measurements at higher temperatures. Resetting the ranging value should be tested to ensure that the timer values can be increased to useful ranges for the higher temperatures as well.

[todo] include sample steps for test

Note, an interrupt occurring during the timing routine will upset the timing. Shouldn't this disable interrupts??!

Ah, actually it shouldn't disable interrupts because the sample time is too long. However if an interrupt occurs, it should set a flag to tell it to disregard that particular sample

Host controller details

The host controller software currently does not dynamically adjust the timing parameters as intended. With appropriate capacitor selection, it still behaves adequately this way. At room temperatures precision is better than ±1°C. At high temperatures of around 180°C accuracy is approximately ±10°C. This is generally acceptable for production, but completing the dynamic timer adjustment code will improve this accuracy.

The important functions are:

  • getDeviceTemperature: Returns the raw timer count from the device
  • calculateResistance: Calculates the resistance of the thermistor in ohms
  • calculateTemperature: Calculates the temperature (celsius) given the thermistor resistance using the known thermistor parameters, β and Rz.

The heater output

Firmware details

Host controller details

The motor driver

See Also

-- Main.SimonMcAuliffe - 24 Jan 2007