Software PWM

取消
显示结果 
显示  仅  | 搜索替代 
您的意思是: 

Software PWM

2,398 次查看
saberragab
Contributor II

 Hello All, i need to make software PWM 3 channels with minimum CPUload and minimum # of timers i'm using S12ZVL128K any one can help me.

13 回复数

1,922 次查看
danielmartynek
NXP TechSupport
NXP TechSupport

Hi,

 

The S12ZVL128 has a PWM module.

Please refer to the attached example code.

 

Regards,

Daniel

0 项奖励
回复

1,922 次查看
saberragab
Contributor II

Hi Daniel,

Thanks for your reply , I know that MagniV has (4 channels 16 bit)HW PWM but i need (7) channels ,So three more channels needed to be implemented by SW.

0 项奖励
回复

1,922 次查看
danielmartynek
NXP TechSupport
NXP TechSupport

Hi,

The S12ZVL128 has actually two PWM modules.

You can therefore use 8 16-bit channels.

See following:

Table 1-2. MC9S12ZVL-Family Comparison.

Figure 1-8. PWM channel mapping for MC9S12ZVL(A)128/96/64

Appendix O.9, O.10 Detailed Register Address MAP for PWM0, PWM1.  

 

Regards,

Daniel

0 项奖励
回复

1,922 次查看
saberragab
Contributor II

Hi,

Thanks again but according to the data sheet 17.4.2.7 PWM 16-Bit Functions say that 4 channels 16 bit only
"The scalable PWM timer also has the option of generating up to 8-channels of 8-bits or 4-channels of
16-bits for greater PWM resolution."

0 项奖励
回复

1,922 次查看
danielmartynek
NXP TechSupport
NXP TechSupport

That is true for one PWM module. But S12ZVL128 has 2 PWM modules.

In figure 1-8 you can see 2 PWM modules, 16 8-bit channels concatenated into 8 16-bit channels.

1,922 次查看
saberragab
Contributor II

Hello Daniel,

You are right  but it was not clear in the datasheet if you have example code how to use PWM1?.
because it seems that the registers are the same as PWM0 and according to the datasheet Figure 17-21. PWM 16-Bit Mode the only mode is to use 4 channels 16 bit mode only?

0 项奖励
回复

1,922 次查看
danielmartynek
NXP TechSupport
NXP TechSupport

Hello,

We don’t have an example code, but it should not be difficult.

 

The name of PWM0-1 registers are the same but they have different addresses. If you look at the S12ZVL128.h header file, you will see that all registers are mapped.

For instance, instead of enable channel 1: PWME_PWME1, there are PWM0E_PWME1, PWM1E_PWME1.

 

I think you can use 8-bit as well, for example PMW0_ch1 or PMW0_ch3 but not PMW0_ch2 because this channel is not routed to a port.

 

The example code I attached previously shows how to concatenate two channels.

For PWM0_Ch01 it will be:

PWM0CTL_CON01 = 1;

For PWM1_Ch01:

PWM1CTL_CON01 = 1;

In this case, channels 0 becomes high order byte of the timer,

channels 1 are used for control determination (clock, polarity, alignment, enablement).

 

I hope it helps.

 

Regards,

Daniel

0 项奖励
回复

1,922 次查看
saberragab
Contributor II

Hello Daniel,

I have checked with NXP and told me that the document is wrong and needs to be corrected.

Could you please confirm?And i have another question how to map the output of PWM0 and PWM1 because if i concatenated two channels 0,1 for both PWM0 and PWM1 So the output PIN in this case is channel 1 which will be common for both how this case will be handled.

0 项奖励
回复

1,922 次查看
danielmartynek
NXP TechSupport
NXP TechSupport

Hi,

Could you please specify what exactly is wrong? Thanks.

 

The output of PWM0, channels 0-1 of is routed to PWM OPTION 1 of the PIM module.

Whereas the output of PWM1 channels 0-1 of is routed to PWM OPTION 0 of the PIM module.

As you can see in Figure 1-8.

In the PIM module, PWM options 0-7 are routed to Port P by default and can be rerouted in MODRR1 register.

 

Regards,

Daniel

0 项奖励
回复

1,922 次查看
saberragab
Contributor II

Hello Daniel,

Thanks for reply my small issue is that when i have contacted NXP by mail they told me that the number of channels available for S12ZVL128 are 8 channels 8 bit and the section in the datasheet need to be corrected , So Could you please confirm?

Regarding to your proposal when i concatenate channel 0,1 for PWM0 , So the output is channel 1
the same will happen for PWM1 in that case the output for both is channel 1, so what we can do with rerouting now?

0 项奖励
回复

1,922 次查看
saberragab
Contributor II

Hello Daniel,

I understand your proposal now thank you. Could you please just confirm if S12ZVL128 has 8*16 bit PWM ?

0 项奖励
回复

1,922 次查看
danielmartynek
NXP TechSupport
NXP TechSupport

Hello,

I don’t think the datasheet needs to be corrected. You should be able to use 8 16-bit PWMs. The mc9s12zvl128.h header file clearly handles 2 PWM modules. I would like to try it, but I’m out of office this week.

Regards,

Daniel

1,922 次查看
saberragab
Contributor II

Hi Daniel,

Thank you very much the issue solved.

0 项奖励
回复