Part Number: MSP432P401R
Tool/software: Code Composer Studio
Hello you guys,
I struggle with a strange problem which occures when using the multi channel adc14 sampling. I have the following code in CCS9.3:
*
* MSP432P401
* ------------------
* | P2.6 |----> Th OP A3
* | P2.7 |----> Th OP A4
* /|\| P2.3 |----> Th OP A1
* | | P2.5 |----> Th OP A0
* P5.5 |<---- A0 In
* | P5.4 |<---- A1 In
* | |
* | |
*
******************************************************************************/
/* DriverLib Includes */
#include <ti/devices/msp432p4xx/driverlib/driverlib.h>
/* Standard Includes */
#include <stdint.h>
#include <stdbool.h>
#include <string.h>
#include <stdio.h>
#include <math.h>
//for the interrupt sampling
//volatile float adcResult;
//volatile float adcResult_2;
//for the loop sampling
volatile uint16_t i=0; //running variable for the bins
volatile float a=0; //running variable for the samples
volatile uint16_t t=0; //variable deciding whether being within first 10 seconds or not
static uint16_t resultsBuffer[2];
volatile float mittelwert[2]; //actual moving mean
//volatile float Norm = 1.63/ 16384; //1.63 = Vref+; 16384 = Digitalisierungs-steps
volatile float Norm = 2.5/16384;
volatile uint32_t samples = 10; //amount of samples _247 für gesamt
volatile uint32_t bins = 10; //amount of bins must be equal to the index (x) of mess[x]
volatile float mess1[10]; //array off all bins, maximum is 4049
volatile float mess2[10];
//volatile uint32_t clock; //variable to track the clock frequency
int main(void)
{
/* Halting WDT */
WDT_A_holdTimer(); //Watchdog aus
Interrupt_enableSleepOnIsrExit(); //prozessor auf sleep wenn interrupt service routine verlassen wird
memset(resultsBuffer, 0x00, 2 * sizeof(uint16_t));
//Enable FPU for floating points operation
FPU_enableModule(); //floation point module enable, for faster mathematics
FPU_enableLazyStacking(); //refer to fuction description for more information
//SystemClock Configuration
//needed to allow 48MHz operation
PCM_setCoreVoltageLevel(PCM_VCORE1); //sets higher core voltage in order to maintain higher clock frequencies
FlashCtl_setWaitState(FLASH_BANK0, 2); //sets the wait states used by the falsh controller. needed to operate at higher frequencies
FlashCtl_setWaitState(FLASH_BANK1, 2); // 1 is little smaller than 10s for the toggle to change, 2 is little bigger
// refer to Datasheet p. 30 table 5.8 for detail information about wait states 1 or 2
//actual clock configuration
CS_startHFXT(false);
CS_setDCOCenteredFrequency(CS_DCO_FREQUENCY_48); //sets the DCO_CLK to 24MHz
CS_initClockSignal(CS_SMCLK, CS_DCOCLK_SELECT, CS_CLOCK_DIVIDER_1);
//![Simple ADC14 Configure]
/* Initializing ADC (SMCLK/1/1) */ //f_SMCLK=DCOCLK/CS_CLOCK_DIVIDER=24Mhz/1=24MHz
ADC14_enableModule(); //enable ADC
ADC14_initModule(ADC_CLOCKSOURCE_SMCLK, ADC_PREDIVIDER_1, ADC_DIVIDER_1,0);
//sets ADC Clock to ADCCLK=SMCLK/PREDEVIDER/DEVIDER=24MHz/4/1=6MHz
//sets Internal Reference Voltage to 2.5V
MAP_REF_A_setReferenceVoltage(REF_A_VREF2_5V);
MAP_REF_A_enableReferenceVoltage();
/* Configuring ADC Memory (ADC_MEM0-ADC_MEM3 A0/A1) in repeat mode
* with use of internal 2.5V references */
ADC14_configureMultiSequenceMode(ADC_MEM0, ADC_MEM4, true);
ADC14_configureConversionMemory(ADC_MEM0,ADC_VREFPOS_INTBUF_VREFNEG_VSS,ADC_INPUT_A0, false);
ADC14_configureConversionMemory(ADC_MEM1,ADC_VREFPOS_INTBUF_VREFNEG_VSS,ADC_INPUT_A1, false);
//hier mit den MEMS aufpassen. weil mem2 eigentlich zu a2 gehört, ich schreibe aber a3 hinein da es den a2 pin 5.3 auf dem board nicht gibt
//ADC14_setSampleHoldTime(10,0); //------not working so far, must be checked-------
/* Setting up GPIO pins as analog inputs (and references) */
GPIO_setAsPeripheralModuleFunctionInputPin(GPIO_PORT_P5,GPIO_PIN5 | GPIO_PIN4, GPIO_TERTIARY_MODULE_FUNCTION);
//tertiary because bits of \b P5SEL1/2 = 1 for analog input operation
//GPIO_setAsPeripheralModuleFunctionInputPin(GPIO_PORT_P5,GPIO_PIN7 | GPIO_PIN6 | GPIO_PIN5 | GPIO_PIN4, GPIO_TERTIARY_MODULE_FUNCTION);
//VREF- = GPIO_PIN7, VREF+ = GPIO_PIN6, DATA_In = GPIO_PIN5, GPIO_PIN4 = do not know yet
GPIO_setAsOutputPin(GPIO_PORT_P2, GPIO_PIN5|GPIO_PIN3|GPIO_PIN6|GPIO_PIN7); //sets Pin 2.3,2.5,2.6,2.7 as GPIO output pins
//Enabling sample timer in auto iteration mode and interrupts
ADC14_enableSampleTimer(ADC_AUTOMATIC_ITERATION); // automatically samples the next value if on is processed
//ADC14_enableInterrupt(ADC_INT0);//enables the interrupt source
/* Enabling Interrupts */
// Interrupt_enableInterrupt(INT_ADC14); //enables the interrupt of the ADC14
// Interrupt_enableMaster();//just for processing the interrupt to the processor
/* Triggering the start of the sample */
ADC14_enableConversion(); //enables conversion of the ADC data
ADC14_toggleConversionTrigger(); //start the sampling
//clock = CS_getSMCLK();
while (1) //loop for calculating the moving mean
{
//PCM_gotoLPM0();//enters low power mode (sleep)
if(t==0)
{
while(a<samples) //calculates the mean for the each bin whereby each bin has samples sample points
{
ADC14_getMultiSequenceResult(resultsBuffer);
mess1[i]=mess1[i]*(a/(a+1))+resultsBuffer[0]*Norm*(1/(a+1)); //calculates the mean from the sample points
mess2[i]=mess2[i]*(a/(a+1))+resultsBuffer[1]*Norm*(1/(a+1));
a++; //jump to the next sample point
}
mittelwert[0]=mittelwert[0]+mess1[i]/bins; //calculates final mean for all the bins
mittelwert[1]=mittelwert[1]+mess2[i]/bins;
i++; //increments the bin
a=0; //resets the samples
if(i==bins) //if i is equal to the maximum number of bins the current bin is set to bin 0
{
i=0; //jump to the first bin
t=1; //sets t to 1 in order to jump to the next 10s interval
}
}
else //for all the new bin after the first 10s
{
mittelwert[0]=mittelwert[0]-mess1[i]/bins; //subtracts the oldest bin from mean
mittelwert[1]=mittelwert[1]-mess2[i]/bins;
while(a<samples) //calculates the mean for each bin whereby each bin has samples sample points
{
ADC14_getMultiSequenceResult(resultsBuffer);
mess1[i]=mess1[i]*(a/(a+1))+resultsBuffer[0]*Norm*(1/(a+1)); //calculates the mean from the sample points
mess2[i]=mess2[i]*(a/(a+1))+resultsBuffer[1]*Norm*(1/(a+1));
a++; //jump to the next sample point
}
mittelwert[0]=mittelwert[0]+mess1[i]/bins; //calculates final mean for all the bins
mittelwert[1]=mittelwert[1]+mess2[i]/bins;
a=0; //resets the samples
i++; //increments the bin
if(i==bins) //if i is equal to the maximum number of bins the current bin is set to bin 0
{
i=0; //jump to the first bin
}
}
if(mittelwert[0]>=1.25 || mittelwert[1]>=1.25) //task to check if the threshold for the SAR is surpassed
{
GPIO_setOutputHighOnPin(GPIO_PORT_P2, GPIO_PIN5); //set output high if threshold is passed
}
else
{
GPIO_setOutputLowOnPin(GPIO_PORT_P2, GPIO_PIN5); //set output low if threshold is not surpassed
}
}
}
So when I try to increment i with the i++ and the routine goes back to while loop, i is somehow set back to 0. The strange thing is, it worked with the code before. Can anyone help?
Best regards