From 104ddc6f98bb8dbf6b457f18232a5b736bee675a Mon Sep 17 00:00:00 2001 From: Jonathan Armstrong Date: Mon, 16 Dec 2024 01:20:40 -0600 Subject: [PATCH] use dedicated pca counter on efm8bb1 after all --- Makefile | 4 ++-- drivers/efm8bb1/inc/timer_interrupts.h | 3 +++ drivers/efm8bb1/src/hal.c | 13 +++++-------- src/main_portisch.c | 2 +- 4 files changed, 11 insertions(+), 11 deletions(-) diff --git a/Makefile b/Makefile index dbc89cb..5da83c4 100644 --- a/Makefile +++ b/Makefile @@ -49,9 +49,9 @@ # sonoff black box #TARGET_BOARD = EFM8BB1 # low cost development board -TARGET_BOARD = EFM8BB1LCB +#TARGET_BOARD = EFM8BB1LCB # sonoff white box -#TARGET_BOARD = OB38S003 +TARGET_BOARD = OB38S003 # catches undefined ifndef TARGET_BOARD diff --git a/drivers/efm8bb1/inc/timer_interrupts.h b/drivers/efm8bb1/inc/timer_interrupts.h index cd52910..005c5cf 100644 --- a/drivers/efm8bb1/inc/timer_interrupts.h +++ b/drivers/efm8bb1/inc/timer_interrupts.h @@ -14,6 +14,9 @@ // original portisch used 0xA0 which seems incorrect (they used 0x0B later) // and 0x0B value makes more sense: // 1/((24500000)/(256-0x0B)) = 0.00001 +// for 1 microsecond +// hex(256 - (1*10^-6)/(1/(24500000))) = 0xE7.8 +//#define TIMER0_PCA0 0xE8 #define TIMER0_PCA0 0x0B // 19200 baud, same on portisch diff --git a/drivers/efm8bb1/src/hal.c b/drivers/efm8bb1/src/hal.c index 5de450d..26f1ac8 100644 --- a/drivers/efm8bb1/src/hal.c +++ b/drivers/efm8bb1/src/hal.c @@ -33,7 +33,7 @@ void set_clock_mode(void) // as explained in timer_interrupts.hal // 1/((24500000)/(256-0x0B)) = 0.00001 seconds - CKCON0 |= T0M__SYSCLK; + //CKCON0 |= T0M__SYSCLK; // FIXME: this is only applicable for split 8-bit timer mode, need to double check // FIXME: used for portisch @@ -206,7 +206,7 @@ void pca0_halt(void) CR = 0; } - +// as I recall, we were double clearing this flag //void clear_capture_flag(void) //{ // // overflow flag @@ -214,19 +214,16 @@ void pca0_halt(void) // CF = 0; //} -// the time constant is explained in the rcswitch.c file +// time conversion is explained in the rcswitch.c file uint16_t countsToTime(const uint16_t counts) { uint16_t duration; - - //duration = counts / 2; - + // this only saves two code bytes on ob38s003 apparently // equivalent to divide by two + //duration = counts / 2; duration = counts >> 1; - //duration = counts; - return duration; } \ No newline at end of file diff --git a/src/main_portisch.c b/src/main_portisch.c index ee31a54..1f9f09b 100644 --- a/src/main_portisch.c +++ b/src/main_portisch.c @@ -541,7 +541,7 @@ void main (void) enable_timer0_interrupt(); enable_timer1_interrupt(); #elif defined(TARGET_BOARD_EFM8BB1) || defined(TARGET_BOARD_EFM8BB1LCB) - // pca used timer0 as timebase on original portisch, we could use the pca counter itself but it is less accurate for microseconds + // pca used timer0 as timebase on original portisch, though we could use the pca counter itself //init_timer0_8bit_autoreload(TIMER0_PCA0); // uart with 19200 baud, uart must use timer1 on efm8bb1 init_timer1_8bit_autoreload(TIMER1_UART0);