Problem in Systick timer on KL46Z

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Problem in Systick timer on KL46Z

2,598 Views
duyba
Contributor II

Hi all,

I am the beginner and I am having problem in blinking 2 Leds with distinct frequencies (1 Hz, and 2 Hz). How can I config Systick_config() function to get 2 different frequencies at the same time?

Thank you!

P/s: sorry for my bad English.

Labels (1)
4 Replies

1,594 Views
mjbcswitzerland
Specialist V

Hi

SysTick can only generate interrupts at a single periodic rate.

It also has a maximum rate so it is often not possible to directly generate 1Hz (50MHz clock will, for example, allow about max. 335ms period).

To control multiple periods you can use a fixed TICK speed (say 50ms) and then a SW counter for each period that you would them like to control something.

eg.

Each time the SysTick interrupt fires (assumed 50ms rate)

static int iTimer1 = 0;

static int iTimer2 = 0;

if (++iTimer1 >= (500/50)) {

    iTimer1 = 0;

    TOGGLE_LED1(); // toggle LED 1 at 1Hz

}

if (++iTimer2 >= (250/50)) {

    iTimer2 = 0;

    TOGGLE_LED2(); // toggle LED2 at 2Hz

}

Regards

Mark

http://www.utasker.com/kinetis.html

1,594 Views
duyba
Contributor II

Thanks for your advice. The variables: Timer1 and Timer2 will increase whenever SysTick interrupt? So we still need to define the SysTick configuration by function SysTick_Config() in main section? Could you explain more about this function such the function's parameter? I think we can directly generate 1 Hz by SysTick_Config(SystemCoreClock/1), the clock of System is 48 MHz. Thanks!

Regards,

Duy

0 Kudos

1,594 Views
mjbcswitzerland
Specialist V

Duy

I don't know the function SysTick_Config() so you will need to look at its code to see what it does any what its parameters control.

Beware that the SYSTICK reload register has only 24 valid bits and so the largest value that can be set is 0x00ffffff, which is about 349.5ms with 48MHz core clock.

Regards

Mark

0 Kudos

1,594 Views
duyba
Contributor II

Thanks so much for your help!

Regards,

Duy

0 Kudos