GPT set frequency

ChibiOS public support forum for topics related to the STMicroelectronics STM32 family of micro-controllers.

Moderator: RoccoMarco

fastlink30
Posts: 42
Joined: Tue Aug 12, 2014 1:25 pm

GPT set frequency

Post by fastlink30 »

with this code the led toggle every 7 sec.!! but the frequency specified on the gptcfg2 is 11khz, what i not have understood? looking on the web api page, the frequency to specify is on Hz
running on stm32f103r8, the only task running is the main

Code: Select all

static void gptcallback2(GPTDriver *gptp) {
   (void) gptp;
   palTogglePad(PORT_LED1, GPIOC_LED1);
}

static GPTConfig gptcfg2 = {
  11025,                     // frequency
  gptcallback2,               // callback
  0,
  0
};

main()
.....
   gptStart(&GPTD8, &gptcfg2);
   gptStartContinuous(&GPTD8, 0);
    while (TRUE)
    {
    }
User avatar
Giovanni
Site Admin
Posts: 14893
Joined: Wed May 27, 2009 8:48 am
Has thanked: 1202 times
Been thanked: 997 times

Re: GPT set frequency

Post by Giovanni »

Hi,

The frequency is obtained using the timer (integer, 16 bits) divider, not necessarily any frequency can be specified in that field.

If you enable assertions in chconf.h and you set a frequency that cannot be generated then gptStart() will be halted with a message.

7 seconds is strange anyway.

Giovanni
fastlink30
Posts: 42
Joined: Tue Aug 12, 2014 1:25 pm

Re: GPT set frequency

Post by fastlink30 »

activated assertion

with 11000 get assertion on gpt_llg.c, so i tryed with 2000, and no assertion
anyway,now, the led pulse with 20sec positive phase :shock:
there are something wrong

also i look gpt_lld.c and
osalDbgAssert(((uint32_t)(psc + 1) * gptp->config->frequency) == gptp->clock,
"invalid frequency");

not must be
osalDbgAssert(((uint32_t)(psc + 1) * gptp->config->frequency) >= gptp->clock,
"invalid frequency");

?

psc with 11000 is 6544, clock 72000000 = 71984000, so no assertion must happen
fastlink30
Posts: 42
Joined: Tue Aug 12, 2014 1:25 pm

Re: GPT set frequency

Post by fastlink30 »

sorry if i return on the same question, but after some time i can look where is the problem.
my system is composed as stm32f103re board 72Mhz, chibios 3.0.4, ugfx

I not understand where is my fault, i've done some test but the frequency i set, is never respected

Code: Select all

static GPTConfig gptcfg2 =
{
    20000,                     // frequency
    gptcallback2,               // callback
    0,
    0
};

static void gptcallback2(GPTDriver *gptp)
{
    (void) gptp;
    palTogglePad(PORT_LED1, GPIOC_LED1);
}

void main()
{
    halInit();
    chSysInit();

   gptStart(&GPTD8, &gptcfg2);
   gptStartContinuous(&GPTD8, 0);
    while (TRUE)
    {
           chThdSleepMilliseconds(200);
    }
}

-----

mcuconf

#define STM32_NO_INIT                       FALSE
#define STM32_HSI_ENABLED                   TRUE
#define STM32_LSI_ENABLED                   FALSE
#define STM32_HSE_ENABLED                   TRUE
#define STM32_LSE_ENABLED                   FALSE
#define STM32_SW                            STM32_SW_PLL
#define STM32_PLLSRC                        STM32_PLLSRC_HSE
#define STM32_PLLXTPRE                      STM32_PLLXTPRE_DIV1
#define STM32_PLLMUL_VALUE                  9
#define STM32_HPRE                          STM32_HPRE_DIV1
#define STM32_PPRE1                         STM32_PPRE1_DIV2
#define STM32_PPRE2                         STM32_PPRE2_DIV2
#define STM32_ADCPRE                        STM32_ADCPRE_DIV4
#define STM32_USB_CLOCK_REQUIRED            TRUE
#define STM32_USBPRE                        STM32_USBPRE_DIV1P5
#define STM32_MCOSEL                        STM32_MCOSEL_NOCLOCK
#define STM32_RTCSEL                        STM32_RTCSEL_HSEDIV
#define STM32_PVD_ENABLE                    FALSE
#define STM32_PLS                           STM32_PLS_LEV0


with this configuration the led toggle every 3/4 secs!
if i look documentation i see the frequency must be in Hz

what means 'not necessarily any frequency can be specified in that field.' ?
User avatar
Giovanni
Site Admin
Posts: 14893
Joined: Wed May 27, 2009 8:48 am
Has thanked: 1202 times
Been thanked: 997 times

Re: GPT set frequency

Post by Giovanni »

If you flash the LED using a thread, is the timing correct?

Giovanni
fastlink30
Posts: 42
Joined: Tue Aug 12, 2014 1:25 pm

Re: GPT set frequency

Post by fastlink30 »

same behaviour, also if the code is on another thread


Code: Select all

static THD_WORKING_AREA(waEvents2, 1024);
static THD_FUNCTION(thEvents2,arg)
{
    gptStart(&GPTD8, &gptcfg2);
    gptStartContinuous(&GPTD8, 0);
    while (TRUE)
    {
        chThdSleepMilliseconds(200);
    }
}

main()
{
.....
chThdCreateStatic(waEvents2, sizeof(waEvents2), NORMALPRIO, thEvents2, NULL);
}
User avatar
Giovanni
Site Admin
Posts: 14893
Joined: Wed May 27, 2009 8:48 am
Has thanked: 1202 times
Been thanked: 997 times

Re: GPT set frequency

Post by Giovanni »

Without GPT, just flashing using the thread...

Giovanni
fastlink30
Posts: 42
Joined: Tue Aug 12, 2014 1:25 pm

Re: GPT set frequency

Post by fastlink30 »

yes, every toggle is 200mS

Code: Select all

//    gptStart(&GPTD8, &gptcfg2);
//    gptStartContinuous(&GPTD8, 0);
    while (TRUE)
    {
        chThdSleepMilliseconds(200);
        palTogglePad(PORT_LED1, GPIOC_LED1);
    }
User avatar
Giovanni
Site Admin
Posts: 14893
Joined: Wed May 27, 2009 8:48 am
Has thanked: 1202 times
Been thanked: 997 times

Re: GPT set frequency

Post by Giovanni »

This means that clock settings are correct, this is why I asked to try it.

The problem is with GPT somehow but I don't see anything obviously wrong there, I assume you have assertions and checks enabled in chconf.h.

Giovanni
fastlink30
Posts: 42
Joined: Tue Aug 12, 2014 1:25 pm

Re: GPT set frequency

Post by fastlink30 »

yes, assertions & check enabled, this things make me crazy....
Post Reply