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.

TMS320F28379D: Switching on and off the LED with a specific potentiometer voltage with TMS320F28379D

Part Number: TMS320F28379D


Switching on and off the LED with a specific potentiometer voltage with TMS320F28379D.

How will I read the voltage value and write the condition to turn on and turn off the led. Can you help me?

//ADC



#include <stdio.h>

#include <string.h>

#include <stdlib.h>



#include "F2837xD_device.h"

#include "F28x_Project.h"

#include "F2837xD_Examples.h"



#include "driverlib.h"

#include "device.h"



#define  ADC_RESOLUTION       12   





uint16_t adcAResult2;



void initADCs(void);

void initADCSOCs(void);

void GPIO_init();

void PinMux_init();

void initEPWM();



//

// Main

//

void main(void)

{

    adcAResult2= 0;



    Device_init();



    Device_initGPIO();

    PinMux_init();



    Interrupt_initModule();



    Interrupt_initVectorTable();



    initADCs();

    initADCSOCs();



    EINT;

    ERTM;





    IER = 0x0000;  //interrupt enable register

    IFR = 0x0000;  //interrupt flag register





          SysCtl_disablePeripheral(SYSCTL_PERIPH_CLK_TBCLKSYNC);

          SysCtl_enablePeripheral(SYSCTL_PERIPH_CLK_TBCLKSYNC);





       while(1)

       {

      

           ADC_forceSOC(ADCA_BASE, ADC_SOC_NUMBER0);

           while(ADC_getInterruptStatus(ADCA_BASE, ADC_INT_NUMBER1) == false) 

           {



           }



           ADC_clearInterruptStatus(ADCA_BASE, ADC_INT_NUMBER1);





           adcAResult2 = ADC_readResult(ADCARESULT_BASE, ADC_SOC_NUMBER0);



           initEPWM();

                   DEVICE_DELAY_US(10000);



       }

   }



void initEPWM()

{



        EPwm1Regs.TBPRD = 4000;       // Set timer period 801 TBCLKs

        EPwm1Regs.TBPHS.bit.TBPHS = 0x0000;        // Phase is 0

        EPwm1Regs.TBCTR = 0x0000;

        EPwm1Regs.CMPA.bit.CMPA =  adcAResult2;   

       EPwm1Regs.TBCTL.bit.CTRMODE = TB_COUNT_UPDOWN; 

       EPwm1Regs.TBCTL.bit.PHSEN = TB_DISABLE;        

       EPwm1Regs.TBCTL.bit.HSPCLKDIV = TB_DIV1;       

       EPwm1Regs.TBCTL.bit.CLKDIV = TB_DIV1;



       EPwm1Regs.AQCTLA.bit.CAU = AQ_SET;           

       EPwm1Regs.AQCTLA.bit.CAD = AQ_CLEAR;         

}



void PinMux_init()

{

    EALLOW;



    GpioCtrlRegs.GPAMUX1.all=0;

    GpioCtrlRegs.GPAMUX1.bit.GPIO0=1;



    EDIS;



}





void initADCs(void)

{

    EALLOW;



    ADC_setPrescaler(ADCA_BASE, ADC_CLK_DIV_4_0); 

#if(ADC_RESOLUTION == 12) 

    ADC_setMode(ADCA_BASE, ADC_RESOLUTION_12BIT, ADC_MODE_SINGLE_ENDED);

#elif(ADC_RESOLUTION == 16)

    ADC_setMode(ADCA_BASE, ADC_RESOLUTION_16BIT, ADC_MODE_DIFFERENTIAL);

#endif



    ADC_setInterruptPulseMode(ADCA_BASE, ADC_PULSE_END_OF_CONV); 

    ADC_enableConverter(ADCA_BASE); 



    DEVICE_DELAY_US(1000);



    EDIS;



}





void initADCSOCs(void)

{



#if(ADC_RESOLUTION == 12)

    ADC_setupSOC(ADCA_BASE, ADC_SOC_NUMBER0, ADC_TRIGGER_SW_ONLY,

                 ADC_CH_ADCIN0, 15);

#elif(ADC_RESOLUTION == 16)

    ADC_setupSOC(ADCA_BASE, ADC_SOC_NUMBER0, ADC_TRIGGER_SW_ONLY,

                 ADC_CH_ADCIN0, 64);

#endif





    ADC_setInterruptSource(ADCA_BASE, ADC_INT_NUMBER1, ADC_SOC_NUMBER0);  

    ADC_enableInterrupt(ADCA_BASE, ADC_INT_NUMBER1);

    ADC_clearInterruptStatus(ADCA_BASE, ADC_INT_NUMBER1);





}

  • Hello Sule,

    For future posts, please do not copy and paste your code as normal text, please use the code block to let other users have an easier time understanding your issue.

    How will I read the voltage value and write the condition to turn on and turn off the led. Can you help me?

    Can you clarify what your question is? Are you unable to read an input on the ADC?

    Best regards,

    Omer Amir