Page 1 of 2

GPT set frequency

Posted: Sat Nov 28, 2015 12:10 pm
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)
    {
    }

Re: GPT set frequency

Posted: Sat Nov 28, 2015 1:19 pm
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

Re: GPT set frequency

Posted: Sat Nov 28, 2015 2:09 pm
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

Re: GPT set frequency

Posted: Sat Dec 19, 2015 5:15 pm
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.' ?

Re: GPT set frequency

Posted: Sat Dec 19, 2015 6:50 pm
by Giovanni
If you flash the LED using a thread, is the timing correct?

Giovanni

Re: GPT set frequency

Posted: Sat Dec 19, 2015 7:01 pm
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);
}

Re: GPT set frequency

Posted: Sat Dec 19, 2015 7:29 pm
by Giovanni
Without GPT, just flashing using the thread...

Giovanni

Re: GPT set frequency

Posted: Sat Dec 19, 2015 7:36 pm
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);
    }

Re: GPT set frequency

Posted: Sat Dec 19, 2015 8:02 pm
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

Re: GPT set frequency

Posted: Sat Dec 19, 2015 8:51 pm
by fastlink30
yes, assertions & check enabled, this things make me crazy....