2893 views|7 replies

4

Posts

0

Resources
The OP
 

Why can’t 28335 output 4 PWM channels at the same time? [Copy link]

#include"DSP28x_Project.h"

#define CPU_CLK 150e6 //System clock 150MHz
#define TBCTLVAL 0x200E //Control register value

Uint32 PWM_CLK,PWM_CLK1,PWM_CLK2;
float SP,SP1,SP2;

void main(void)
{

InitSysCtrl(); //Initialize system
InitGpio(); //Initialize GPIIO
InitPieCtrl(); //Clear all interrupts
IER = 0x0000;
IFR = 0x0000;
InitPieVectTable(); //Initialize interrupt vector table


PWM_CLK1 = 1000;
SP1 = CPU_CLK/(2*PWM_CLK1);
InitEPwm1Gpio();
EPwm1Regs.TBSTS.all = 0; //Clear the time base status register
EPwm1Regs.TBPHS.half.TBPHS = 0; //Phase register Set to 0
EPwm1Regs.TBCTR = 0; //Clear the time base counter
EPwm1Regs.CMPCTL.all = 0x50; //CMPA and CMPB are configured in immediate mode
EPwm1Regs.CMPA.half.CMPA = SP1/2; //Set the duty cycle The ratio is 0.5, SP is the value of the period register
EPwm1Regs.CMPB = 0;
EPwm1Regs.AQCTLA.all = 0x60; //When the value of the time base counter is equal to the value of CMPA and is counting up, EPWMxA outputs high level; when the time The value of the reference counter is equal to the value of CMPA and is counting down. EPWMxA outputs low level
EPwm1Regs.AQCTLB.all = 0;
EPwm1Regs.AQSFRC.all = 0;
EPwm1Regs.AQCSFRC.all = 0;
EPwm1Regs.DBCTL.all = 0xb ; //EPwm1B is associated with EPwm1A, that is, EPwm1B changes with the change of EPwm1A
EPwm1Regs.DBRED = 0; //The dead time of the rising edge is set to 0
EPwm1Regs.DBFED = 0; //The dead time of the falling edge is set Is 0
EPwm1Regs.TZSEL.all = 0; //The joint defense zone module is not used, all are invalid
EPwm1Regs.TZCTL.all = 0;
EPwm1Regs.TZEINT.all = 0;
EPwm1Regs.TZFLG.all = 0;
EPwm1Regs.TZCLR.all = 0;
EPwm1Regs.TZFRC.all = 0;
EPwm1Regs.ETSEL.all
= 0
;
EPwm1Regs.ETFLG.all
= 0; ;
EPwm1Regs.TBCTL.all = 0x0010 + TBCTLVAL; //Increase and decrease mode
EPwm1Regs.TBPRD = SP1;

PWM_CLK2 = 2000;
SP2 = CPU_CLK/(2*PWM_CLK2);
InitEPwm2Gpio();
EPwm2Regs.TBSTS.all = 0; //Clear the time base status register
EPwm2Regs.TBPHS.half.TBPHS = 0; //Phase register Set to 0
EPwm2Regs.TBCTR = 0; //Clear the time base counter
EPwm2Regs.CMPCTL.all = 0x50; //CMPA and CMPB are configured in immediate mode
EPwm2Regs.CMPA.half.CMPA = SP2/2; //Set the duty cycle The ratio is 0.5, SP is the value of the period register
EPwm2Regs.CMPB = 0;
EPwm2Regs.AQCTLA.all = 0x60; //When the value of the time base counter is equal to the value of CMPA and is counting up, EPWMxA outputs high level; when the time The value of the reference counter is equal to the value of CMPA and is counting down. EPWMxA outputs low level
EPwm2Regs.AQCTLB.all = 0;
EPwm2Regs.AQSFRC.all = 0;
EPwm2Regs.AQCSFRC.all = 0;
EPwm2Regs.DBCTL.all = 0xb ; //EPwm1B is associated with EPwm1A, that is, EPwm1B changes with the change of EPwm1A
EPwm2Regs.DBRED = 0; //The dead time of the rising edge is set to 0
EPwm2Regs.DBFED = 0; //The dead time of the falling edge is set Is 0
EPwm2Regs.TZSEL.all = 0; //The joint defense zone module is not used, all are invalid
EPwm2Regs.TZCTL.all = 0;
EPwm2Regs.TZEINT.all = 0;
EPwm2Regs.TZFLG.all = 0;
EPwm2Regs.TZCLR.all = 0;
EPwm2Regs.TZFRC.all = 0; EPwm2Regs.ETSEL.all = 0
; EPwm2Regs.ETFLG.all = 0; ; EPwm2Regs.TBCTL.all = 0x0010 + TBCTLVAL; //Increase and decrease mode EPwm2Regs.TBPRD = SP2;





for(; ;)
{

}
}


//Looking at the oscilloscope, it only outputs a 2000Hz waveform. Why is there no 1000Hz waveform? ? Where did I make a mistake? Please tell me, I'm a noob.

This post is from Microcontroller MCU

Latest reply

