How to generate HF clock output?

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

Moderators: barthess, RoccoMarco

ceremcem
Posts: 59
Joined: Mon Aug 10, 2015 6:57 am
Has thanked: 6 times
Been thanked: 3 times

How to generate HF clock output?

Postby ceremcem » Mon Aug 10, 2015 7:05 am

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,

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

Re: How to generate HF clock output?

Postby Giovanni » Mon Aug 10, 2015 7:22 am

What version are you using?

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

Giovanni

ceremcem
Posts: 59
Joined: Mon Aug 10, 2015 6:57 am
Has thanked: 6 times
Been thanked: 3 times

Re: How to generate HF clock output?

Postby ceremcem » Thu Aug 27, 2015 2:21 pm

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.

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

Re: How to generate HF clock output?

Postby Giovanni » Thu Aug 27, 2015 2:24 pm

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

ceremcem
Posts: 59
Joined: Mon Aug 10, 2015 6:57 am
Has thanked: 6 times
Been thanked: 3 times

Re: How to generate HF clock output?

Postby ceremcem » Thu Aug 27, 2015 11:53 pm

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 :)


Return to “STM32 Support”

Who is online

Users browsing this forum: No registered users and 4 guests