Learn MoreFAQsTutorials

6 posts / 0 new
Last post
magergar
Offline
Last seen:1 month 3 weeks ago
加入:2020-05-26 18:20
DA14531 PWM Frequency

Hi

Im trying to learn how to use the peripherals of the module DA14531 and using the example.

I manage to generate a PWM and removed the for loop that change the pwm DC and fixed to 50% but the frequency is the problem

I can't understand the formula that it use, in the datasheet says that:

Timer2_clk_freq_Hz/Required_freq_Hz − 1

an the example has a function that does that:

timer2_pwm_freq_set();

but I can't get the desired frequency

I can move the parameter to get something close but the point is to know the exact formula and not guessing...

Is there something I am doing wrong?

PM_Dialog
Offline
Last seen:3 hours 33 min ago
Staff
加入:2018-02-08 11:03
Hi magergar,

Hi magergar,

Thanks for your question online and for your interest in our TINY module solution. The timer2_pwm_freq_set() configure the TRIPLE_PWM_FREQUENCY register. Please see Table 327: TRIPLE_PWM_FREQUENCY (0x50003408) in the DA14531 datasheet to check how it should be configured.

I guess that you are using the timer2 example of the SDK. Can I ask what you are trying to accomplish and what should be the PWM output signal? Do you want to change the duty cycle?

Regarding the frequency, please also read the comment above the timer2_pwm_freq_set() in timer2,h header file.

Thanks, PM_Dialog

magergar
Offline
Last seen:1 month 3 weeks ago
加入:2020-05-26 18:20
Hi,

Hi,

Yes I'm using the example in the sdk for Timer2(PWM)

What I'm trying to do is get 1kHz and just change the duty cycle between 0-100%

Just for now I set it to 50% a don't have any trouble with this my problem is still the frequency

in the example is like this

// System clock, divided by 8, is the Timer2 input clock source (according
// to the clk_div_config struct above).PWM_FREQUENCY
timer2_pwm_freq_set(500, 1600000/8);

and it's suposed to give 500Hz

but I have notice that the example is based on the DA14585 device (which I read that works with 16MHz) and my device works with 32Mhz says the datasheet

so I changed to

ttimer2_pwm_freq_set(1000, 4000000);

and the frequency I get for this is 3.676Hz...

the datasheet says that the TRIPLE_PWM_FREQUENCY registry has this formula:

pwm freq = module Frequency / (value+1)

which is the exact formula in this function -> timer2_pwm_freq_set()

I still don't know why I get such low frequency and not even a round number 3.676Hz its a little bit strange

to get the frequency of 1khz I changed the values to this

timer2_pwm_freq_set(6700u, 100000);

and I get 1.053kHz in the oscilloscope but to me is really odd

waiteyang
Offline
Last seen:3 weeks 11 hours ago
加入:2017-02-17 09:19
要使用系统的CLK

要使用系统的CLK

static tim2_config_t config =
{
.clk_source = TIM2_CLK_SYS,
.hw_pause = TIM2_HW_PAUSE_OFF
};

magergar
Offline
Last seen:1 month 3 weeks ago
加入:2020-05-26 18:20
This works perfectly thanks

This works perfectly thanks for the reply

The example code didn't have this line: ".clk_source = TIM2_CLK_SYS,"

with this I set:

// System clock, divided by 8, is the Timer2 input clock source (according to the clk_div_config struct above)

timer2_pwm_freq_set(PWM_FREQUNCY, 2000000); //in my case PWM_FREQUNCY=1000

and I get exactly the frequncy I put

PM_Dialog
Offline
Last seen:3 hours 33 min ago
Staff
加入:2018-02-08 11:03
Hi waiteyang, Thanks for your

嗨waiteyang,谢谢你的建议!It would be very helpful for the other community.

Hi magergar. Glad that you figured the issue out.

Thanks, PM_Dialog