adc working
This commit is contained in:
59
src/measure.c
Normal file
59
src/measure.c
Normal file
@ -0,0 +1,59 @@
|
||||
/*
|
||||
* adc.cpp
|
||||
*
|
||||
* Created on: 03.10.2014
|
||||
* Author: wn
|
||||
*/
|
||||
|
||||
#include <msp430g2553.h>
|
||||
#include <stdint.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
#include "measure.h"
|
||||
#include "PontCoopScheduler.h"
|
||||
#include "display.h"
|
||||
#include "gpio.h"
|
||||
|
||||
|
||||
const float R_REF = 3000.0;
|
||||
const uint16_t N_MAX = 1023;
|
||||
const float PT1000_R0 = 1000.0;
|
||||
const float PT1000_Coeff = 3.85e-3;
|
||||
|
||||
|
||||
|
||||
void measureInit(void *handleArg) {
|
||||
ADC10CTL0 = SREF1 | ADC10SHT_3 | ADC10SR | REFOUT | REFON | REF2_5V | ADC10ON;
|
||||
ADC10CTL1 = INCH_3;
|
||||
ADC10AE0 = BIT3;
|
||||
}
|
||||
|
||||
void measureCollectAndProcessConversion(void *handleArg);
|
||||
|
||||
void measureStartConversion(void *handleArg) {
|
||||
gpioSetPin(TESTPIN1, HIGH);
|
||||
ADC10CTL0 |= ENC | ADC10SC;
|
||||
schAdd(measureCollectAndProcessConversion, NULL, 10, 0);
|
||||
gpioSetPin(TESTPIN1, LOW);
|
||||
}
|
||||
|
||||
void measureCollectAndProcessConversion(void *handleArg) {
|
||||
gpioSetPin(TESTPIN2, HIGH);
|
||||
uint16_t n = 0xffff;
|
||||
if ((ADC10CTL0 & ADC10IFG) != 0) {
|
||||
n = ADC10MEM;
|
||||
ADC10CTL0 &= ~(ADC10IFG | ENC);
|
||||
}
|
||||
|
||||
// process adcValue
|
||||
// store result in variable temperature
|
||||
float r = ((((float)N_MAX) / ((float)n)) - 1.0) * R_REF;
|
||||
float t = (r / PT1000_R0 - 1) / PT1000_Coeff;
|
||||
|
||||
uint8_t temperature = (uint8_t)t;
|
||||
|
||||
displaySetValue(temperature);
|
||||
gpioSetPin(TESTPIN2, LOW);
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user