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.

CCS/MSP430FR6989: switch button for 4 values

Part Number: MSP430FR6989


Tool/software: Code Composer Studio

Hello guys , i'm working at a project for my school were to make a data acquisition (voltage) program with 4 channels. Here is my code .... i don't know how to configure to switch betwen the values can somebody can help me please.

#include <msp430.h>
#include <string.h>
#include <stdlib.h>
#include "driverlib.h"
#include "hal_LCD.h"

#define STARTUP_MODE         0

volatile unsigned char mode = STARTUP_MODE;

// rezultate ADC - matrice cu 10 masuratori
int ADC_results [10][4];
// index ADC în matricea ADC_resuts; initializare cu 0

int index_ADC = 0;
volatile unsigned short usiButton1 = 0;


int main(void) {
    int j,k;
    int ind_ADC;
    char disp_ADC [50];
    char sample1_ADC [5];
    char sample2_ADC [5];
    char sample3_ADC [5];
    char sample4_ADC [5];

    WDTCTL = WDTPW | WDTHOLD;   // Stop watchdog timer
    for (j= 0; j<10; j++)
        for (k= 0; j<4; j++)
            ADC_results [j][k] = 0;


     /* Disable the GPIO power-on default high-impedance mode to activate
     * previously configured port settings
     */

    ADC12_B_initParam initParam = {0};
    initParam.sampleHoldSignalSourceSelect = ADC12_B_SAMPLEHOLDSOURCE_SC;
    initParam.clockSourceSelect = ADC12_B_CLOCKSOURCE_ADC12OSC;
    initParam.clockSourceDivider = ADC12_B_CLOCKDIVIDER_1;
    initParam.clockSourcePredivider = ADC12_B_CLOCKPREDIVIDER__1;
    initParam.internalChannelMap = ADC12_B_NOINTCH;
    ADC12_B_init(ADC12_B_BASE, &initParam);


    ADC12_B_setupSamplingTimer(ADC12_B_BASE,
    ADC12_B_CYCLEHOLD_64_CYCLES,
    ADC12_B_CYCLEHOLD_64_CYCLES,
    ADC12_B_MULTIPLESAMPLESENABLE);

    //Enable the ADC12 B module
    ADC12_B_enable(ADC12_B_BASE);

    ADC12_B_enableInterrupt(ADC12_B_BASE, ADC12_B_IE0, 0, 0);
    ADC12_B_enableInterrupt(ADC12_B_BASE, ADC12_B_IE1, 0, 0);
    ADC12_B_enableInterrupt(ADC12_B_BASE, ADC12_B_IE2, 0, 0);
    ADC12_B_enableInterrupt(ADC12_B_BASE, ADC12_B_IE3, 0, 0);

    ADC12_B_configureMemoryParam configureMemoryParam = {0};
    configureMemoryParam.memoryBufferControlIndex = ADC12_B_MEMORY_0;
    configureMemoryParam.inputSourceSelect = ADC12_B_INPUT_A4;
    configureMemoryParam.refVoltageSourceSelect = ADC12_B_VREFPOS_AVCC_VREFNEG_VSS;
    configureMemoryParam.endOfSequence = ADC12_B_NOTENDOFSEQUENCE;
    configureMemoryParam.windowComparatorSelect = ADC12_B_WINDOW_COMPARATOR_DISABLE;
    configureMemoryParam.differentialModeSelect = ADC12_B_DIFFERENTIAL_MODE_DISABLE;
    ADC12_B_configureMemory(ADC12_B_BASE, &configureMemoryParam);

    configureMemoryParam.memoryBufferControlIndex = ADC12_B_MEMORY_1;
    configureMemoryParam.inputSourceSelect = ADC12_B_INPUT_A5;
    configureMemoryParam.refVoltageSourceSelect = ADC12_B_VREFPOS_AVCC_VREFNEG_VSS;
    configureMemoryParam.endOfSequence = ADC12_B_NOTENDOFSEQUENCE;
    configureMemoryParam.windowComparatorSelect = ADC12_B_WINDOW_COMPARATOR_DISABLE;
    configureMemoryParam.differentialModeSelect = ADC12_B_DIFFERENTIAL_MODE_DISABLE;
    ADC12_B_configureMemory(ADC12_B_BASE, &configureMemoryParam);

    configureMemoryParam.memoryBufferControlIndex = ADC12_B_MEMORY_2;
    configureMemoryParam.inputSourceSelect = ADC12_B_INPUT_A6;
    configureMemoryParam.refVoltageSourceSelect = ADC12_B_VREFPOS_AVCC_VREFNEG_VSS;
    configureMemoryParam.endOfSequence = ADC12_B_NOTENDOFSEQUENCE;
    configureMemoryParam.windowComparatorSelect = ADC12_B_WINDOW_COMPARATOR_DISABLE;
    configureMemoryParam.differentialModeSelect = ADC12_B_DIFFERENTIAL_MODE_DISABLE;
    ADC12_B_configureMemory(ADC12_B_BASE, &configureMemoryParam);

    configureMemoryParam.memoryBufferControlIndex = ADC12_B_MEMORY_3;
    configureMemoryParam.inputSourceSelect = ADC12_B_INPUT_A7;
    configureMemoryParam.refVoltageSourceSelect = ADC12_B_VREFPOS_AVCC_VREFNEG_VSS;
    configureMemoryParam.endOfSequence = ADC12_B_NOTENDOFSEQUENCE;
    configureMemoryParam.windowComparatorSelect = ADC12_B_WINDOW_COMPARATOR_DISABLE;
    configureMemoryParam.differentialModeSelect = ADC12_B_DIFFERENTIAL_MODE_DISABLE;
    ADC12_B_configureMemory(ADC12_B_BASE, &configureMemoryParam);

    ADC12_B_startConversion(ADC12_B_BASE,
    ADC12_B_MEMORY_0,
    ADC12_B_REPEATED_SEQOFCHANNELS);


   Init_LCD();
   PMM_unlockLPM5();

    __bic_SR_register(GIE);
    __bis_SR_register(GIE);


    while (1)
    {
        __bic_SR_register(GIE);

        if (index_ADC == 0)
            ind_ADC= 9;
        else
            ind_ADC= index_ADC-1;

       ltoa((long) ADC_results[ind_ADC][0], sample1_ADC);
       ltoa((long) ADC_results[ind_ADC][1], sample2_ADC);
       ltoa((long) ADC_results[ind_ADC][2], sample3_ADC);
       ltoa((long) ADC_results[ind_ADC][3], sample4_ADC);

       strcpy(disp_ADC, "1 ");
                         strcat(disp_ADC, sample1_ADC);
                         displayScrollText(disp_ADC);

      strcpy(disp_ADC, "2");
                         strcat(disp_ADC, sample2_ADC);
                         displayScrollText(disp_ADC);

      strcpy(disp_ADC, "3");
                         strcat(disp_ADC, sample3_ADC);
                         displayScrollText(disp_ADC);

         strcpy(disp_ADC, "4 ");
                         strcat(disp_ADC, sample4_ADC);
                         displayScrollText(disp_ADC);
        __bis_SR_register(GIE);

        __delay_cycles(200000);

    }



}

