Page 1 of 1

How to generate HF clock output?

Posted: Mon Aug 10, 2015 7:05 am
by ceremcem
We are using ChibiOS STM32F407 Discovery Board (8Mhz XTAL) to generate a relatively high frequency output (500 kHz) with the following code:

Code: Select all

    static void squareWave(void *arg)
    {
        /* PB0 will be used for square wave
            use AlternateFunction.0 for digital io
        */
   
        palSetPadMode(GPIOB, 0, PAL_MODE_ALTERNATE(0));
       palSetPadMode(GPIOB, 0, PAL_MODE_OUTPUT_PUSHPULL);
   
        while(true)
        {
            palSetPad(GPIOB, 0);
            chThdSleepMicroseconds(1);
            palClearPad(GPIOB, 0);
            chThdSleepMicroseconds(1);
        }
    }



But the result is 10 kHz or so. What do we do wrong?

Edit

if `#define CH_CFG_ST_FREQUENCY 10000` remains in `chconf.h`, it does produce a 10 kHz output. When we change that value from 10000 to 1000000, it gives just about 100 kHz (99.8 kHz or so), but not 500 kHz. Also,

Re: How to generate HF clock output?

Posted: Mon Aug 10, 2015 7:22 am
by Giovanni
What version are you using?

For that kind of things better use the PWM driver anyway.

Giovanni

Re: How to generate HF clock output?

Posted: Thu Aug 27, 2015 2:21 pm
by ceremcem
I'm using ChibiOS-3.x. Regarding to your suggestion, I wrote a simple variable frequency PWM generator:

https://github.com/ceremcem/chibi-test/ ... 282/main.c

It's dirty but it works.

Thank you for leading.

Note: I was not aware of your answer. Fixed this in the notification settings. Anyway, I'm sorry for the late response.

Re: How to generate HF clock output?

Posted: Thu Aug 27, 2015 2:24 pm
by Giovanni
Hi,

I forgot to mention, there are also the MCO1 and MCO2 pins that can output any internal clock source. Depending on the frequency you need you may also consider them.

Giovanni

Re: How to generate HF clock output?

Posted: Thu Aug 27, 2015 11:53 pm
by ceremcem
As per question, that would be a sensible option, but I omitted to say that I needed that kind of variable frequency. Since I was pretty sure about the code block that generates the squarewave, I thought I might change the sleep time as I wish at the end of this issue, but pwm driver does exacly what I would :)