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: 121
Joined: Tue Oct 17, 2017 2:24 pm
Has thanked: 43 times
Been thanked: 30 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: 14444
Joined: Wed May 27, 2009 8:48 am
Location: Salerno, Italy
Has thanked: 1074 times
Been thanked: 921 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: 121
Joined: Tue Oct 17, 2017 2:24 pm
Has thanked: 43 times
Been thanked: 30 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: 14444
Joined: Wed May 27, 2009 8:48 am
Location: Salerno, Italy
Has thanked: 1074 times
Been thanked: 921 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: 14444
Joined: Wed May 27, 2009 8:48 am
Location: Salerno, Italy
Has thanked: 1074 times
Been thanked: 921 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: 22
Joined: Sat Mar 17, 2018 2:51 pm
Has thanked: 4 times
Been thanked: 12 times

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: 14444
Joined: Wed May 27, 2009 8:48 am
Location: Salerno, Italy
Has thanked: 1074 times
Been thanked: 921 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: 121
Joined: Tue Oct 17, 2017 2:24 pm
Has thanked: 43 times
Been thanked: 30 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

nikiwaibel
Posts: 22
Joined: Sat Mar 17, 2018 2:51 pm
Has thanked: 4 times
Been thanked: 12 times

Re: Setting up GPT and changing interval

Postby nikiwaibel » Tue Jul 17, 2018 12:00 pm

@wurstnase: thanks for detailed explanation. it makes a lot of sense, if you look at it that way!

@Giovanni: maybe sthg like that could be added to the docs. i think it is important to make very clear that
  • passing 1 stops the timer
  • passing 0 causes the timer to count to MAX (2^16 or 2^32)


Return to “Bug Reports”

Who is online

Users browsing this forum: No registered users and 8 guests