Setting up GPT and changing interval Topic is solved

Report here problems in any of ChibiOS components. This forum is NOT for support.
User avatar
wurstnase
Posts: 55
Joined: Tue Oct 17, 2017 2:24 pm
Has thanked: 22 times
Been thanked: 8 times
Contact:

Setting up GPT and changing interval  Topic is solved

Postby wurstnase » Fri Jan 26, 2018 3:38 am

Hi,

setting up the GPT and changing the interval has different results.

Setup the GPT in continuous mode will set the ARR to interval.
Changing the interval will set the ARR to interval -1.

hal_gpt_lld.c

Code: Select all

void gpt_lld_start_timer(GPTDriver *gptp, gptcnt_t interval) {
  gptp->tim->ARR = (uint32_t)(interval);        /* Time constant.           */


hal_gpt_lld.h

Code: Select all

#define gpt_lld_change_interval(gptp, interval)                               \
  ((gptp)->tim->ARR = (uint32_t)((interval) - 1))
\o/ Nico

User avatar
Giovanni
Site Admin
Posts: 11019
Joined: Wed May 27, 2009 8:48 am
Location: Salerno, Italy
Has thanked: 354 times
Been thanked: 298 times
Contact:

Re: Setting up GPT and changing interval

Postby Giovanni » Fri Feb 02, 2018 11:15 am

Thanks.

Fixed as bug #914.

Giovanni

User avatar
wurstnase
Posts: 55
Joined: Tue Oct 17, 2017 2:24 pm
Has thanked: 22 times
Been thanked: 8 times
Contact:

Re: Setting up GPT and changing interval

Postby wurstnase » Wed Jun 20, 2018 8:56 am

While the GPT driver is:

Code: Select all

#define gpt_lld_change_interval(gptp, interval)                             \
  ((gptp)->tim->ARR = (uint32_t)(interval))


the PWM driver is:

Code: Select all

#define pwm_lld_change_period(pwmp, period)                                 \
  ((pwmp)->tim->ARR = ((period) - 1))
\o/ Nico

User avatar
Giovanni
Site Admin
Posts: 11019
Joined: Wed May 27, 2009 8:48 am
Location: Salerno, Italy
Has thanked: 354 times
Been thanked: 298 times
Contact:

Re: Setting up GPT and changing interval

Postby Giovanni » Sat Jul 07, 2018 10:47 am

I think that the -1 is the correct implementation, timers count up to ARR+1. PWM is fine, will fix GPT.

Giovanni

User avatar
Giovanni
Site Admin
Posts: 11019
Joined: Wed May 27, 2009 8:48 am
Location: Salerno, Italy
Has thanked: 354 times
Been thanked: 298 times
Contact:

Re: Setting up GPT and changing interval

Postby Giovanni » Sat Jul 07, 2018 10:51 am

Fixed as bug #957.

Giovanni

nikiwaibel
Posts: 2
Joined: Sat Mar 17, 2018 2:51 pm

Re: Setting up GPT and changing interval

Postby nikiwaibel » Sat Jul 14, 2018 11:56 pm

hmm, i don't see why ((interval) - 1)) should be correct: if i want an interrupt after 1 tick, i'd like to use

Code: Select all

gptStartOneShot(&GPTD11, 1);

currently (well, since the last update) the above does nothing, as the ARR reg ist loaded with 0 → timer off ("The counter is blocked while the auto-reload value is null.").

User avatar
Giovanni
Site Admin
Posts: 11019
Joined: Wed May 27, 2009 8:48 am
Location: Salerno, Italy
Has thanked: 354 times
Been thanked: 298 times
Contact:

Re: Setting up GPT and changing interval

Postby Giovanni » Sun Jul 15, 2018 6:10 am

Loading ARR with 1 would divide the input clock by 2 not by 1, this is my understanding of manuals, see the various diagrams for up-counting modes.

The counter blocked to zero is expected since it would be reloading at each clock cycle. Is the callback triggered?

Giovanni.

User avatar
wurstnase
Posts: 55
Joined: Tue Oct 17, 2017 2:24 pm
Has thanked: 22 times
Been thanked: 8 times
Contact:

Re: Setting up GPT and changing interval

Postby wurstnase » Sun Jul 15, 2018 1:59 pm

It takes some time and thinking for me also, that -1 is correct.

Running the TIM with 10MHz.
ARR = 1

Code: Select all

0 1 0 1 0 1 0 1
  ^   ^   ^   ^

So in this case the ARR resets with 5MHz.
One tick takes 100ns. One period needs 200ns. (2x)

ARR = 2

Code: Select all

0 1 2 0 1 2 0 1 2 0 1 2
    ^     ^     ^     ^

So in this case the ARR resets with 3.33MHz.
One tick takes again 100ns. One period needs 300ns. (3x)
\o/ Nico


Return to “Bug Reports”

Who is online

Users browsing this forum: No registered users and 3 guests