Other Parts Discussed in Thread: TMS320F28335
I am working with tms320f28335. Currently I am working on programing for generating PWM using sine triangular technique. so for that i need to initialize GPIO pin. here i am attaching my code can u please tell me the problem with initilization?????????
#include "DSP28335_Regs.h"
#include "DSP28335_RegDef.h"
#include "adc.h"
#include "Pwms.h"
#include "gpio.h"
void main(void)
{
DemoADC.stop = 0;
DemoADC.ret_val_mon = 1;
DemoADC.count_saved = 0;
DemoADC.count_adc = 0;
DemoADC.timer_period = 0xFFF0;
DemoADC.n_samples = 1000;
DemoADC.ch_sel1 = 0x0021;
DemoADC.ch_sel2 = 0;
DemoADC.ch_sel3 = 0;
DemoADC.ch_sel4 = 0;
DemoADC.max_ch = 1;
EALLOW; // Enable writing to EALLOW protected registers
SysCtrlRegs.HISPCP.bit.HSPCLK = 0; // HSPCLK = SYSCLKOUT / 1 = 150MHz
SysCtrlRegs.PCLKCR0.bit.TBCLKSYNC = 1; // Start all the timers synced
EDIS; // Disable writing to EALLOW protected areas
EALLOW; // Enable writing to EALLOW protected registers
SysCtrlRegs.PCLKCR1.bit.EPWM1ENCLK=1; // Enable ePWM1 clock
SysCtrlRegs.PCLKCR0.bit.ADCENCLK=1; // Enable ADC clock
EDIS;
EALLOW;
GpioCtrlRegs.GPAMUX1.bit.GPIO0=1;
EDIS;
// Allow synchronization
EPwm1Regs.TBCTL.bit.SYNCOSEL = 0; // Pass through
EPwm1Regs.TBCTL.bit.PHSEN = 0; // Phase loading disabled
EPwm1Regs.TBCTL.bit.CLKDIV = 0; // Clock ratio to SYSCLKOUT
EPwm1Regs.TBCTL.bit.HSPCLKDIV = 0; //
EPwm1Regs.TBPHS.half.TBPHS = 0; // Set Phase register to zero
EPwm1Regs.TBPRD = DemoADC.timer_period; // Set timer period
EPwm1Regs.TBCTL.bit.CTRMODE = TB_COUNT_UPDOWN; // Count up-down
EALLOW; // Enable writing to the EALLOW protected areas
PieVectTable.ADCINT = &adc_isr; // Set the interrupt vector for ADC interrupt
EDIS; // Disable writing to the EALLOW protected areas
EALLOW; // Enable writing to the EALLOW protected areas
AdcRegs.ADCTRL3.all = 0x00E0; // Power up bandgap/reference/ADC circuits
DELAY_US(5000); // Delay before converting ADC channels
EDIS; // Disable writing to the EALLOW protected areas
AdcRegs.ADCTRL1.bit.SEQ_CASC=1;
AdcRegs.ADCTRL1.bit.ACQ_PS = 0xF; // S/H width in ADC module periods = 16 ADC clocks
AdcRegs.ADCTRL3.bit.ADCCLKPS = 3; // ADC module clock = HSPCLK/(1*8) = 150MHz/(1*8) = 18.75MHz
// Set Maximum Conversion Channels Register:
AdcRegs.ADCMAXCONV.all = DemoADC.max_ch; // Setup the number of conv's on SEQ1
// Initialize ADC Input Channel Select Sequencing Control Register:
AdcRegs.ADCCHSELSEQ1.all = DemoADC.ch_sel1; // Setup the 1st to 4th SEQ1 conv.
AdcRegs.ADCTRL2.bit.EPWM_SOCA_SEQ1 = 1; // Enable SOCA from ePWM to start SEQ1
AdcRegs.ADCTRL2.bit.INT_ENA_SEQ1 = 1; // Enable SEQ1 interrupt (every EOS)
// Start ADC with timer 1 event:
EPwm1Regs.ETSEL.bit.SOCAEN = 1; // Enable SOC on A group
EPwm1Regs.ETSEL.bit.SOCASEL = 1; // Generate SOC when time-base counter equal to zero.
EPwm1Regs.ETPS.bit.SOCAPRD = 1; // Generate pulse on 1st event
// start PWM generation
EALLOW; // Enable writing to EALLOW protected registers
SysCtrlRegs.PCLKCR0.bit.TBCLKSYNC = 1; // Start all the timers synced
EDIS; // Disable writing to EALLOW protected areas
DELAY_US(500); // Delay before converting ADC channels
// Enable ADCINT in PIE
PieCtrlRegs.PIEIER1.bit.INTx6 = 1;
PieCtrlRegs.PIEIER1.bit.INTx1 = 1;
IER |= M_INT1; // Enable CPU Interrupt 1
EINT; // Enable Global interrupt INTM
ERTM; // Enable Global realtime interrupt DBGM
// Generate system reset
DINT;
EALLOW; // Enable writing to EALLOW protected registers
SysCtrlRegs.WDCR = 0x000F; // Enable Watchdog and write incorrect WD Check Bits
// (001 in lieu of 101) to force a system reset
asm(" NOP");
asm(" NOP");
asm(" NOP");
}
int count_adc;
int n_samples;
/*unsigned int ad0;
unsigned int ad1;*/
//===========================================
// ADC interrupt service routine
//===========================================
interrupt void adc_isr(void)
{
long int a=AdcRegs.ADCRESULT0;
long int b=AdcRegs.ADCRESULT1;
EALLOW;
GpioCtrlRegs.GPADIR.bit.GPIO0=1;
EDIS;
if(a>b)
GpioDataRegs.GPASET.bit.GPIO0=1;
else
GpioDataRegs.GPACLEAR.bit.GPIO0=1;
// Reinitialize for next ADC sequence
AdcRegs.ADCTRL2.bit.RST_SEQ1 =1 ; // Reset SEQ1
AdcRegs.ADCST.bit.INT_SEQ1_CLR =1 ; // Clear INT SEQ1 bit
PieCtrlRegs.PIEACK.all = PIEACK_GROUP1; // Acknowledge interrupt to PIE
}
void Delay(unsigned long LoopCnt)
{
unsigned long i;
for (i = 0; i < LoopCnt; i++){}
}