Hi all,
I am using F28M36x. I am try to run the control suite project(ePWM_adc_soc). I am running this in my DSP core i am getting some values from ADCRESULT register. I dont know, where is that value coming from. And i am trying to monitor SOCA,SOCB in the GPIO0, GPIO1 pin( Now i am using ePWM1 ). I dont get any clock pulse. How to create a clock pulse from my ePWM1. I need to monitor that ePWM output(clock).
My code is:
//###########################################################################
// FILE: adc_soc_c28.c
// TITLE: ADC1 Start-Of-Conversion (SOC) Example Program.
//
//! \addtogroup control_example_list
//! <h1> ADC1 Start of Conversion (adc_soc)</h1>
//!
//! This ADC example uses ePWM1 to generate two periodic and
//! simultaneous SOCs to the ADC. Two channels are converted,
//! ADC1A0 and ADC1A2, triggered by EPWM1SOCA and EPWM1SOCB
//! respectively.
//!
//! Note that because ADC SOC0 has a higher priority by default
//! than SOC1, channel 0 conversion will take precedence over
//! channel 1 conversion.
//!
//! - EPWM1SOCA triggers SOC0
//! - EPMM1SOCB triggers SOC1
//! - EOC1 triggers ADCINT1 after ADC result register is latched
//!
//! New EPWM compare registers CMPC and CMPD are used to control
//! SOCA and SOCB
//!
//! \b Watch \b Variables \n
//! - Voltage1[10] - Last 10 ADCRESULT0 values
//! - Voltage2[10] - Last 10 ADCRESULT1 values
//! - ConversionCount - Current result number 0-9
//! - LoopCount - Idle loop counter
//
//###########################################################################
// $TI Release: F28M36x Support Library v110 $
// $Release Date: Tue Nov 6 08:49:15 CST 2012 $
//###########################################################################
#include "DSP28x_Project.h" // Device Headerfile and Examples Include File
#include <string.h>
#define DUTY_CYCLE 500
#define PERIOD 1000
// Prototype statements for functions found within this file.
interrupt void adc1_isr( void );
void ConfigAdc1( void );
void ConfigEpwm1( void );
// Global variables used in this example:
Uint16 LoopCount;
Uint16 ConversionCount;
Uint16 Voltage1[10];
Uint16 Voltage2[10];
main()
{
unsigned short analoginit;
// Step 1. Initialize System Control for Control and Analog Subsytems
// Enable Peripheral Clocks
// This example function is found in the F28M36x_SysCtrl.c file.
InitSysCtrl();
// If project is linked into flash, copy critical code sections to RAM.
#ifdef _FLASH
memcpy(&RamfuncsRunStart, &RamfuncsLoadStart, (size_t)&RamfuncsLoadSize);
#endif
EDIS;
// Step 2. Initialize GPIO:
// This example function is found in the F28M36x_Gpio.c file and
// illustrates how to set the GPIO to it's default state.
// InitGpio(); // Skipped for this example
EALLOW;
GpioG1CtrlRegs.GPADIR.bit.GPIO0 = 1; // Set as output
GpioG1CtrlRegs.GPAMUX1.bit.GPIO0 = 1; // Select EPWM1SOCA as driving source
GpioG1CtrlRegs.GPADIR.bit.GPIO1 = 1; // Set as output
GpioG1CtrlRegs.GPAMUX1.bit.GPIO1 = 1; // Select EPWM1SOCB as driving source
EDIS;
// Step 3. Clear all interrupts and initialize PIE vector table:
// Disable CPU interrupts
DINT;
// Initialize the PIE control registers to their default state.
// The default state is all PIE interrupts disabled and flags
// are cleared.
// This function is found in the F28M36x_PieCtrl.c file.
InitPieCtrl();
// Disable CPU interrupts and clear all CPU interrupt flags:
IER = 0x0000;
IFR = 0x0000;
// Initialize the PIE vector table with pointers to the shell Interrupt
// Service Routines (ISR).
// This will populate the entire table, even if the interrupt
// is not used in this example. This is useful for debug purposes.
// The shell ISR routines are found in F28M36x_DefaultIsr.c.
// This function is found in F28M36x_PieVect.c.
InitPieVectTable();
// Interrupts that are used in this example are re-mapped to
// ISR functions found within this file.
EALLOW; // This is needed to write to EALLOW protected register
PieVectTable.ADCINT1 = &adc1_isr;
EDIS; // This is needed to disable write to EALLOW protected registers
// Step 4. Initialize all the Device Peripherals:
// This function is found in F28M36x_InitPeripherals.c
// InitPeripherals(); // Not required for this example
InitAdc1(); // For this example, init the ADC
// Step 5. User specific code, enable interrupts:
// Enable ADCINT1 in PIE
PieCtrlRegs.PIEIER1.bit.INTx1 = 1; // Enable INT 1.1 in the PIE
IER |= M_INT1; // Enable CPU Interrupt 1
EINT; // Enable Global interrupt INTM
ERTM; // Enable Global realtime interrupt DBGM
// Configure ADC and EPWM1 sub-modules
ConfigAdc1();
ConfigEpwm1();
LoopCount = 0;
ConversionCount = 0;
// Wait for ADC interrupt
for(;;)
{
LoopCount++;
}
}
interrupt void adc1_isr( void )
{
Voltage1[ConversionCount] = Adc1Result.ADCRESULT0;
Voltage2[ConversionCount] = Adc1Result.ADCRESULT1;
// If 20 conversions have been logged, start over
if(ConversionCount == 9)
{
ConversionCount = 0;
}
else ConversionCount++;
Adc1Regs.ADCINTFLGCLR.bit.ADCINT1 = 1; //Clear ADCINT1 flag reinitialize
// for next SOC
PieCtrlRegs.PIEACK.all = PIEACK_GROUP1; // Acknowledge interrupt to PIE
return;
}
void ConfigEpwm1( void )
{
// Assumes ePWM1 clock is already enabled in InitSysCtrl();
EALLOW;
// Enable SOCA and SOCB
EPwm1Regs.ETSEL.bit.SOCAEN = 1; // Enable SOC on A group
EPwm1Regs.ETSEL.bit.SOCBEN = 1; // Enable SOC on B group
EPwm1Regs.ETSEL.bit.SOCASEL = 0x4; // Select SOC from CMPA/CMPC on up count
EPwm1Regs.ETSEL.bit.SOCBSEL = 0x6; // Select SOC from CMPB/CMPD on up count
EPwm1Regs.ETSEL.bit.SOCASELCMP = 0x1; // CMPC
EPwm1Regs.ETSEL.bit.SOCBSELCMP = 0x1; // CMPD
EPwm1Regs.ETPS.bit.SOCAPRD = 3; // Generate SOCA pulse on every 3rd event
EPwm1Regs.ETPS.bit.SOCBPRD = 3; // Generate SOCA pulse on every 3rd event
// Time-base registers
EPwm1Regs.TBPRD = PERIOD; // Set EPWM timer period
EPwm1Regs.TBPHS.all = 0; // Time-Base Phase Register
EPwm1Regs.TBCTR = 0; // Time-Base Counter Register
EPwm1Regs.TBCTL.bit.PRDLD = TB_IMMEDIATE; // Set Immediate load
EPwm1Regs.TBCTL.bit.CTRMODE = TB_COUNT_UP; // Count-up mode: used for asymmetric PWM
EPwm1Regs.TBCTL.bit.PHSEN = TB_DISABLE; // Disable phase loading
EPwm1Regs.TBCTL.bit.SYNCOSEL = TB_SYNC_DISABLE;
// Set TBCLK frequency
EPwm1Regs.TBCTL.bit.HSPCLKDIV = TB_DIV1; // TBCLK = SYSCLKOUT
EPwm1Regs.TBCTL.bit.CLKDIV = TB_DIV1;
// Setup shadow register load on ZERO
EPwm1Regs.CMPCTL.bit.SHDWAMODE = CC_SHADOW;
EPwm1Regs.CMPCTL.bit.SHDWBMODE = CC_SHADOW;
EPwm1Regs.CMPCTL.bit.LOADAMODE = CC_CTR_ZERO; // load on CTR=Zero
EPwm1Regs.CMPCTL.bit.LOADBMODE = CC_CTR_ZERO; // load on CTR=Zero
// Set Compare values
EPwm1Regs.CMPC = DUTY_CYCLE;
EPwm1Regs.CMPD = DUTY_CYCLE;
EDIS;
}
void ConfigAdc1( void )
{
// Configure ADC
EALLOW;
Adc1Regs.ADCCTL2.bit.ADCNONOVERLAP = 1; // Set ADC to non-overlap mode
Adc1Regs.ADCCTL1.bit.INTPULSEPOS = 1; // EOC trips after conversion result is latched
Adc1Regs.INTSEL1N2.bit.INT1E = 1; // Enabled ADCINT1
Adc1Regs.INTSEL1N2.bit.INT1CONT = 0; // Disable ADCINT1 Continuous mode
Adc1Regs.INTSEL1N2.bit.INT1SEL = 1; // setup EOC1 to trigger ADCINT1
// Select ADC input channels
Adc1Regs.ADCSOC0CTL.bit.CHSEL = 0; // set SOC0 channel select to ADC1A0
Adc1Regs.ADCSOC1CTL.bit.CHSEL = 2; // set SOC1 channel select to ADC1A2
// Selecting triggers for SOCs
AnalogSysctrlRegs.TRIG5SEL.all = 5; // Assigning EPWM1SOCA to TRIGGER 5 of analog subsystem
AnalogSysctrlRegs.TRIG6SEL.all = 6; // Assigning EPWM1SOCB to TRIGGER 6 of analog subsystem
Adc1Regs.ADCSOC0CTL.bit.TRIGSEL = 9; // Assign EPWM1SOCA to SOC0 TRIGSEL
Adc1Regs.ADCSOC1CTL.bit.TRIGSEL = 10; // Assign EPWM1SOCB to SOC1 TRIGSEL
// Set S/H window of 7 ADC clock cycles
Adc1Regs.ADCSOC0CTL.bit.ACQPS = 6; // S/H = ACQPS + 1
Adc1Regs.ADCSOC1CTL.bit.ACQPS = 6;
EDIS;
}
Thanks in advance!!!
Thirumoorthy.R