185
ADC10 setup is similar to the setup we have seen in the last example. However, this time we enabled
ADC10 interrupt as this is an interrupt-based demo.
The ADC ISR is simple. Here we are just toggling P1.0 LED to indicate ADC conversion completion and
clearing ADC interrupt flag after reading ADC data value.
#pragma vector = ADC10_VECTOR
__interrupt void ADC10_ISR_HOOK(void)
{
P1OUT ^= BIT0;
ADC_Value = ADC10MEM;
ADC10CTL0 &= ~ADC10IFG;
}
In the main loop, AD conversion process starts using software trigger. The result of this conversion is
extracted from the ADC ISR shown above. The ADC data obtained from the ISR is shown on a LCD. Two
values are shown – actual ADC count and the corresponding temperature against that ADC readout.
// ADC Start Conversion - Software trigger
ADC10CTL0 |= ADC10SC;
P1OUT ^= BIT6;
t = get_volt(ADC_Value);
t = get_temp(t);
lcd_print(12, 0, ADC_Value);
lcd_print(12, 1, t);
delay_ms(200);
To extract temperature in degree Celsius, first the ADC count is converted to millivolts and then this
voltage value is translated to temperature value using the voltage vs temperature transfer function
shown earlier. T_offset is an optional constant that is used to negate any offset in temperature
readout.
unsigned int get_volt(unsigned int value)
{
return (unsigned int)((value * 3600.0) / 1023.0);
}
unsigned int get_temp(unsigned int value)
{
return (unsigned int)((((value / 1000.0) - 0.986) / 0.00355) + T_offset);
}