Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

hello sir I am using TI c 2 0 0 0 2 8 3 7 9 D board. ' I would like to create the

hello sir
I am using TI c200028379D board.'
I would like to create the content below by combining the two codes in the attachment.
1. I want ePWM1 and ePWM2 to appear when the ADC input comes on.
2. ePWM A and B must appear complementary to each other.
3. If the ADC input is larger than 1.5v (2048), PWM1 duty should increase, and if it is smaller, PWM2 should decrease.
ADC will be input as a function generator.
//###########################################################################
//
// NO.1 code
//
// Continuous D/A and A/D triggered by ePWM
//
// modified from adc_soc_epwm_cpu01.c
//
//###########################################################################
//
// Included Files
//
#include "F28x_Project.h"
//
// Globals
//
volatile struct DAC_REGS* DAC_PTR[4]={0x0,&DacaRegs,&DacbRegs,&DaccRegs};
Uint16 dacval =2048;
//
// Defines
//
#define REFERENCE_VDAC 0
#define REFERENCE_VREF 1
#define DACA 1
#define DACB 2
#define DACC 3
#define REFERENCE REFERENCE_VREF
#define DAC_NUM DACA
// filter coefficients
#define BCOEFF 3.045902795142122e-02
#define ACOEFF -9.390819440971575e-01
//
// Function Prototypes
//
void ConfigureADC(void);
void ConfigureEPWM(void);
void SetupADCEpwm(Uint16 channel);
interrupt void adca1_isr(void);
void configureDAC(Uint16 dac_num);
//
// Defines
//
#define RESULTS_BUFFER_SIZE 256
//
// Globals
//
Uint16 AdcaResults;
Uint16 resultsIndex;
volatile Uint16 bufferFull;
float y;
float u_prev;
void main(void)
{
//
// Step 1. Initialize System Control:
// PLL, WatchDog, enable Peripheral Clocks
// This example function is found in the F2837xD_SysCtrl.c file.
//
InitSysCtrl();
//
// Step 2. Initialize GPIO:
// This example function is found in the F2837xD_Gpio.c file and
// illustrates how to set the GPIO to it's default state.
//
InitGpio(); // Skipped for this example
//
// 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 F2837xD_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 F2837xD_DefaultIsr.c.
// This function is found in F2837xD_PieVect.c.
//
InitPieVectTable();
//
// Map ISR functions
//
EALLOW;
PieVectTable.ADCA1_INT = &adca1_isr; //function for ADCA interrupt 1
EDIS;
//
// Configure the ADC and power it up
//
ConfigureADC();
ConfigureDAC(DAC_NUM);
//
// Configure the ePWM
//
ConfigureEPWM();
//
// Setup the ADC for ePWM triggered conversions on channel 0
//
SetupADCEpwm(14);
//
// Enable global Interrupts and higher priority real-time debug events:
//
IER |= M_INT1; //Enable group 1 interrupts
EINT; // Enable Global interrupt INTM
ERTM; // Enable Global realtime interrupt DBGM
//
// Initialize results buffer
//
// for(resultsIndex =0; resultsIndex < RESULTS_BUFFER_SIZE; resultsIndex++)
//{
// AdcaResults[resultsIndex]=0;
//}
resultsIndex =0;
bufferFull =0;
//
// enable PIE interrupt
//
PieCtrlRegs.PIEIER1.bit.INTx1=1;
//
// sync ePWM
//
EALLOW;
CpuSysRegs.PCLKCR0.bit.TBCLKSYNC =1;
//
//take conversions indefinitely in loop
//
do
{
//
//start ePWM
//
EPwm1Regs.ETSEL.bit.SOCAEN =1; //enable SOCA
EPwm1Regs.TBCTL.bit.CTRMODE =0; //unfreeze, and enter up count mode
} while(1);
}
//
// ConfigureADC - Write ADC configurations and power up the ADC for both
// ADC A and ADC B
//
void ConfigureADC(void)
{
EALLOW;
//
//write configurations
//
AdcaRegs.ADCCTL2.bit.PRESCALE =6; //set ADCCLK divider to /4
AdcSetMode(ADC_ADCA, ADC_RESOLUTION_12BIT, ADC_SIGNALMODE_SINGLE);
//
//Set pulse positions to late
//
AdcaRegs.ADCCTL1.bit.INTPULSEPOS =1

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Intelligent Information And Database Systems Asian Conference Aciids 2012 Kaohsiung Taiwan March 2012 Proceedings Part 2 Lnai 7197

Authors: Jeng-Shyang Pan ,Shyi-Ming Chen ,Ngoc-Thanh Nguyen

2012th Edition

3642284892, 978-3642284892

More Books

Students also viewed these Databases questions