Skip to content
Snippets Groups Projects
Commit 43eeac23 authored by Leonardo Martinez Hornak's avatar Leonardo Martinez Hornak
Browse files

ADC module working, ISR is getting called

parent 224b8d02
No related branches found
No related tags found
No related merge requests found
......@@ -20,7 +20,7 @@
#define INCLUDE_ADC_H_
/**
* @brief Initializes ADC14, configuring it to use the temperature sensor
* @brief Initializes REFA and ADC14, configuring it to use the temperature sensor
*/
void initializeADC();
......
......@@ -2,20 +2,37 @@
#include "adc.h"
#include "fifo_function_queue.h"
static int adcval;
static unsigned int adcval;
//Callback function for queue
void (*temperature_ready_callback)();
void initializeADC(){
/* Temp Sensor ADC10CLK/4 */
//ADC10CTL1 = INCH_10 + ADC10DIV_3; //
//ADC10CTL0 = SREF_1 + ADC10SHT_3 + ADC10ON + ADC10IE + REFON;
//REF_A, waits until reference generator is not busy
while(REFCTL0 & REF_A_CTL0_GENBUSY);
//NVIC
//Set REF_A to be used, temp sensor enabled and REFOUT disabled
REFCTL0 = REF_A_CTL0_ON;
/* Espero que se estabilice la Ref del ADC */
//Sets ADC14ENC to 0 to make modifications to the registers, resets all register just in case
ADC14->CTL0 = 0;
//ADC Clock Divided by 3, ACLK, Single Channel - Single Conversion, SH signal sourced from sampling timer
ADC14->CTL0 |= ADC14_CTL0_DIV_2 + ADC14_CTL0_SSEL_2 + ADC14_CTL0_SHP;
//TODO Make sure time makes sense when timer is configured - Sample rate must not exceed 200ksps
//Sets default value to CTL1 register and
//sets resolution to 10 bits, low power mode (sample rate must not exceed 200ksps), temperature sensor selected for ADC input channel MAX - 1, ADC14CSTARTADDx = 0
//ADC14->CTL1 = ADC14_CTL1_RES_1 + ADC14_CTL1_PWRMD_2 + ADC14_CTL1_TCMAP;
ADC14->CTL1 = ADC14_CTL1_RES_1 + ADC14_CTL1_TCMAP;
//Sets Channel 22 as input channel, single ended mode, V(R+) = Vref buffered / V(R-) = Vss
ADC14->MCTL[0]= ADC14_MCTLN_INCH_22 + ADC14_MCTLN_VRSEL_1;
//TODO Review this function
//Wait for ADC to stabilize
__delay_cycles(1000);
}
......@@ -26,26 +43,37 @@ void setTempCallbackFunction(void *callback_function)
void runADCConversion(){
/* Start samppling and conversionb*/
//ADC10CTL0 |= ENC + ADC10SC + ADC10ON+ REFON;
//ADC14 is turned on, enable conversion, start conversion,
ADC14->CTL0 |= ADC14_CTL0_ON + ADC14_CTL0_ENC + ADC14_CTL0_SC;
//Enable ISRs (ADC Register 0 - Channel 22)
ADC14 -> IER0 |= ADC14_IER0_IE0;
NVIC_SetPriority(ADC14_IRQn,3);
NVIC_EnableIRQ(ADC14_IRQn);
}
int getTemperatureReading(){
int temp;
/* Convert ADC value to celsius degrees*/
temp = (((adcval - 673) * 423)/1024);
//Converts mVolts to miliCelsius using temperature sensor transfer function (no calibration)
//Using 10 bits resolution
temp = (((adcval - 686) * 512)/1024);
return temp;
}
void ADC14_IRQHandler(void)
{
//addToFunctionQueue(temperature_ready_callback);
/*
adcval = ADC10MEM;
ADC10CTL0 &= ~ENC;
ADC10CTL0 &= ~(ADC10ON + REFON);
addToFunctionQueue(temperature_ready_callback);
//Reading to ADC14MEM clears the IFG
adcval = ADC14->MEM[0];
ADC14->CTL0 &= ~ADC14_CTL0_ENC;
ADC14->CTL0 &= ~ADC14_CTL0_ON;
__low_power_mode_off_on_exit();
*/
}
//Disable ISRs
ADC14 -> IER0 &= ~ADC14_IER0_IE0;
NVIC_DisableIRQ(ADC14_IRQn);
}
......@@ -3,7 +3,7 @@
void updateTemperatureReading(void);
static int body_temperature;
volatile static int body_temperature;
void initializeBodyTemperature(void)
{
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment