Tool/software: Code Composer Studio
Dear all,
So, I botched up two example codes, and here it is:
#include "driverlib.h"
uint16_t results[4]; // SD24 Conversion and Temp Results
// results[0] = raw SD24 results
// results[1] = temp in K
// results[2] = temp in C
// results[3] = temp in F
uint8_t Flag_1 = 0; //Flag 1 for ADC
unsigned int Flag_2 = 0; //Flag 2 for Timer
#define TIMER_PERIOD 10
unsigned int TIMER_PERIOD_PERIOD = 0;
void main(void) {
// Stop WDT
WDT_hold(WDT_BASE);
// Internal ref
SD24_init(SD24_BASE, SD24_REF_INTERNAL);
//Ch0 single mode, internal temp sensor
SD24_initConverterAdvancedParam param = {0};
param.converter = SD24_CONVERTER_0;
param.conversionMode = SD24_SINGLE_MODE;
param.groupEnable = SD24_NOT_GROUPED;
param.inputChannel = SD24_INPUT_CH_TEMPERATURE;
param.dataFormat = SD24_DATA_FORMAT_2COMPLEMENT;
param.interruptDelay = SD24_FOURTH_SAMPLE_INTERRUPT;
param.oversampleRatio = SD24_OVERSAMPLE_256;
param.gain = SD24_GAIN_1;
SD24_initConverterAdvanced(SD24_BASE, ¶m);
SD24_enableInterrupt(SD24_BASE, SD24_CONVERTER_0, SD24_CONVERTER_INTERRUPT);
// Delay ~200us for 1.2V ref to settle
__delay_cycles(3200);
// Set P2.1 as output pin to drive the LED
GPIO_setAsOutputPin(GPIO_PORT_P2, GPIO_PIN1);
// Timer_A Setup
Timer_A_initUpModeParam upModeConfig =
{
TIMER_A_CLOCKSOURCE_SMCLK, // SMCLK Clock Source
TIMER_A_CLOCKSOURCE_DIVIDER_1, // SMCLK/8 = 256kHz
TIMER_PERIOD, // 250ms
TIMER_A_TAIE_INTERRUPT_DISABLE, // Disable Overflow ISR
TIMER_A_CCIE_CCR0_INTERRUPT_ENABLE, // Enable CCR0 interrupt
TIMER_A_DO_CLEAR // Clear Counter
};
while(1) {
// Start conversion
SD24_startConverterConversion(SD24_BASE, SD24_CONVERTER_0);
// Enter LPM0 w/ interrupts
//__bis_SR_register(LPM0_bits | GIE);
// For debugger
__no_operation();
if (Flag_1 == 1)// the Interrupt routine is complete
{
Flag_2 = 1;
GPIO_setOutputLowOnPin(GPIO_PORT_P2, GPIO_PIN1);// Turn on LED
// Configure the timer to use ACLK and interrupt when timer reaches CCR0
Timer_A_initUpMode(TIMER_A0_BASE, &upModeConfig);
Timer_A_startCounter(TIMER_A0_BASE, TIMER_A_UP_MODE);
// Calculate Temperatures in different scales
results[1] = ((unsigned long)results[0] * 1200)/70711;
results[2] = results[1] - 273;
results[3] = (results[2] * 9/5) + 32;
Flag_2 = 0;
__delay_cycles(1000);
__no_operation();
TIMER_PERIOD_PERIOD = 0;
GPIO_setOutputHighOnPin(GPIO_PORT_P2, GPIO_PIN1); // Turn Off LED
Flag_1 = 0;
//Flag_2 = 0;
}
__bis_SR_register(LPM0_bits | GIE);
//GPIO_setOutputHighOnPin(GPIO_PORT_P2, GPIO_PIN1);
// Calculate Temperatures in different scales
//results[1] = ((unsigned long)results[0] * 1200)/70711;
//results[2] = results[1] - 273;
//results[3] = (results[2] * 9/5) + 32;
__no_operation(); // SET BREAKPOINT HERE
}
}
//----------------------------------------------------------------------------------------------------------------
//Interrupt Functions
//---------------------------------------------------------------------------------------------------------------
//ADC
#if defined(__TI_COMPILER_VERSION__) || defined(__IAR_SYSTEMS_ICC__)
#pragma vector=SD24_VECTOR
__interrupt void SD24_ISR(void) {
#elif defined(__GNUC__)
void __attribute__ ((interrupt(SD24_VECTOR))) SD24_ISR (void)
{
#else
#error Compiler not supported!
#endif
switch (__even_in_range(SD24IV,SD24IV_SD24MEM3))
{
case SD24IV_NONE: break;
case SD24IV_SD24OVIFG: break;
case SD24IV_SD24MEM0:
// Save CH0 results (clears IFG)
results[0] = SD24_getHighWordResults(SD24_BASE, SD24_CONVERTER_0);
break;
case SD24IV_SD24MEM1: break;
case SD24IV_SD24MEM2: break;
case SD24IV_SD24MEM3: break;
default: break;
}
Flag_1 = 1;
// __bic_SR_register_on_exit(LPM0_bits); // Wake up from LPM0
}
//Timer_A---------------------------------------------------------------------------------------------------------------
#if defined(__TI_COMPILER_VERSION__) || defined(__IAR_SYSTEMS_ICC__)
#pragma vector=TIMER0_A0_VECTOR
__interrupt
#elif defined(__GNUC__)
__attribute__((interrupt(TIMER0_A0_VECTOR)))
#endif
void TA0_ISR(void) {
// TIMER0_A0_VECTOR only contains CCR0 interrupt
// No need to check/clear interrupt flags, toggle LED to show ISR reached
//GPIO_toggleOutputOnPin(GPIO_PORT_P1, GPIO_PIN4);
if (Flag_2 == 1)
{
TIMER_PERIOD_PERIOD = TIMER_PERIOD_PERIOD +1;
}
}
The idea is to time the calculation operation of converting the unsigned long into Kelvin, Celcius, and Fahrenheit, over and over again (For consistency).
The Flag_1, checks if a new ADC data is available.
The Flag_2 is to stop the TIMER_PERIOD_PERIOD counter.
Thus the time taken should be = 61.04(ns) * 10(TIMER_PERIOD) * TIMER_PERIOD_PERIOD.
I am pretty sure, this is the wrong way to approach this, so any help would be appreciated, and where do I put the breakpoint to read the TIMER_PERIOD_PERIOD value?
Thank you.
Regards,
Neal