Skip to content

Commit 65d6645

Browse files
committed
Properly round non integer bus-frequencies in MHz
PIT prescaler now rounds to nearest instead of down. Since when FLL is used (default on KL05Z, but also possible on others), the bus frequencies is 23.986MHz, rounding down is bad.
1 parent 8da5345 commit 65d6645

File tree

1 file changed

+1
-1
lines changed
  • libraries/mbed/targets/hal/TARGET_Freescale/TARGET_KLXX

1 file changed

+1
-1
lines changed

libraries/mbed/targets/hal/TARGET_Freescale/TARGET_KLXX/us_ticker.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ static void pit_init(void) {
4444
PIT->CHANNEL[1].TCTRL |= PIT_TCTRL_TEN_MASK; // Start timer 1
4545

4646
// Use channel 0 as a prescaler for channel 1
47-
PIT->CHANNEL[0].LDVAL = bus_frequency() / 1000000 - 1;
47+
PIT->CHANNEL[0].LDVAL = (bus_frequency() + 500000) / 1000000 - 1;
4848
PIT->CHANNEL[0].TCTRL = PIT_TCTRL_TEN_MASK; // Start timer 0, disable interrupts
4949
}
5050

0 commit comments

Comments
 (0)