cancel
Showing results for 
Search instead for 
Did you mean: 

FlexPWM SPC56EL Driver

Patriks
Senior
Posted on January 16, 2015 at 10:09

Hello,

I have some problems using the PWM sample project together with the SPC56xL Discovery board. The project generates different PWM signals on the PWMA pin of submodule0. I was able to adapt the PWM configuration to generate the same signal on PWMB pin of submodule0. But now, I also wanted to generate PWM signals with submodule1 of FLEXPWM1. Therfore, I configured thetwo additional controller pinsusing thepin wizard and adapted the sample code like this:

pwmStart(&PWMD1, &pwm_config_pwmcfg); 
pwmStart(&PWMD2, &pwm_config_pwmcfg); 
osalThreadSleepMilliseconds(2000); 
/* 
* Starts the PWM channel 0 using 75% duty cycle. 
*/ 
pwmEnableChannel(&PWMD1, 0, PWM_PERCENTAGE_TO_WIDTH(&PWMD1, 7500)); 
pwmEnableChannel(&PWMD1, 1, PWM_PERCENTAGE_TO_WIDTH(&PWMD1, 7500)); 
pwmEnableChannel(&PWMD2, 0, PWM_PERCENTAGE_TO_WIDTH(&PWMD2, 7500)); 
pwmEnableChannel(&PWMD2, 1, PWM_PERCENTAGE_TO_WIDTH(&PWMD2, 7500)); 
osalThreadSleepMilliseconds(5000);

The result is, that submodule0 still woks fine, but the outputs of submodule1 not. Is there any additional work to do, when I want to use the other PWM submodules? Best regards, Patrik
This discussion has been locked for participation. If you have a question, please start a new topic in order to ask your question
1 ACCEPTED SOLUTION

Accepted Solutions
zambrano.luigi
Senior III
Posted on January 16, 2015 at 14:37

Hello,

the issue will be solved in the next release. Meanwhile you can use the following workaround: replace in the file components/spc56elxx_hal_drivers_component/lib/src/pwm_lld.c the line

if ((pwmp->flexpwmp->MASK.B.MASKA & (1U << sid)) == 1)

with the line

if ((pwmp->flexpwmp->MASK.B.MASKA & (1U << sid)) == (1U << sid))

and the line

if ((pwmp->flexpwmp->MASK.B.MASKB & (1U << sid)) == 1)

with the line

if ((pwmp->flexpwmp->MASK.B.MASKB & (1U << sid)) == (1U << sid))

Please, note that the file pwm_lld.c will be replaced with the original version (losing the modifications for the fix) everytime you generate the code by pushing on the Quick Generate button.

Regards,

Luigi

View solution in original post

7 REPLIES 7
zambrano.luigi
Senior III
Posted on January 16, 2015 at 14:37

Hello,

the issue will be solved in the next release. Meanwhile you can use the following workaround: replace in the file components/spc56elxx_hal_drivers_component/lib/src/pwm_lld.c the line

if ((pwmp->flexpwmp->MASK.B.MASKA & (1U << sid)) == 1)

with the line

if ((pwmp->flexpwmp->MASK.B.MASKA & (1U << sid)) == (1U << sid))

and the line

if ((pwmp->flexpwmp->MASK.B.MASKB & (1U << sid)) == 1)

with the line

if ((pwmp->flexpwmp->MASK.B.MASKB & (1U << sid)) == (1U << sid))

Please, note that the file pwm_lld.c will be replaced with the original version (losing the modifications for the fix) everytime you generate the code by pushing on the Quick Generate button.

Regards,

Luigi

Patriks
Senior
Posted on January 19, 2015 at 07:35

Hello,

Thanks, your workaround solved the problem. Can you explain the effect of the changed lines to me? I would like to understand why the PWM outputs are activated now. Maybe you can also help me understanding the configuration of the PWM outputs by using the PWMconfig structure. Currently it looks like that:

const PWMConfig pwm_config_pwmcfg = { 
250000, 
50000, 
NULL, 
{ 
{ 
PWM_OUTPUT_ACTIVE_HIGH | PWM_COMPLEMENTARY_OUTPUT_DISABLED, 
NULL 
}, 
{ 
PWM_OUTPUT_ACTIVE_HIGH | PWM_COMPLEMENTARY_OUTPUT_DISABLED, 
NULL 
} 
}, 
PWM_ALIGN_EDGE 
};

This settings leads to a measured PWM frequency of 5 Hz.In which way correspond the two valuesfor frequency and periodwithin the PWMconfig structureto the PWM output frequency? Best regards, Patrik
zambrano.luigi
Senior III
Posted on January 19, 2015 at 12:03

Hi,

in order to use the pwm channels, you have to unmask the related submodule. With the previous code version, the submodules 1-3 are not correctly unmasked.

The PWM structure contains the PWM parameters that you set by using the graphic interface. The first parameter (

250000

) is the PWM clock frequency, the second (

50000

) is the PWM period, the third (NULL) is the pointer to the period callback function (you can define a function that are called at the end of every period). Then you can find two structures that define the properties of tha channel a and of channel b.

Regards,

Luigi

Patriks
Senior
Posted on January 19, 2015 at 13:23

Hello,

Thanks again for your explanation. I think I understand now why my PWM configuration leads to a 5Hz PWM Signal.

1/250.000 * 50.000 = 0,2 seconds ==> 5Hz 

Best regards,

Patrik

zambrano.luigi
Senior III
Posted on January 19, 2015 at 13:36

Yes, you are right. 

Best Regards,

Luigi

Patriks
Senior
Posted on January 22, 2015 at 13:54

Hello,

I have another question about the FlexPWM. I would like to synchronize a timer with the rising edge of my generated PWM signal. That means a counter should start at the rising edge and count up until it re-initializes with the next rising edge. For my application, it is very important, that the counter always starts exactly with the rising PWM edge. Is there a way to do that counter start and initialization in hardware? In the reference manual, I read something about CTU and eTimer.

Best regards,

Patrik

zambrano.luigi
Senior III
Posted on January 28, 2015 at 07:46

Hi Patrik

sorry for the delay. I think your problem can be solved by using the CTU (Cross Triggering Unit) in pair with one of the eTimer (e.g. eTimer0). You can configure the CTU in order to generate the trigger event EMITER0_TRG on the rising edge of one of the PWM signals. Then you have to configure the eTimer0 in One-Shot mode with Secondary Count Source = AUX0. In this way the eTimer0 should restart on every rising edge of the PWM. At the moment the code to manage this functionality is not included in SPC5Studio.

Best Regards,

Luigi