// asta trebuie lasata asa
// Se poate modificat codul corepunzator
// intreruperilor pt ADC12MEM0 (ADC12_B_MEMORY_0) pana la ADC12MEM3
// cele 4 locatii de mem asociate canalelor ADC 4, 5, 6, 7

#if defined(__TI_COMPILER_VERSION__) || defined(__IAR_SYSTEMS_ICC__)
#pragma vector = ADC12_VECTOR
__interrupt void ADC12_ISR(void)
#elif defined(__GNUC__)
void __attribute__ ((interrupt(ADC12_VECTOR))) ADC12_ISR (void)
#else
#error Compiler not supported!
#endif
{
  switch(__even_in_range(ADC12IV, ADC12IV_ADC12RDYIFG))
  {
    case ADC12IV_NONE:        break;        // Vector  0:  No interrupt
    case ADC12IV_ADC12OVIFG:  break;        // Vector  2:  ADC12MEMx Overflow
    case ADC12IV_ADC12TOVIFG: break;        // Vector  4:  Conversion time overflow
    case ADC12IV_ADC12HIIFG:  break;        // Vector  6:  ADC12BHI
    case ADC12IV_ADC12LOIFG:  break;        // Vector  8:  ADC12BLO
    case ADC12IV_ADC12INIFG:  break;        // Vector 10:  ADC12BIN

    case ADC12IV_ADC12IFG0:                 // Vector 12:  ADC12MEM0 Interrupt
          ADC12_B_clearInterrupt(ADC12_B_BASE, 0, ADC12_B_IFG0);
          index_ADC++;
      if (index_ADC == 10)                   //
          index_ADC=0;
         // index_AD=formula pentru conversie
      ADC_results [index_ADC][0]= ADC12MEM0;
//      __bic_SR_register_on_exit(LPM0_bits);       // Exit active CPU
      break;                                        // Clear CPUOFF bit from 0(SR)
    case ADC12IV_ADC12IFG1:                         // Vector 14:  ADC12MEM1
            ADC12_B_clearInterrupt(ADC12_B_BASE, 0, ADC12_B_IFG1);
        ADC_results [index_ADC][1]= ADC12MEM1;
        break;
    case ADC12IV_ADC12IFG2:                         // Vector 16:  ADC12MEM2
            ADC12_B_clearInterrupt(ADC12_B_BASE, 0, ADC12_B_IFG2);
        ADC_results [index_ADC][2]= ADC12MEM2;
        break;

    case ADC12IV_ADC12IFG3:                         // Vector 18:  ADC12MEM3
           ADC12_B_clearInterrupt(ADC12_B_BASE, 0, ADC12_B_IFG3);
        ADC_results [index_ADC][3]= ADC12MEM3;
        break;


    default: break;
  }
}


  • Hello Gireada,

    I do not see the function to set the respective GPIOs as their ternary module function for ADC applications. You should also be setting A7 as the end of sequence and not enabling interrupts for each ADC12MEMx except the last one. Init_LCD and PMM_unlockLPM5 should also come before starting conversions, and I do not know why you set GIE three times in a row. You must also either poll the ADCIFG or enter a LPM to prevent your while loop from continuing until you have properly sampled the channels, entered the ISR, and stored the values to memory. Please further reference the code example you found or the adc12_a_ex7_sequence.c example from the F5xx/6xx DriverLib package.

    Regards,
    Ryan

**Attention** This is a public forum