This thread has been locked.
If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.
Part Number: MSP432P401R
Tool/software: Code Composer Studio
I am using timer 32 to create delay( desired delay is of 50us), the delay time decreases as i decrease the count in the timer register, but after a particular count the delay stays at some value say 128us, how to attain a delay of 20us or below using a DCO freq of 48MHZ and timer32??
Gopalakrishnan,
I'd like to help you, but can you share your code so I can better assist you? Are you using TI Drivers or Driverlib or Baremetal code?
hello Evan,
I sorted out the issue i had before,
1) i wrote a code using timer32 to do ADC on a sample with a programmed delay
2) the count value in the program decides the delay
3) the code works fine till a certain amount of delay
4) i found that the extra delay was due to the conversion time of ADC and the time taken for the remaining part of the program to execute ( i removed the other part of the program like ADC and UART things, the program was fine with desired value of delay )
i now need some advice on how to reduce this delay caused by the other part of the code
i have also attached the code i used
thank you
//* DriverLib Includes */ #include "driverlib.h" /* Standard Includes */ #include <stdint.h> #include <stdbool.h> /* variable intialization */ static volatile uint16_t curADCResult,dval,i,j; static volatile uint32_t dec; static volatile float resultsBuffer[UINT8_MAX],d; static volatile uint8_t resPos; char itos[8]={0,}; /* UART configuration with 9600 baud rate and 48MHZ clock*/ const eUSCI_UART_Config uartConfig = { EUSCI_A_UART_CLOCKSOURCE_SMCLK, // SMCLK Clock Source 312, // BRDIV = 78 8, // UCxBRF = 2 0, // UCxBRS = 0 EUSCI_A_UART_NO_PARITY, // No Parity EUSCI_A_UART_LSB_FIRST, // MSB First EUSCI_A_UART_ONE_STOP_BIT, // One stop bit EUSCI_A_UART_MODE, // UART mode EUSCI_A_UART_OVERSAMPLING_BAUDRATE_GENERATION // Oversampling }; int main(void) { /* Halting the Watchdog */ WDT_A_holdTimer(); /* temporary and count variable*/ curADCResult = 0; resPos = 0; /* Setting DCO to 48MHz */ CS_setDCOCenteredFrequency(CS_DCO_FREQUENCY_48); /* Setting MCLK to REFO at 48MHz for LF mode */ CS_initClockSignal(CS_MCLK, CS_DCOCLK_SELECT, CS_CLOCK_DIVIDER_1); PCM_setPowerState(PCM_AM_LF_VCORE0); /* Enabling the FPU for floating point operation */ FPU_enableModule(); FPU_enableLazyStacking(); /* Selecting P1.2 and P1.3 in UART mode */ GPIO_setAsPeripheralModuleFunctionInputPin(GPIO_PORT_P1, GPIO_PIN1 | GPIO_PIN2 | GPIO_PIN3, GPIO_PRIMARY_MODULE_FUNCTION); /*setting P2.5 as output and initializing to 0*/ GPIO_setAsOutputPin(GPIO_PORT_P2, GPIO_PIN5); GPIO_setOutputLowOnPin(GPIO_PORT_P2, GPIO_PIN5); /*setting LED Pin P1.0 as output and initializing to 0*/ GPIO_setAsOutputPin(GPIO_PORT_P1, GPIO_PIN0); GPIO_setOutputLowOnPin(GPIO_PORT_P1, GPIO_PIN0); /* Configuring GPIOs (5.5 A0) */ GPIO_setAsPeripheralModuleFunctionInputPin(GPIO_PORT_P5, GPIO_PIN5, GPIO_TERTIARY_MODULE_FUNCTION); /* Initializing ADC (MCLK/1/4) */ ADC14_enableModule(); ADC14_initModule(ADC_CLOCKSOURCE_MCLK, ADC_PREDIVIDER_1, ADC_DIVIDER_4, 0); /* Configuring ADC Memory */ ADC14_configureSingleSampleMode(ADC_MEM0, true); ADC14_configureConversionMemory(ADC_MEM0, ADC_VREFPOS_AVCC_VREFNEG_VSS, ADC_INPUT_A0, false); /* Configuring Sample Timer */ ADC14_enableSampleTimer(ADC_MANUAL_ITERATION); /* Configuring UART Module */ UART_initModule(EUSCI_A0_MODULE, &uartConfig); /* Enable UART module */ UART_enableModule(EUSCI_A0_MODULE); /* disabling UART receive interrupts */ UART_disableInterrupt(EUSCI_A0_MODULE, EUSCI_A_UART_RECEIVE_INTERRUPT); Interrupt_disableInterrupt(INT_EUSCIA0); /* Configuring Timer32 in periodic mode */ Timer32_initModule(TIMER32_0_MODULE, TIMER32_PRESCALER_1, TIMER32_32BIT, TIMER32_PERIODIC_MODE); /* setting count value to timer register*/ Timer32_setCount(TIMER32_0_MODULE,1090); /* enabling timer interrupts*/ Timer32_enableInterrupt(TIMER32_0_MODULE); /* starting timer32*/ Timer32_startTimer(TIMER32_0_MODULE, true); /* Enabling interrupts */ Interrupt_enableInterrupt(INT_T32_INT1); Interrupt_enableMaster(); /* Sleeping when not in use */ while (1) { PCM_gotoLPM0(); } } /* Timer32 ISR */ void timer32_isr(void) { /* clearing Timer32 interrupt flag*/ Timer32_clearInterruptFlag(TIMER32_0_MODULE); /* toggling P1.0 and P2.5*/ GPIO_toggleOutputOnPin(GPIO_PORT_P2, GPIO_PIN5); GPIO_toggleOutputOnPin(GPIO_PORT_P1, GPIO_PIN0); /*enabling ADC Conversion*/ ADC14_enableConversion(); /* transferring ADC result to a variable*/ curADCResult = ADC14_getResult(ADC_MEM0); /*ADC value conversion with respect to reference Voltage and storing it in array*/ resultsBuffer[resPos] = (curADCResult * 3.3) / 16384; resPos++; /* float value to string conversion*/ d = (curADCResult * 3.3) / 16384; dval=d; dec= (int)(d*100000)%100000; itos[7]='\n'; for(i=6;i>=2;i--) { itos[i]=(dec%10)+'0'; dec=dec/10; } itos[1]='.'; itos[0]=(dval%10)+'0'; /* Enabling/Toggling Conversion */ ADC14_toggleConversionTrigger(); /*transmitting converted values*/ for(j=0;j<8;j++) { UART_transmitData(EUSCI_A0_MODULE,itos[j]); } /* resetting timer32 register with count and starting it again*/ Timer32_setCount(TIMER32_0_MODULE,1090); Timer32_startTimer(TIMER32_0_MODULE, true); }
Gopalakrishnan,
I would first look at increasing the baud rate of your UART. you are using 9600 baud which is significantly slower than 115200 baud. That may help, but with regards to timing I'm not sure if this will still get you inside the window that you are looking for.
/* UART Configuration Parameter. These are the configuration parameters to * make the eUSCI A UART module to operate with a 115200 baud rate. These * values were calculated using the online calculator that TI provides * at: * software-dl.ti.com/.../index.html */ const eUSCI_UART_Config uartConfig = { EUSCI_A_UART_CLOCKSOURCE_SMCLK, // SMCLK Clock Source 13, // BRDIV = 13 0, // UCxBRF = 0 37, // UCxBRS = 37 EUSCI_A_UART_NO_PARITY, // No Parity EUSCI_A_UART_MSB_FIRST, // MSB First EUSCI_A_UART_ONE_STOP_BIT, // One stop bit EUSCI_A_UART_MODE, // UART mode EUSCI_A_UART_OVERSAMPLING_BAUDRATE_GENERATION // Oversampling };
If this doesn't work, I would adjust the code to continue to use the 115200 baud, but remove your floating point to string conversion math and see if this works within your window. Lastly, if this doesn't work, I would look towards removing your UART_TransmitData outside of your interrupt service routine and instead transmit before going back to LPMx mode in your while(1). Let me know if this helps.
Evan,
iam clear with the baud rate problem and i modified the code...i must have 30 samples per cycle ...or atleast a minimum of 20 samples per cycle..
thank you
Hello Evan,
i tried dock light and its working fine, i have another doubt... in the code that i have uploaded when i try to read data from the array as shown below,
resultsBuffer[resPos] = (curADCResult * 3.3) / 16384;
d=redultsBuffer[resPos];
i often find the value at d to be 0 ratherbeing the value captured from adc at that moment, what might be the problem?
is there any other way i cant get assistance during my work hours, im from india and i work from 0900 to 1700?
thank you,
Hi Gopalakrishnan,
Can you please review the code attached to this thread. A colleague of mine and I sat down and created a simple example of what you are looking for running at 44khz. There are a number of changes that were made, please check the comments for the changes.
We also would like to kindly ask that you update your driverlib and make sure you are using the Red MSP432 LaunchPad. There are a number of changes that have been made for the newer versions of driverlib and the Red LaunchPad contains Rev C silicon that has a number of bug fixes.
This code will send your ADC bytes in raw hex value, from here I would investigate if you can still do your math with this higher baud rate (1Mbaud currently). Instead of using the manual math on the CPU, you can leverage the ARM Floating-point Processing Unit (FPU) to do your math a little faster if you'd like. This can be done through the CMSIS DSP Library. See this app note for more details:
Code is attached as "customer.c"
/* * customer.c * */ //* DriverLib Includes */ #include <ti/devices/msp432p4xx/driverlib/driverlib.h> /* Standard Includes */ #include <stdint.h> #include <stdbool.h> /* variable intialization */ static volatile uint16_t curADCResult,dval,i,j; static volatile uint32_t dec; static volatile float resultsBuffer[UINT8_MAX],d; static volatile uint8_t resPos; char itos[8]={0,}; /* UART configuration with 9600 baud rate and 48MHZ clock*/ /* * 8bytes at 1M baud - 6.7ms, sampling rate is 12Khz, 83us */ const eUSCI_UART_Config uartConfig = { EUSCI_A_UART_CLOCKSOURCE_SMCLK, // SMCLK Clock Source 1, // BRDIV = 78 8, // UCxBRF = 2 0, // UCxBRS = 0 EUSCI_A_UART_NO_PARITY, // No Parity EUSCI_A_UART_LSB_FIRST, // MSB First EUSCI_A_UART_ONE_STOP_BIT, // One stop bit EUSCI_A_UART_MODE, // UART mode EUSCI_A_UART_OVERSAMPLING_BAUDRATE_GENERATION // Oversampling }; int main(void) { /* Halting the Watchdog */ MAP_WDT_A_holdTimer(); /* temporary and count variable*/ curADCResult = 0; resPos = 0; /* * If going to run DCO at 48Mhz then you need to run at * Vcore1 and Flash wait state 1 */ MAP_PCM_setCoreVoltageLevel(PCM_VCORE1); /* * Revision C silicon supports wait states of 1 at 48Mhz * Revision B (black launchpad) requires 2 */ MAP_FlashCtl_setWaitState(FLASH_BANK0, 1); MAP_FlashCtl_setWaitState(FLASH_BANK1, 1); /* Setting DCO to 48MHz */ MAP_CS_setDCOCenteredFrequency(CS_DCO_FREQUENCY_48); /* Setting MCLK to REFO at 48MHz for LF mode */ MAP_CS_initClockSignal(CS_MCLK, CS_DCOCLK_SELECT, CS_CLOCK_DIVIDER_1); /* * USE SMCLK for ADC and not MCLK */ MAP_CS_initClockSignal(CS_SMCLK, CS_DCOCLK_SELECT, CS_CLOCK_DIVIDER_2); /* * LF mode suggest 125Khz */ // MAP_PCM_setPowerState(PCM_AM_LF_VCORE0); /* Enabling the FPU for floating point operation */ MAP_FPU_enableModule(); MAP_FPU_enableLazyStacking(); /* Selecting P1.2 and P1.3 in UART mode */ MAP_GPIO_setAsPeripheralModuleFunctionInputPin(GPIO_PORT_P1, GPIO_PIN1 | GPIO_PIN2 | GPIO_PIN3, GPIO_PRIMARY_MODULE_FUNCTION); /*setting P2.5 as output and initializing to 0*/ MAP_GPIO_setAsOutputPin(GPIO_PORT_P2, GPIO_PIN5); MAP_GPIO_setOutputLowOnPin(GPIO_PORT_P2, GPIO_PIN5); /*setting LED Pin P1.0 as output and initializing to 0*/ MAP_GPIO_setAsOutputPin(GPIO_PORT_P1, GPIO_PIN0); MAP_GPIO_setOutputLowOnPin(GPIO_PORT_P1, GPIO_PIN0); /* Configuring GPIOs (5.5 A0) */ MAP_GPIO_setAsPeripheralModuleFunctionInputPin(GPIO_PORT_P5, GPIO_PIN5, GPIO_TERTIARY_MODULE_FUNCTION); /* * Initializing ADC (MCLK/1/4) */ MAP_ADC14_enableModule(); /* * The MCLK is at 48Mhz which is not valid per the datasheet. */ MAP_ADC14_initModule(ADC_CLOCKSOURCE_SMCLK, ADC_PREDIVIDER_1, ADC_DIVIDER_2, 0); /* Configuring ADC Memory */ MAP_ADC14_configureSingleSampleMode(ADC_MEM0, true); MAP_ADC14_configureConversionMemory(ADC_MEM0, ADC_VREFPOS_AVCC_VREFNEG_VSS, ADC_INPUT_A0, false); /* Configuring Sample Timer */ MAP_ADC14_enableSampleTimer(ADC_MANUAL_ITERATION); /* * default sample time is 4 clock cycles */ /* * enabling ADC Conversion */ MAP_ADC14_enableConversion(); /* Configuring UART Module */ //MAP_UART_initModule(EUSCI_A0_MODULE, &uartConfig); /* * updated driverlib SDK 1_30_00_40 */ MAP_UART_initModule(EUSCI_A0_BASE, &uartConfig); /* Enable UART module */ // MAP_UART_enableModule(EUSCI_A0_MODULE); /* * updated driverlib SDK 1_30_00_40 */ MAP_UART_enableModule(EUSCI_A0_BASE); /* disabling UART receive interrupts */ // MAP_UART_disableInterrupt(EUSCI_A0_MODULE, EUSCI_A_UART_RECEIVE_INTERRUPT); /* * updated driverlib SDK 1_30_00_40 */ MAP_UART_disableInterrupt(EUSCI_A0_BASE, EUSCI_A_UART_RECEIVE_INTERRUPT); MAP_Interrupt_disableInterrupt(INT_EUSCIA0); /* Configuring Timer32 in periodic mode */ // MAP_Timer32_initModule(TIMER32_0_MODULE, TIMER32_PRESCALER_1, TIMER32_32BIT, // TIMER32_PERIODIC_MODE); /* * updated driverlib SDK 1_30_00_40 */ MAP_Timer32_initModule(TIMER32_0_BASE, TIMER32_PRESCALER_1, TIMER32_32BIT, TIMER32_PERIODIC_MODE); /* setting count value to timer register*/ // MAP_Timer32_setCount(TIMER32_0_MODULE,1090); /* * updated driverlib SDK 1_30_00_40 */ /* * Timer source is the MCLK which is 48Mhz * in order to get 12Khz you would need a * value of 4000 */ MAP_Timer32_setCount(TIMER32_0_BASE,1090); /* enabling timer interrupts*/ // MAP_Timer32_enableInterrupt(TIMER32_0_MODULE); /* * updated driverlib SDK 1_30_00_40 */ MAP_Timer32_enableInterrupt(TIMER32_0_BASE); /* Enabling interrupts */ MAP_Interrupt_enableInterrupt(INT_T32_INT1); MAP_Interrupt_enableMaster(); /* starting timer32*/ /* * updated driverlib SDK 1_30_00_40 */ /* * if one-shot mode is set to true then * only called once and must be reintialized */ // MAP_Timer32_startTimer(TIMER32_0_BASE, true); MAP_Timer32_startTimer(TIMER32_0_BASE, false); /* Sleeping when not in use */ while (1) { MAP_PCM_gotoLPM0(); } } /* Timer32 ISR */ //void timer32_isr(void) void T32_INT1_IRQHandler(void) { /* clearing Timer32 interrupt flag*/ // MAP_Timer32_clearInterruptFlag(TIMER32_0_MODULE); /* * updated driverlib SDK 1_30_00_40 */ MAP_Timer32_clearInterruptFlag(TIMER32_0_BASE); /* toggling P1.0 and P2.5*/ MAP_GPIO_toggleOutputOnPin(GPIO_PORT_P2, GPIO_PIN5); MAP_GPIO_toggleOutputOnPin(GPIO_PORT_P1, GPIO_PIN0); /* Enabling/Toggling Conversion */ MAP_ADC14_toggleConversionTrigger(); /* * Poll waiting for interrupt to complete */ while(!(MAP_ADC14_getInterruptStatus() & ADC_INT0)); /* * toggling P1.0 and P2.5 * Debug */ // MAP_GPIO_toggleOutputOnPin(GPIO_PORT_P2, GPIO_PIN5); MAP_GPIO_toggleOutputOnPin(GPIO_PORT_P1, GPIO_PIN0); /* transferring ADC result to a variable*/ curADCResult = MAP_ADC14_getResult(ADC_MEM0); MAP_UART_transmitData(EUSCI_A0_BASE,(uint8_t)curADCResult); curADCResult = curADCResult >> 8; MAP_UART_transmitData(EUSCI_A0_BASE,(uint8_t)curADCResult); /*ADC value conversion with respect to reference Voltage and storing it in array*/ // resultsBuffer[resPos] = (curADCResult * 3.3) / 16384; // resPos++; // // /* float value to string conversion*/ // d = (curADCResult * 3.3) / 16384; // dval=d; // dec= (int)(d*100000)%100000; // itos[7]='\n'; // for(i=6;i>=2;i--) // { // itos[i]=(dec%10)+'0'; // dec=dec/10; // } // itos[1]='.'; // itos[0]=(dval%10)+'0'; // // /*transmitting converted values*/ // for(j=0;j<8;j++) // { //// MAP_UART_transmitData(EUSCI_A0_MODULE,itos[j]); // /* // * updated driverlib SDK 1_30_00_40 // */ // MAP_UART_transmitData(EUSCI_A0_BASE,itos[j]); // // } /* * The timer is in periodic mode so it automatically resets to * set count. */ /* resetting timer32 register with count and starting it again*/ // MAP_Timer32_setCount(TIMER32_0_MODULE,1090); /* * updated driverlib SDK 1_30_00_40 */ // MAP_Timer32_setCount(TIMER32_0_BASE,1090); // MAP_Timer32_startTimer(TIMER32_0_MODULE, true); /* * updated driverlib SDK 1_30_00_40 */ // MAP_Timer32_startTimer(TIMER32_0_BASE, true); /* * toggling P1.0 and P2.5 * Debug */ MAP_GPIO_toggleOutputOnPin(GPIO_PORT_P2, GPIO_PIN5); // MAP_GPIO_toggleOutputOnPin(GPIO_PORT_P1, GPIO_PIN0); }
Evan,
what will be the major difference if i used a black MSP432?
and is the baud rate 1M, and what does the sampling at 12Khz comment signify?
thank you for ur time
Evan,
im now clear with the code. now i would like to know whether the following will work?
d= ((curADCResult*3.3)/16384)*1000;
MAP_UART_transmitData(EUSCI_A0_BASE,(uint8_t)d);
what iam trying to do here is that to transmit the actual voltage values in millivolts ,
what value will i obtain if i send this and visualise through docklight??
what should be the actual value that is to be fed to docklight in order to get output in integer??
regards
Gopalakrishnan P
Evan,
i have another doubt. can you make me clear with the reference voltage value that i have used in the program?? what is the highest and lowest range of the ADC according to the code??
thanks and regards
Evan,
I asked the previous question because in an example program they have set the reference voltages to be default voltage (1.2 v) but they had used 3.3 to normalize the ADC value... why was it done??
MAP_ADC14_configureConversionMemory(ADC_MEM0, ADC_VREFPOS_AVCC_VREFNEG_VSS,
ADC_INPUT_A0, false);
curADCResult = MAP_ADC14_getResult(ADC_MEM0);
normalizedADCRes = (curADCResult * 3.3) / 16384;
the above code is a part of example named ADC14_single_conversion_repeat
thanks and regards
Hi Evan,
I tried modifying the code like I am doing certain number of samples and then transmitting them, so that i can avoid the delay that happened in the previous case.this works well... but i have two issues
1) previously i was using UINT8_MAX for the resultsBuffer array in which iam supposed to store the ADC results, by thi sthe array is defined to a size of 256, the code i modified is now sending 200 values at a time, now i thought of increasing the array size and to increase the number of samples sent at an instance by making the array size as resultsBuffer[UINT16_MAX], when i used this it says im out of memory, how to overcome this issue?? the image below is the error
2) in the code i am interrupting the timer once 200 samples have been saved , to send those data stored. i would like to start the timer again to do the same process again ,but the timer stops after one cycle, how do i rectify this?/ i have also attached my code..please help solving these issues.
thanks
/* * customer.c * */ //* DriverLib Includes */ #include "driverlib.h" /* Standard Includes */ #include <stdint.h> #include <stdbool.h> /* variable intialization */ static volatile uint16_t curADCResult,dval,i,j; static volatile uint32_t dec; static volatile float resultsBuffer[UINT16_MAX],d; static volatile uint16_t resPos; char itos[9]={0,}; /* UART configuration with 9600 baud rate and 48MHZ clock*/ /* * 8bytes at 1M baud - 6.7ms, sampling rate is 12Khz, 83us */ const eUSCI_UART_Config uartConfig = { EUSCI_A_UART_CLOCKSOURCE_SMCLK, // SMCLK Clock Source 1, // BRDIV = 78 8, // UCxBRF = 2 0, // UCxBRS = 0 EUSCI_A_UART_NO_PARITY, // No Parity EUSCI_A_UART_LSB_FIRST, // MSB First EUSCI_A_UART_ONE_STOP_BIT, // One stop bit EUSCI_A_UART_MODE, // UART mode EUSCI_A_UART_OVERSAMPLING_BAUDRATE_GENERATION // Oversampling }; int main(void) { /* Halting the Watchdog */ MAP_WDT_A_holdTimer(); /* temporary and count variable*/ curADCResult = 0; resPos = 0; /* * If going to run DCO at 48Mhz then you need to run at * Vcore1 and Flash wait state 1 */ MAP_PCM_setCoreVoltageLevel(PCM_VCORE1); /* * Revision C silicon supports wait states of 1 at 48Mhz * Revision B (black launchpad) requires 2 */ MAP_FlashCtl_setWaitState(FLASH_BANK0, 2); MAP_FlashCtl_setWaitState(FLASH_BANK1, 2); /* Setting DCO to 48MHz */ MAP_CS_setDCOCenteredFrequency(CS_DCO_FREQUENCY_48); /* Setting MCLK to REFO at 48MHz for LF mode */ MAP_CS_initClockSignal(CS_MCLK, CS_DCOCLK_SELECT, CS_CLOCK_DIVIDER_1); /* * USE SMCLK for ADC and not MCLK */ MAP_CS_initClockSignal(CS_SMCLK, CS_DCOCLK_SELECT, CS_CLOCK_DIVIDER_2); /* * LF mode suggest 125Khz */ // MAP_PCM_setPowerState(PCM_AM_LF_VCORE0); /* Enabling the FPU for floating point operation */ MAP_FPU_enableModule(); MAP_FPU_enableLazyStacking(); /* Selecting P1.2 and P1.3 in UART mode */ MAP_GPIO_setAsPeripheralModuleFunctionInputPin(GPIO_PORT_P1, GPIO_PIN1 | GPIO_PIN2 | GPIO_PIN3, GPIO_PRIMARY_MODULE_FUNCTION); /*setting P2.5 as output and initializing to 0*/ MAP_GPIO_setAsOutputPin(GPIO_PORT_P2, GPIO_PIN5); MAP_GPIO_setOutputLowOnPin(GPIO_PORT_P2, GPIO_PIN5); /*setting LED Pin P1.0 as output and initializing to 0*/ MAP_GPIO_setAsOutputPin(GPIO_PORT_P1, GPIO_PIN0); MAP_GPIO_setOutputLowOnPin(GPIO_PORT_P1, GPIO_PIN0); /* Configuring GPIOs (5.5 A0) */ MAP_GPIO_setAsPeripheralModuleFunctionInputPin(GPIO_PORT_P5, GPIO_PIN5, GPIO_TERTIARY_MODULE_FUNCTION); /* * Initializing ADC (MCLK/1/4) */ MAP_ADC14_enableModule(); /* * The MCLK is at 48Mhz which is not valid per the datasheet. */ MAP_ADC14_initModule(ADC_CLOCKSOURCE_SMCLK, ADC_PREDIVIDER_1, ADC_DIVIDER_2, 0); /* Configuring ADC Memory */ MAP_ADC14_configureSingleSampleMode(ADC_MEM0, true); MAP_ADC14_configureConversionMemory(ADC_MEM0, ADC_VREFPOS_AVCC_VREFNEG_VSS, ADC_INPUT_A0, false); /* Configuring Sample Timer */ MAP_ADC14_enableSampleTimer(ADC_MANUAL_ITERATION); /* * default sample time is 4 clock cycles */ /* * enabling ADC Conversion */ MAP_ADC14_enableConversion(); /* Configuring UART Module */ //MAP_UART_initModule(EUSCI_A0_MODULE, &uartConfig); /* * updated driverlib SDK 1_30_00_40 */ MAP_UART_initModule(EUSCI_A0_BASE, &uartConfig); /* Enable UART module */ // MAP_UART_enableModule(EUSCI_A0_MODULE); /* * updated driverlib SDK 1_30_00_40 */ MAP_UART_enableModule(EUSCI_A0_BASE); MAP_Timer32_initModule(TIMER32_BASE, TIMER32_PRESCALER_1, TIMER32_32BIT, TIMER32_PERIODIC_MODE); MAP_Timer32_setCount(TIMER32_BASE,1090); MAP_Timer32_enableInterrupt(TIMER32_BASE); /* Enabling interrupts */ MAP_Interrupt_enableInterrupt(INT_T32_INT1); MAP_Interrupt_enableMaster(); MAP_Timer32_startTimer(TIMER32_BASE, false); /* Sleeping when not in use */ while (1) { MAP_PCM_gotoLPM0(); } } /* Timer32 ISR */ //void timer32_isr(void) void T32_INT1_IRQHandler(void) { MAP_Timer32_clearInterruptFlag(TIMER32_BASE); /* toggling P1.0 and P2.5*/ MAP_GPIO_toggleOutputOnPin(GPIO_PORT_P2, GPIO_PIN5); MAP_GPIO_toggleOutputOnPin(GPIO_PORT_P1, GPIO_PIN0); /* Enabling/Toggling Conversion */ MAP_ADC14_toggleConversionTrigger(); /* * Poll waiting for interrupt to complete */ while(!(MAP_ADC14_getInterruptStatus() & ADC_INT0)); /* * toggling P1.0 and P2.5 * Debug */ // MAP_GPIO_toggleOutputOnPin(GPIO_PORT_P2, GPIO_PIN5); MAP_GPIO_toggleOutputOnPin(GPIO_PORT_P1, GPIO_PIN0); /* transferring ADC result to a variable*/ curADCResult = MAP_ADC14_getResult(ADC_MEM0); resultsBuffer[resPos++] = (curADCResult * 1.2) / 16384; if((resPos%200)==0) { readytotransmit(); } MAP_GPIO_toggleOutputOnPin(GPIO_PORT_P2, GPIO_PIN5); // MAP_GPIO_toggleOutputOnPin(GPIO_PORT_P1, GPIO_PIN0); } void readytotransmit() { uint16_t a,e=0,f,g=1,h; float b; h=g*200; f=e*200; for(a=f;a<h;a++) { b=resultsBuffer[a]; dval=b; dec= (int)(b*100000)%100000; itos[8]='\r'; itos[7]='\n'; for(i=6;i>=2;i--) { itos[i]=(dec%10)+'0'; dec=dec/10; } itos[1]='.'; itos[0]=(dval%10)+'0'; /*transmitting converted values*/ for(j=0;j<8;j++) { MAP_UART_transmitData(EUSCI_A0_MODULE,itos[j]); } } g++; e++; }
Gopalakrishnan
( your answers will be verified ;-) )
Hello Evan,
Sorry for the long break, the previously sent code was just to visualize the data stored in form of a graph using excels sheet , and i somehow managed to do the same and the quality of the wave was could( replication was good). Now I'm trying to process this digital signals to analog signals through a DAC unit. does the MSP432P401R board have an internal DAC unit like ADC if it is there can u help me start with the DAC unit to convert the digital values that is have to frame an analog signal??
thank you,
Gopalakrishnan P
hello Evan,
i tried finding some forums regarding setting up a DAC externally to msp432, i have mentioned the link below also the circuit diagram
these are the things i would like to do,
i must be able to reconstruct the analog signal on which we did ADC before .
that is feed the ADC data to the MSP and to use the DAC setup and regain the signal..
is it possible through the above given ckt and the code mentioned in the link???
kindly provide a solution,
thank you,
Gopalakrishnan P
hello Evan,
I tried with the sample codes, I tried attaching he UART receiving part with the SPI part to communicate with the DAC hardware that is made externally, now before that I will explain what I actually need,
1)previously we had discussed about ADC sampling of the analog signal, that part being done now I have a ADC data in one MSP
2) this data has to be sent to another MSP which has DAC attached to it externally
3) the receiving MSP should send the data received to DAC unit through SPI
this is my objective.
now,
I have attached the code that I have tried, the following are my doubts
1)can I use the same clock source SMCLK for both UART and SPI in the same board
2) we had shifted the ADC value and sent it 8 bit at a time, now if I receive the data as such and send it to DAC will it affect the system?? ( in code customer.c )
3) how do I send the 14 bit ADC values in binary as such from MSP 1 to MSP 2??
//***************************************************************************** // // MSP432 main.c template - Empty main // //**************************************************************************** /* DriverLib Includes */ #include "driverlib.h" /* Standard Includes */ #include <stdint.h> #include <stdbool.h> /* Statics */ static volatile uint8_t RXData = 0; /* SPI Master Configuration Parameter */ const eUSCI_SPI_MasterConfig spiMasterConfig = { EUSCI_B_SPI_CLOCKSOURCE_SMCLK, // SMCLK Clock Source 3000000, // SMCLK = DCO = 3MHZ 500000, // SPICLK = 500khz EUSCI_B_SPI_MSB_FIRST, // MSB First EUSCI_B_SPI_PHASE_DATA_CHANGED_ONFIRST_CAPTURED_ON_NEXT, // Phase EUSCI_B_SPI_CLOCKPOLARITY_INACTIVITY_HIGH, // High polarity EUSCI_B_SPI_3PIN // 3Wire SPI Mode }; const eUSCI_UART_Config uartConfig = { EUSCI_A_UART_CLOCKSOURCE_SMCLK, // SMCLK Clock Source 1, // BRDIV = 78 8, // UCxBRF = 2 0, // UCxBRS = 0 EUSCI_A_UART_NO_PARITY, // No Parity EUSCI_A_UART_LSB_FIRST, // MSB First EUSCI_A_UART_ONE_STOP_BIT, // One stop bit EUSCI_A_UART_MODE, // UART mode EUSCI_A_UART_OVERSAMPLING_BAUDRATE_GENERATION // Oversampling }; int main(void) { /* Halting the Watchdog */ MAP_WDT_A_holdTimer(); /* * If going to run DCO at 48Mhz then you need to run at * Vcore1 and Flash wait state 1 */ MAP_PCM_setCoreVoltageLevel(PCM_VCORE1); /* * Revision C silicon supports wait states of 1 at 48Mhz * Revision B (black launchpad) requires 2 */ MAP_FlashCtl_setWaitState(FLASH_BANK0, 2); MAP_FlashCtl_setWaitState(FLASH_BANK1, 2); /* Setting DCO to 48MHz */ MAP_CS_setDCOCenteredFrequency(CS_DCO_FREQUENCY_48); MAP_CS_initClockSignal(CS_SMCLK, CS_DCOCLK_SELECT, CS_CLOCK_DIVIDER_2); /* Enabling the FPU for floating point operation */ MAP_FPU_enableModule(); MAP_FPU_enableLazyStacking(); /* Selecting P1.2 and P1.3 in UART mode */ MAP_GPIO_setAsPeripheralModuleFunctionInputPin(GPIO_PORT_P1, GPIO_PIN1 | GPIO_PIN2 | GPIO_PIN3, GPIO_PRIMARY_MODULE_FUNCTION); MAP_UART_initModule(EUSCI_A0_BASE, &uartConfig); UART_enableInterrupt(EUSCI_A0_BASE, EUSCI_A_UART_RECEIVE_INTERRUPT); Interrupt_enableInterrupt(INT_EUSCIA0); MAP_UART_enableModule(EUSCI_A0_BASE); /* Selecting P1.5 P1.6 and P1.7 in SPI mode */ GPIO_setAsPeripheralModuleFunctionInputPin(GPIO_PORT_P1, GPIO_PIN5 | GPIO_PIN6 | GPIO_PIN7, GPIO_PRIMARY_MODULE_FUNCTION); SPI_disableInterrupt(EUSCI_B0_BASE, EUSCI_B_SPI_RECEIVE_INTERRUPT); Interrupt_disableInterrupt(INT_EUSCIB0); while (1) { MAP_PCM_gotoLPM0(); } } void UART_receive_IRQ(void) { uint32_t status = MAP_UART_getEnabledInterruptStatus(EUSCI_A0_BASE); MAP_UART_clearInterruptFlag(EUSCI_A0_BASE, status); if(status & EUSCI_A_UART_RECEIVE_INTERRUPT_FLAG) { RXData = MAP_UART_receiveData(EUSCI_A0_BASE); { SPI_transmitData(EUSCI_B0_BASE, RXData); } MAP_Interrupt_disableSleepOnIsrExit(); } }
kindly assist me with your corrections in the above attached code..
thanks and regards,
Gopalakrishnan P
**Attention** This is a public forum