NHS3152 16 bit Timer PWM

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

NHS3152 16 bit Timer PWM

849 Views
VitoDes
Contributor I

Hello everyone,

I tried to use the 16 bit timer as PWM generator on NHS3152 chip with CT16_M0 and M1 pins and it seems that the highest frequency reached is only 30Hz when the system clock is 2MHz and the timer prescaler is set to 0.

I also tried to set the the system clock to 8MHz and the PWM reach 120Hz (logically), whiwh is still too slow for our application.

Is there any advice on how to increase the frequency, or did I make something wrong in the program ?

Here is the simple code implemented :

Chip_IOCON_SetPinConfig(NSS_IOCON, IOCON_PIO0_3, IOCON_FUNC_1);
Chip_IOCON_SetPinConfig(NSS_IOCON, IOCON_PIO0_7, IOCON_FUNC_1);

Chip_TIMER16_0_Init();

Chip_TIMER_PrescaleSet(NSS_TIMER16_0, 0);

Chip_TIMER_SetMatch(NSS_TIMER16_0, 0, 20000);
Chip_TIMER_MatchDisableInt(NSS_TIMER16_0, 0);
Chip_TIMER_StopOnMatchDisable(NSS_TIMER16_0, 0);
Chip_TIMER_ResetOnMatchDisable(NSS_TIMER16_0, 0);

Chip_TIMER_SetMatch(NSS_TIMER16_0, 1, 40000); 
Chip_TIMER_MatchDisableInt(NSS_TIMER16_0, 1);
Chip_TIMER_StopOnMatchDisable(NSS_TIMER16_0, 1);
Chip_TIMER_ResetOnMatchDisable(NSS_TIMER16_0, 1);

Chip_TIMER_SetMatchOutputMode(NSS_TIMER16_0, 0, TIMER_MATCH_OUTPUT_PWM);
Chip_TIMER_SetMatchOutputMode(NSS_TIMER16_0, 1, TIMER_MATCH_OUTPUT_PWM);
Chip_TIMER_Reset(NSS_TIMER16_0);
Chip_TIMER_Enable(NSS_TIMER16_0);

 Thank you.

0 Kudos
5 Replies

802 Views
mario_castaneda
NXP TechSupport
NXP TechSupport

Hi @VitoDes,

I hope you are doing great.

Just to confirm, both pins are getting a low frequency?

Did you check the note that is the reference manual 15.9.10? what is the value of your MCR is set as logic 0?

Regards,

Mario

0 Kudos

775 Views
VitoDes
Contributor I

Hi @mario_castaneda,

Hope you are fine, sorry for the late answer.

Both pins are the same frequency and have exactly the same beahviour.

I've read the 15.9.10 section and the MCR is set as logic 0 the same as the MR registers are setted with the good values. 

I have just a question about the note in 15.9.10 section, it says that the MCR must be set to logic 0 in order to disable the reset and the stop on match and just after it says to set the MRR bit to logic 1 in order to enable the timer reset. But this operation does not allow to control the width of the pulse.

Is there a part of the code I am missing ?

 

Thank you.

Best regards.

0 Kudos

712 Views
VitoDes
Contributor I

Hello @mario_castaneda,

Hope you are fine.

Did you find something about the pwm low frequency, please ?

Thank you for your support.

Best regards.

0 Kudos

818 Views
VitoDes
Contributor I

Hello @mario_castaneda,

Thank you for your answer, I was aware about this comments and I've already tried to PrescaleSet to 1 which gave me a 15Hz frenquency, as well as agument 10 gave 3Hz PWM. That's why I tried to set prescaler to 0 to have the maximum frequency. Everything looks consistent with a nominal frequency of 30Hz.

The same way I tried the command :

Chip_TIMER_PrescaleSet(NSS_TIMER16_0, ((uint32_t)Chip_Clock_System_GetClockFreq() / 250) - 1);

found in the timer_nss_example_3, didn't set a 250Hz PWM as it should.

 

Thank you for your support.

Best regards.

 

0 Kudos

833 Views
mario_castaneda
NXP TechSupport
NXP TechSupport

Hi @VitoDes,

Please look at the comments below.

/* - The timer frequency is derived from the system clock frequency.
* - A prescaler value of n will result in a divider of (n+1)
* Set the timer to tick very slow - accuracy is not a concern here.
* A large prescaler value that still gives a couple of units at the slowest system clock frequency is chosen:
* 2**13 - 1. This gives 7 ticks per second @62.5kHz, 61 ticks @500kHz, 976 @8MHz.
*/
Chip_TIMER_PrescaleSet(NSS_TIMER16_0, (1<<13) - 1);

Could you please try to pass an argument as 1?

Regards,

Mario

0 Kudos