Compare commits

...

4 commits

Author SHA1 Message Date
Stephan I. Böttcher
20d4e45356 bate: reduce standby current into pins
MCLK and DOUT randomly stick at high or low when the µC enters standby
mode.

MCLK TCA0 WO0 is properly disabled to keep the pin at low level.  A high
level pushes current into the pressure sensor.

DOUT input pullup is not enabled.  A low level on DOUT (LSB of the
temperature) pulls current from the pullup.
2024-04-15 19:53:21 +02:00
Stephan I. Böttcher
2a6254c24a minor style fixes, review with Björn 2024-04-15 19:52:33 +02:00
Stephan I. Böttcher
5d7679fbb4 make: explicit spi clk speed cpu_clk/64 2024-04-15 19:51:19 +02:00
Stephan I. Böttcher
28d492bdaf make: build bate.eeprom with bate.hex 2024-04-15 15:56:36 +02:00
4 changed files with 43 additions and 21 deletions

View file

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

View file

@ -89,19 +89,48 @@ void rfen(uint8_t on)
#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
void init_mclk(uint8_t p)
{
if (p < 50 || p > 100)
if (!p || p==0xff)
p = PERIOD;
PORTB.DIRSET = Bit(0);
VPORTB.DIR |= Bit(0); // MCLK
MCLK.INTCTRL = TCA_SINGLE_CMP0_bm;
MCLK.CMP0 = p;
MCLK.CTRLA = TCA_SINGLE_CLKSEL_DIV2_gc;
MCLK.CTRLB = TCA_SINGLE_CMP0EN_bm | TCA_SINGLE_WGMODE_FRQ_gc;
mclk(1);
BATE_PORT.DIR |= Bit(DIN_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)
@ -137,7 +166,7 @@ void bate_wait()
uint16_t timeout = 3277; // 50ms
tick = 0;
while (BATE_PORT.IN & Bit(DOUT_PORT)) {
PORTA.PIN2CTRL = PORT_PULLUPEN_bm | PORT_ISC_FALLING_gc;
PORTA.PIN2CTRL = PA2_PULLUP | PORT_ISC_FALLING_gc;
sleep_cpu();
if (tick) {
tick = 0;
@ -147,16 +176,7 @@ void bate_wait()
}
}
}
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;
PORTA.PIN2CTRL = PA2_PULLUP | PORT_ISC_INTDISABLE_gc;
}
static inline

View file

@ -27,8 +27,8 @@ void bate_calib(const union bate *bate, struct pressure *pt)
uint16_t D1 = bate->D1;
uint16_t D2 = bate->D2;
uint16_t UT1 = C5 + 20224;
uint16_t dT = D2 - UT1;
uint16_t UT1 = C5 + 20224;
uint16_t dT = D2 - UT1;
uint16_t TEMPSENS = C6 + 50;
int16_t TEMP = mul16sun(dT, TEMPSENS, 6) + 200;
@ -36,7 +36,7 @@ void bate_calib(const union bate *bate, struct pressure *pt)
int16_t TCO = C4 - 512;
uint16_t OFFT1 = C2 << 2;
// fails when TCO < 0
uint16_t OFF = OFFT1 + mul16sun(dT, TCO, 4);
uint16_t OFF = OFFT1 + mul16sun(dT, TCO, 4);
uint16_t SENST1 = C1 + 24576;
uint16_t TCS = C3;

View file

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