Compare commits

..

No commits in common. "20d4e45356c380af9ccff5b97253aec6e74c4a79" and "2d860e7deeb9176604b3c3db3df9aa819ff89df6" have entirely different histories.

4 changed files with 21 additions and 43 deletions

View file

@ -126,7 +126,7 @@ BC_TRIG = 0x29
BC_SEND = 0x59 BC_SEND = 0x59
BC_PWR = 0x7c BC_PWR = 0x7c
BC_TEST = 0 BC_TEST = 0
BC_SPI = 4 BC_SPI = 0xff
BC_MDEL = 2 BC_MDEL = 2
BC_PER = 9 BC_PER = 9
BC_CPER = 30 BC_CPER = 30
@ -151,8 +151,6 @@ bate.config:
clean: clean:
rm -f *.hex *.o *.s *.map *.elf *.d rm -f *.hex *.o *.s *.map *.elf *.d
bate.hex: bate.eeprom
.PHONY: eeprom.eeprom .PHONY: eeprom.eeprom
eeprom.eeprom: eeprom.eeprom:
$(AD) -U eeprom:r:$@ $(AD) -U eeprom:r:$@

View file

@ -89,48 +89,19 @@ void rfen(uint8_t on)
#define MCLK TCA0.SINGLE #define MCLK TCA0.SINGLE
// The CMP0 port seems to be randomly high after TCA disable
// The pin on the sensor draws about 30µA when high.
// Just toggling the ENABLE bit is insufficient.
static inline
void mclk(uint8_t on)
{
if (on) {
MCLK.CTRLB = TCA_SINGLE_CMP0EN_bm | TCA_SINGLE_WGMODE_FRQ_gc;
MCLK.CTRLA = TCA_SINGLE_CLKSEL_DIV2_gc | TCA_SINGLE_ENABLE_bm;
}
else {
MCLK.CTRLA = 0;
MCLK.CTRLB = 0;
}
}
static inline static inline
void init_mclk(uint8_t p) void init_mclk(uint8_t p)
{ {
if (!p || p==0xff) if (p < 50 || p > 100)
p = PERIOD; p = PERIOD;
VPORTB.DIR |= Bit(0); // MCLK PORTB.DIRSET = Bit(0);
MCLK.INTCTRL = TCA_SINGLE_CMP0_bm; MCLK.INTCTRL = TCA_SINGLE_CMP0_bm;
MCLK.CMP0 = p; MCLK.CMP0 = p;
mclk(1); MCLK.CTRLA = TCA_SINGLE_CLKSEL_DIV2_gc;
MCLK.CTRLB = TCA_SINGLE_CMP0EN_bm | TCA_SINGLE_WGMODE_FRQ_gc;
BATE_PORT.DIR |= Bit(DIN_PORT); BATE_PORT.DIR |= Bit(DIN_PORT);
BATE_PORT.DIR |= Bit(SCK_PORT); BATE_PORT.DIR |= Bit(SCK_PORT);
PORTA.PIN2CTRL = PORT_PULLUPEN_bm;
// DOUT input.
// The pullup draws 80µA in STDBY, when the sensor happens
// to end with DOUT=0. The attached logic analyser drew 30µA,
// when DOUT=1 so the STDBY current was toggling between 50µA and 100µA.
// 20µA goes into the LDO. Which we may want to remove.
# ifdef DOUT_PULLUP
# define PA2_PULLUP PORT_PULLUPEN_bm
PORTA.PIN2CTRL = PA2_PULLUP;
# else
# define PA2_PULLUP 0
# endif
} }
ISR(PORTA_PORT_vect, ISR_NAKED) ISR(PORTA_PORT_vect, ISR_NAKED)
@ -166,7 +137,7 @@ void bate_wait()
uint16_t timeout = 3277; // 50ms uint16_t timeout = 3277; // 50ms
tick = 0; tick = 0;
while (BATE_PORT.IN & Bit(DOUT_PORT)) { while (BATE_PORT.IN & Bit(DOUT_PORT)) {
PORTA.PIN2CTRL = PA2_PULLUP | PORT_ISC_FALLING_gc; PORTA.PIN2CTRL = PORT_PULLUPEN_bm | PORT_ISC_FALLING_gc;
sleep_cpu(); sleep_cpu();
if (tick) { if (tick) {
tick = 0; tick = 0;
@ -176,7 +147,16 @@ void bate_wait()
} }
} }
} }
PORTA.PIN2CTRL = PA2_PULLUP | PORT_ISC_INTDISABLE_gc; PORTA.PIN2CTRL = PORT_PULLUPEN_bm | PORT_ISC_INTDISABLE_gc;
}
static inline
void mclk(uint8_t on)
{
if (on)
MCLK.CTRLA |= TCA_SINGLE_ENABLE_bm;
else
MCLK.CTRLA &=~ TCA_SINGLE_ENABLE_bm;
} }
static inline static inline

View file

@ -204,7 +204,7 @@ uint16_t divmod10(uint16_t u, uint8_t *mod)
"add r20, r0" "\n\t" "add r20, r0" "\n\t"
"adc %A[r], r1" "\n\t" "adc %A[r], r1" "\n\t"
"adc %B[r], r19" "\n\t" "adc %B[r], r19" "\n\t"
"ldi r19, 10" "\n\t" "ldi r19, lo8(10)" "\n\t"
"inc r20" "\n\t" "inc r20" "\n\t"
"mul r19, r20" "\n\t" "mul r19, r20" "\n\t"
"mov %[d], r1" "\n\t" "mov %[d], r1" "\n\t"