WIP: redo power sequence

This commit is contained in:
Jeremy Soller
2019-11-22 10:02:24 -07:00
parent 6585f917c2
commit 9cfd3a8d5a
2 changed files with 126 additions and 7 deletions

View File

@ -9,14 +9,19 @@ void delay_ticks(uint16_t ticks) {
timer_stop();
}
// One millisecond in ticks is determined as follows:
// 9.2 MHz is the clock rate
// The timer divider is 12
// The timer rate is 12 / 9.2 MHz = 1.304 us
// The ticks are 1000 ms / (1.304 us) = 766.667
// 65536 - 766.667 = 64769.33
// 1 us * 9.2 MHz / 12 is 69/90
// Warning: this will round to the nearest tick
#define delay_us(X) \
delay_ticks((uint16_t)((((uint32_t)(X)) * 69UL + 89UL) / 90UL));
// 1 ns * 9.2 MHz / 12 is 69/90000
// Warning: this will round to the nearest tick
#define delay_ns(X) \
delay_ticks((uint16_t)((((uint32_t)(X)) * 69UL + 89999UL) / 90000UL));
// This loops through delays of one ms in order to avoid overflow
void delay_ms(int ms) {
for (int i = 0; i < ms; i++) {
delay_ticks(767);
delay_us(1000);
}
}