Other Parts Discussed in Thread: ENERGIA, MSP432WARE
Tool/software: Code Composer Studio
Hi, we are currently working on a project and we are unable to get the readings we want.
We are testing out a CO2 detector that gives out analog signal ( assumed so as we just analogread() on energia ) but we are using CCS for future reference.
We used an example given by MSP432Ware under Single Conversion Repeat
This is our code that we have written
/* DriverLib Includes */
#include "driverlib.h"
/* Standard Includes */
#include <stdint.h>
#include <stdbool.h>
static volatile uint16_t curADCResult;
static volatile float normalizedADCRes;
int main(void)
{
/* Stop Watchdog */
MAP_WDT_A_holdTimer();
curADCResult = 0;
FlashCtl_setWaitState(FLASH_BANK0,2);
FlashCtl_setWaitState(FLASH_BANK1, 2);
PCM_setPowerState(PCM_AM_LDO_VCORE1);
CS_setDCOCenteredFrequency(CS_DCO_FREQUENCY_48);
FPU_enableModule();
FPU_enableLazyStacking();
ADC14_enableModule();
ADC14_initModule(ADC_CLOCKSOURCE_MCLK, ADC_PREDIVIDER_1, ADC_DIVIDER_4, 0);
GPIO_setAsPeripheralModuleFunctionInputPin(GPIO_PORT_P5, GPIO_PIN5, GPIO_PRIMARY_MODULE_FUNCTION);//SET CO2 SENSOR INPUT
ADC14_configureSingleSampleMode(ADC_MEM0, true);
ADC14_configureConversionMemory(ADC_MEM0, ADC_VREFPOS_AVCC_VREFNEG_VSS,ADC_INPUT_A0, false);
ADC14_enableSampleTimer(ADC_MANUAL_ITERATION);
ADC14_enableConversion();
ADC14_toggleConversionTrigger();
ADC14_enableInterrupt(ADC_INT0);
Interrupt_enableInterrupt(INT_ADC14);
Interrupt_enableMaster();
GPIO_setAsOutputPin(GPIO_PORT_P2, GPIO_PIN0);//RED
GPIO_setOutputLowOnPin(GPIO_PORT_P2, GPIO_PIN0);
GPIO_setAsOutputPin(GPIO_PORT_P2, GPIO_PIN1);//GREEN
GPIO_setOutputLowOnPin(GPIO_PORT_P2, GPIO_PIN1);
GPIO_setAsOutputPin(GPIO_PORT_P2, GPIO_PIN2);//BLUE
GPIO_setOutputLowOnPin(GPIO_PORT_P2, GPIO_PIN2);
volatile uint32_t u;
uint32_t volatile i;
while(1)
{
PCM_gotoLPM0();
i = (int)normalizedADCRes;
if(i<= 100)
{
GPIO_setOutputHighOnPin(GPIO_PORT_P2, GPIO_PIN1);//green light up
GPIO_setOutputLowOnPin(GPIO_PORT_P2, GPIO_PIN2);
GPIO_setOutputLowOnPin(GPIO_PORT_P2, GPIO_PIN0);
}
else if ((i>100) && (i<200))
{
GPIO_setOutputHighOnPin(GPIO_PORT_P2, GPIO_PIN2);//Blue light up
GPIO_setOutputLowOnPin(GPIO_PORT_P2, GPIO_PIN1);
GPIO_setOutputLowOnPin(GPIO_PORT_P2, GPIO_PIN0);
}
else if(i>=200)
{
GPIO_setOutputHighOnPin(GPIO_PORT_P2, GPIO_PIN0);//Red light up
GPIO_setOutputLowOnPin(GPIO_PORT_P2, GPIO_PIN1);
GPIO_setOutputLowOnPin(GPIO_PORT_P2, GPIO_PIN2);
}
for(u=1000;u>0;u--);
}
}
void ADC14_IRQHandler(void)
{
uint64_t status = ADC14_getEnabledInterruptStatus();
ADC14_clearInterruptFlag(status);
if(ADC_INT0 & status)
{
curADCResult = ADC14_getResult(ADC_MEM0);
normalizedADCRes = (curADCResult * 5)/16384;
ADC14_toggleConversionTrigger();
}
}
Please do help to advice with this code, we would really appreciate the offer . Thank you :D