Check it out slowly, and you have to combine it with the basic units in the kernel.   Details Published on 2019-7-31 08:15
 

3191

Posts

0

Resources
2
 

Check the program carefully and you will definitely be able to do it.

This post is from Microcontroller MCU
 
Personal signature为江山踏坏了乌骓马,为社稷拉断了宝雕弓。
 

4

Posts

0

Resources
3
 
chenbingjy published on 2019-7-30 15:12 Check the program carefully, you can definitely do it

The configuration of each pwm wave is the same, only the frequency and period values are changed. A single PWM compilation can be successful. .

This post is from Microcontroller MCU

Comments

I don't understand what you mean by "single PWM compilation can succeed"? Can each one generate a waveform?  Details Published on 2019-7-30 15:36
 
 
 

3191

Posts

0

Resources
4
 
This post was last edited by chenbingjy on 2019-7-30 15:39
How will I become Published on 2019-7-30 15:22 The configuration of each pwm wave is the same, but the frequency and period values are changed. A single PWM compilation can be successful. .

I don't understand what you mean by "single PWM compilation can be successful"?

Can each one produce a waveform?

I'm sure the pins are all different.

This post is from Microcontroller MCU
 
Personal signature为江山踏坏了乌骓马,为社稷拉断了宝雕弓。
 
 

4

Posts

0

Resources
5
 
chenbingjy published on 2019-7-30 15:36 What will I become? Published on 2019-7-30 15:22 The configuration of each pwm wave is the same, except that the frequency and period values are changed. A single PWM compilation...

Of the 4 pins, only two have complementary waveforms. PWM1 and PWM2 are compiled separately, and the corresponding two GPIO ports have waveforms. When the programs are compiled together (as shown in the picture above), the two GPIO ports corresponding to PWM2 have waveforms, but PWM1 does not.

This post is from Microcontroller MCU
 
 
 

3191

Posts

0

Resources
6
 

InitEPwm2Gpio();

It feels weird. Could it be that your InitEPwm2Gpio(); overwrote InitEPwm1Gpio();?

Post the code.

This post is from Microcontroller MCU
 
Personal signature为江山踏坏了乌骓马,为社稷拉断了宝雕弓。
 
 

4

Posts

0

Resources
7
 
chenbingjy published on 2019-7-30 15:51 InitEPwm2Gpio(); It feels very strange. Could it be that you gave InitEPwm2Gpio(); to InitEPwm1Gpio();...

void
InitEPwm1Gpio(void)
{
EALLOW;

//
// Enable internal pull-up for the selected pins
// Pull-ups can be enabled or disabled by the user.
// This will enable the pullups for the specified pins.
// Comment out other unwanted lines.
//
GpioCtrlRegs .GPAPUD.bit.GPIO0 = 0; // Enable pull-up on GPIO0 (EPWM1A)
GpioCtrlRegs.GPAPUD.bit.GPIO1 = 0; // Enable pull-up on GPIO1 (EPWM1B)

//
// Configure ePWM-1 pins using GPIO regs
// This specifies which of the possible GPIO pins will be ePWM1 functional
// pins. Comment out other unwanted lines.
//
GpioCtrlRegs.GPAMUX1.bit.GPIO0 = 1; // Configure GPIO0 as EPWM1A
GpioCtrlRegs.GPAMUX1.bit.GPIO1 = 1; // Configure GPIO1 as EPWM1B

EDIS;
}

void
InitEPwm2Gpio(void)
{
EALLOW;

//
// Enable internal pull-up for the selected pins
// Pull-ups can be enabled or disabled by the user.
// This will enable the pullups for the specified pins.
// Comment out other unwanted lines.
//
GpioCtrlRegs .GPAPUD.bit.GPIO2 = 0; // Enable pull-up on GPIO2 (EPWM2A)
GpioCtrlRegs.GPAPUD.bit.GPIO3 = 0; // Enable pull-up on GPIO3 (EPWM3B)

//
// Configure ePWM-2 pins using GPIO regs
// This specifies which of the possible GPIO pins will be ePWM2 functional
// pins. Comment out other unwanted lines.
//
GpioCtrlRegs.GPAMUX1.bit.GPIO2 = 1; // Configure GPIO2 as EPWM2A
GpioCtrlRegs.GPAMUX1.bit.GPIO3 = 1; // Configure GPIO3 as EPWM2B

EDIS;
}

//The configuration in the file has not been changed.

This post is from Microcontroller MCU
 
 
 

2618

Posts

0

Resources
8
 

Check it out slowly, and you have to combine it with the basic units in the kernel.

This post is from Microcontroller MCU
 
 
 

Guess Your Favourite
Just looking around
Find a datasheet?

EEWorld Datasheet Technical Support

EEWorld
subscription
account

EEWorld
service
account

Automotive
development
circle

Copyright © 2005-2024 EEWORLD.com.cn, Inc. All rights reserved 京B2-20211791 京ICP备10001474号-1 电信业务审批[2006]字第258号函 京公网安备 11010802033920号
快速回复 返回顶部 Return list