Hai,
I am working on TMS320F28335. I need to generate a pulse when the sampled value through ADC is less than a specified value. Following is the piece of code I am trying to use. Kindly help me in getting the proper output.
#include "DSP2833x_Device.h"
extern void InitAdc(void);
extern void InitSysCtrl(void);
extern void InitPieCtrl(void);
extern void InitPieVectTable(void);
void Gpio_select(void);
#define AVG 100 // Average sample limit
#define BUF_SIZE 100 // Sample buffer size
Uint16 SampleTable1[BUF_SIZE];
float Output1[BUF_SIZE];
void main(void)
{
Uint16 i;
InitSysCtrl(); // Basic Core Init from DSP2833x_SysCtrl.c
DINT; // Disable all interrupts
Gpio_select(); // GPIO9, GPIO11, GPIO34 and GPIO49 as output
// to 4 LEDs at Peripheral Explorer)
InitPieCtrl(); // basic setup of PIE table; from DSP2833x_PieCtrl.c
// Disable CPU interrupts and clear all CPU interrupt flags:
IER = 0x0000;
IFR = 0x0000;
InitPieVectTable(); // default ISR's in PIE
InitAdc(); // Basic ADC setup, incl. calibration
AdcRegs.ADCTRL1.all = 0;
AdcRegs.ADCTRL1.bit.ACQ_PS = 7; // 7 = 8 x ADCCLK
AdcRegs.ADCTRL1.bit.SEQ_CASC =1; // 1=cascaded sequencer
AdcRegs.ADCTRL1.bit.CPS = 1; // divide by 2
AdcRegs.ADCTRL1.bit.CONT_RUN = 1; // Continous run mode
AdcRegs.ADCTRL2.all = 0;
AdcRegs.ADCTRL2.bit.SOC_SEQ1 = 1; // 1=Software trigger
AdcRegs.ADCTRL2.bit.EPWM_SOCA_SEQ1 =0; // 0=SEQ1 cannot be started by ePWMx SOCA trigger.
AdcRegs.ADCTRL2.bit.INT_MOD_SEQ1 = 0; // 0= interrupt after every end of sequence
AdcRegs.ADCTRL3.bit.ADCCLKPS = 3; // ADC clock: FCLK = HSPCLK / 2 * ADCCLKPS
AdcRegs.ADCMAXCONV.all = 0x0000;
AdcRegs.ADCCHSELSEQ1.bit.CONV00 = 0;
for (i=0; i<AVG; i++)
{
while (AdcRegs.ADCST.bit.INT_SEQ1== 0) {} // Wait for interrupt
AdcRegs.ADCST.bit.INT_SEQ1_CLR = 1;
SampleTable1[i] =((AdcRegs.ADCRESULT0>>4) );
if(SampleTable1[i]<685)
{
GpioDataRegs.GPASET.bit.GPIO12 = 1;
}
else
{
GpioDataRegs.GPASET.bit.GPIO12 = 0;
}
}
}
void Gpio_select(void)
{
EALLOW;
GpioCtrlRegs.GPAMUX1.all = 0; // GPIO15 ... GPIO0 = General Puropse I/O
GpioCtrlRegs.GPAMUX2.all = 0; // GPIO31 ... GPIO16 = General Purpose I/O
GpioCtrlRegs.GPBMUX1.all = 0; // GPIO47 ... GPIO32 = General Purpose I/O
GpioCtrlRegs.GPBMUX2.all = 0; // GPIO63 ... GPIO48 = General Purpose I/O
GpioCtrlRegs.GPCMUX1.all = 0; // GPIO79 ... GPIO64 = General Purpose I/O
GpioCtrlRegs.GPCMUX2.all = 0; // GPIO87 ... GPIO80 = General Purpose I/O
GpioCtrlRegs.GPADIR.all = 0;
GpioCtrlRegs.GPBDIR.all = 0; // GPIO63-32 as inputs
GpioCtrlRegs.GPCDIR.all = 0;
GpioCtrlRegs.GPAMUX1.bit.GPIO12= 0;
GpioCtrlRegs.GPADIR.bit.GPIO12 = 1;
EDIS;
}