Skip to content

Commit

Permalink
use dedicated pca counter on efm8bb1 after all
Browse files Browse the repository at this point in the history
  • Loading branch information
mightymos committed Dec 16, 2024
1 parent 0e755d5 commit 104ddc6
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 11 deletions.
4 changes: 2 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 3 additions & 0 deletions drivers/efm8bb1/inc/timer_interrupts.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
13 changes: 5 additions & 8 deletions drivers/efm8bb1/src/hal.c
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -206,27 +206,24 @@ void pca0_halt(void)
CR = 0;
}


// as I recall, we were double clearing this flag
//void clear_capture_flag(void)
//{
// // overflow flag
// //PCA0CN0 &= ~CF__SET;
// 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;
}
2 changes: 1 addition & 1 deletion src/main_portisch.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit 104ddc6

Please sign in to comment.