Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

several patches that mean a dramatic power reduction while in idle/armed + neutral #102

Open
wants to merge 11 commits into
base: master
Choose a base branch
from
7 changes: 5 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ AUX_TARGETS = afro_pr0.hex afro_pr1.hex diy0.hex

all: $(ALL_TARGETS)

$(ALL_TARGETS): tgy.asm boot.inc
$(AUX_TARGETS): tgy.asm boot.inc
$(ALL_TARGETS): tgy.asm boot.inc ntc-table.inc
$(AUX_TARGETS): tgy.asm boot.inc ntc-table.inc

.inc.hex:
@test -e $*.asm || ln -s tgy.asm $*.asm
Expand All @@ -24,6 +24,9 @@ test: all
clean:
-rm -f $(ALL_TARGETS) *.cof *.obj *.eep.hex *.eeprom

ntc-table.inc: create-ntc-table.sh *.inc
./create-ntc-table.sh > $@

binary_zip: $(ALL_TARGETS)
TARGET="tgy_`date '+%Y-%m-%d'`_`git rev-parse --verify --short HEAD`"; \
mkdir "$$TARGET" && \
Expand Down
34 changes: 33 additions & 1 deletion afro_nfet.inc
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@
.equ USE_I2C = 1
.equ USE_UART = 1
.equ USE_ICP = 1
.equ USE_SLEEP = 2
.equ USE_LED_PWM = 3
.equ USE_ADC = 1

.equ DEAD_LOW_NS = 300
.equ DEAD_HIGH_NS = 300
Expand Down Expand Up @@ -37,7 +40,12 @@
; PORT C definitions *
;*********************
.equ mux_voltage = 7 ; ADC7 voltage input (18k from Vbat, 3.3k to gnd, 10.10V -> 1.565V at ADC7)
.equ mux_voltage_mul = (5*256*(18000+3300)/3300)
.equ mux_voltage_off = 0
.equ mux_temperature = 6 ; ADC6 temperature input (3.3k from +5V, 10k NTC to gnd)
.equ mux_temperature_rpullup = 3300
.equ mux_temperature_rntc = 10000
.equ mux_temperature_beta = 3950
.equ i2c_clk = 5 ; ADC5/SCL
.equ i2c_data = 4 ; ADC4/SDA
.equ red_led = 3 ; o
Expand All @@ -62,7 +70,7 @@
.ENDMACRO
.MACRO GRN_off
cbi DDRC, green_led
.ENDMACRO
.ENDMACRO

;*********************
; PORT D definitions *
Expand All @@ -83,3 +91,27 @@
.equ BnFET_port = PORTD
.equ CnFET_port = PORTD
.equ ApFET_port = PORTD

;*****************************************
; ENABLE_LOW_POWER_FET_MODE during sleep *
;*****************************************
.equ USE_FET_SET_LOW_POWER = 1
.equ USE_FET_RESET_LOW_POWER = 1

.MACRO FET_SET_LOW_POWER
cbi AnFET_port,AnFET
cbi BnFET_port,BnFET
cbi CnFET_port,CnFET
cbi ApFET_port,ApFET
cbi BpFET_port,BpFET
cbi CpFET_port,CpFET
.ENDMACRO

.MACRO FET_RESET_LOW_POWER
cbi AnFET_port,AnFET
cbi BnFET_port,BnFET
cbi CnFET_port,CnFET
sbi ApFET_port,ApFET
sbi BpFET_port,BpFET
sbi CpFET_port,CpFET
.ENDMACRO
56 changes: 56 additions & 0 deletions create-ntc-table.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
#! /bin/sh

RPULLUP_VALUES="`awk -F= '/^\.equ[ \t]*mux_temperature_rpullup/{C[$2]++}END{for(i in C){if(i!=0)printf "%i ",i;}}' *.inc`"
RNTC_VALUES="`awk -F= '/^\.equ[ \t]*mux_temperature_rntc[ \t]*=/{C[$2]++}END{for(i in C){if(i!=0)printf "%i ",i;}}' *.inc`"
BETA_VALUES="`awk -F= '/^\.equ[ \t]*mux_temperature_beta[ \t]*=/{C[$2]++}END{for(i in C){if(i!=0)printf "%i ",i;}}' *.inc`"

test -z "$1" || RPULLUP_VALUES=$1
test -z "$2" || RNTC_VALUES=$2
test -z "$3" || BETA_VALUES=$3

echo "; NTC thermal tables"
echo "; generated via script: $0"
echo ".if defined(mux_temperature_rpullup) && defined(mux_temperature_rntc) && defined(mux_temperature_beta)"
(
for R in $RPULLUP_VALUES; do
for T in $RNTC_VALUES; do
for B in $BETA_VALUES; do
echo "$R $T $B";
done
done
done
) | awk '
function printline(A,B) {
# scale and saturate
C=B*256;
if (C<-32768){ C=-32768; }
if (C>32767){ C=32767; }
TS=C/256;
if (C<0){C+=65536};
# and print
printf "\t.dw 0x%04x\t; ADC = %4i, Temp = %6.1fC\n", C, A, TS;
}
{
RPULLUP=$1;
RTHERMAL=$2;
BETA=$3;
printf ";----------------------------------------------------------------\n";
printf "; RPULLUP = %i, RTHERMAL = %i, BETA = %i\n", RPULLUP, RTHERMAL, BETA;
printf ".%sif (mux_temperature_rpullup == %i) && (mux_temperature_rntc == %i) && (mux_temperature_beta == %i)\n", PREFIX, RPULLUP, RTHERMAL, BETA;
PREFIX="else";
printline(0, -100*RPULLUP);
for(ADC=1;ADC<255;ADC++){
# handle both pullups/pulldowns
if (RPULLUP<0) {
X=-((255/(255-ADC))-1)*RPULLUP/RTHERMAL;
} else {
X=((255/ADC)-1)*RPULLUP/RTHERMAL;
}
# do the real calculation
ITK=log(X)/BETA + 1/(273.15+25);
T=1/ITK -273.15;
printline(ADC,T)
}
printline(255, 100*RPULLUP);
}
END{if (NR>0) {printf ".else\n\t.error \"No corresponding BETA, RPULLUP and RNTC values found - please recreate ntc-table.inc via make to reflect your changes to .inc\"\n.endif\n.endif\n";}}'
Loading