aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--README5
-rwxr-xr-xbin/build-25.sh2
-rwxr-xr-xbin/build-85.sh26
-rwxr-xr-xbin/flash-85.sh4
-rw-r--r--tk-attiny.h16
-rw-r--r--tk-calibration.h48
-rw-r--r--tk-delay.h7
-rw-r--r--tk-random.h5
8 files changed, 82 insertions, 31 deletions
diff --git a/README b/README
index 3612013..27a8c00 100644
--- a/README
+++ b/README
@@ -37,6 +37,11 @@ For Windows users, these links may be useful:
http://budgetlightforum.com/node/29684
+ Getting a USBasp to work in Windows:
+
+ http://rayshobby.net/dead-simple-driver-installation-for-usbasp-and-usbtiny-on-windows/
+ http://www.protostack.com/accessories/usbasp-avr-programmer
+
To set up an attiny dev environment on Ubuntu (13.10):
sudo apt-get install flex byacc bison gcc libusb-dev libc6-dev
diff --git a/bin/build-25.sh b/bin/build-25.sh
index 618b94a..2c58db5 100755
--- a/bin/build-25.sh
+++ b/bin/build-25.sh
@@ -8,7 +8,7 @@ export ATTINY=25
export MCU=attiny$ATTINY
export CC=avr-gcc
export OBJCOPY=avr-objcopy
-export CFLAGS="-Wall -g -Os -mmcu=$MCU -c -std=gnu99 -DATTINY=$ATTINY -I.."
+export CFLAGS="-Wall -g -Os -mmcu=$MCU -c -std=gnu99 -DATTINY=$ATTINY -I.. -I../.. -I../../.."
export OFLAGS="-Wall -g -Os -mmcu=$MCU"
export LDFLAGS=
export OBJCOPYFLAGS='--set-section-flags=.eeprom=alloc,load --change-section-lma .eeprom=0 --no-change-warnings -O ihex'
diff --git a/bin/build-85.sh b/bin/build-85.sh
new file mode 100755
index 0000000..14a3da4
--- /dev/null
+++ b/bin/build-85.sh
@@ -0,0 +1,26 @@
+#!/bin/bash
+
+# Instead of using a Makefile, since most of the firmwares here build in the
+# same exact way, here's a script to do the same thing
+
+export PROGRAM=$1
+export ATTINY=85
+export MCU=attiny$ATTINY
+export CC=avr-gcc
+export OBJCOPY=avr-objcopy
+export CFLAGS="-Wall -g -Os -mmcu=$MCU -c -std=gnu99 -DATTINY=$ATTINY -I.."
+export OFLAGS="-Wall -g -Os -mmcu=$MCU"
+export LDFLAGS=
+export OBJCOPYFLAGS='--set-section-flags=.eeprom=alloc,load --change-section-lma .eeprom=0 --no-change-warnings -O ihex'
+export OBJS=$PROGRAM.o
+
+function run () {
+ echo $*
+ $*
+ if [ x"$?" != x0 ]; then exit 1 ; fi
+}
+
+run $CC $CFLAGS -o $PROGRAM.o -c $PROGRAM.c
+run $CC $OFLAGS $LDFLAGS -o $PROGRAM.elf $PROGRAM.o
+run $OBJCOPY $OBJCOPYFLAGS $PROGRAM.elf $PROGRAM.hex
+run avr-size -C --mcu=$MCU $PROGRAM.elf | grep Full
diff --git a/bin/flash-85.sh b/bin/flash-85.sh
new file mode 100755
index 0000000..1434b7d
--- /dev/null
+++ b/bin/flash-85.sh
@@ -0,0 +1,4 @@
+#/bin/sh
+FIRMWARE=$1
+avrdude -c usbasp -p t85 -u -U lfuse:w:0xe2:m -U hfuse:w:0xde:m -U efuse:w:0xff:m -Uflash:w:$FIRMWARE
+# http://www.engbedded.com/cgi-bin/fcx.cgi?P_PREV=ATtiny85&P=ATtiny85&M_LOW_0x3F=0x22&M_HIGH_0x07=0x06&M_HIGH_0x20=0x00&B_SPIEN=P&B_SUT0=P&B_CKSEL3=P&B_CKSEL2=P&B_CKSEL0=P&B_BODLEVEL0=P&V_LOW=E2&V_HIGH=DE&V_EXTENDED=FF
diff --git a/tk-attiny.h b/tk-attiny.h
index 4058fea..72ed2f0 100644
--- a/tk-attiny.h
+++ b/tk-attiny.h
@@ -36,7 +36,7 @@
#define F_CPU 8000000UL
#define EEPSIZE 128
#define V_REF REFS1
- #define BOGOMIPS (F_CPU/3200)
+ #define BOGOMIPS (F_CPU/4000)
#else
Hey, you need to define ATTINY.
#endif
@@ -73,6 +73,9 @@
//#define TEMP_DIDR ADC4D
#define TEMP_CHANNEL 0b00001111
+#define FAST 0xA3 // fast PWM both channels
+#define PHASE 0xA1 // phase-correct PWM both channels
+
#endif // FET_7135_LAYOUT
#ifdef TRIPLEDOWN_LAYOUT
@@ -106,7 +109,10 @@
//#define TEMP_DIDR ADC4D
#define TEMP_CHANNEL 0b00001111
-#endif // FET_7135_LAYOUT
+#define FAST 0xA3 // fast PWM both channels
+#define PHASE 0xA1 // phase-correct PWM both channels
+
+#endif // TRIPLEDOWN_LAYOUT
#ifdef FERRERO_ROCHER_LAYOUT
/*
@@ -118,6 +124,8 @@
* ----
*/
// TODO: fill in this section, update Ferrero_Rocher code to use it.
+#define FAST 0x23 // fast PWM channel 1 only
+#define PHASE 0x21 // phase-correct PWM channel 1 only
#endif // FERRERO_ROCHER_LAYOUT
#ifdef NANJG_LAYOUT
@@ -131,6 +139,10 @@
#define ADC_PRSCL 0x06 // clk/64
#define PWM_LVL OCR0B // OCR0B is the output compare register for PB1
+
+#define FAST 0x23 // fast PWM channel 1 only
+#define PHASE 0x21 // phase-correct PWM channel 1 only
+
#endif // NANJG_LAYOUT
#ifndef PWM_LVL
diff --git a/tk-calibration.h b/tk-calibration.h
index 617c809..c2ab801 100644
--- a/tk-calibration.h
+++ b/tk-calibration.h
@@ -25,31 +25,31 @@
// These values were measured using RMM's FET+7135.
// See battcheck/readings.txt for reference values.
// the ADC values we expect for specific voltages
-#define ADC_44 192
-#define ADC_43 188
+#define ADC_44 194
+#define ADC_43 189
#define ADC_42 184
-#define ADC_41 179
-#define ADC_40 175
-#define ADC_39 171
-#define ADC_38 167
-#define ADC_37 162
-#define ADC_36 158
-#define ADC_35 154
-#define ADC_34 150
-#define ADC_33 145
-#define ADC_32 141
-#define ADC_31 137
-#define ADC_30 133
-#define ADC_29 129
-#define ADC_28 124
-#define ADC_27 120
-#define ADC_26 116
-#define ADC_25 112
-#define ADC_24 107
-#define ADC_23 103
-#define ADC_22 99
-#define ADC_21 95
-#define ADC_20 91
+#define ADC_41 178
+#define ADC_40 173
+#define ADC_39 168
+#define ADC_38 163
+#define ADC_37 158
+#define ADC_36 152
+#define ADC_35 147
+#define ADC_34 142
+#define ADC_33 137
+#define ADC_32 131
+#define ADC_31 126
+#define ADC_30 121
+#define ADC_29 116
+#define ADC_28 111
+#define ADC_27 105
+#define ADC_26 100
+#define ADC_25 95
+#define ADC_24 90
+#define ADC_23 84
+#define ADC_22 79
+#define ADC_21 74
+#define ADC_20 69
#define ADC_100p ADC_42 // the ADC value for 100% full (resting)
#define ADC_75p ADC_40 // the ADC value for 75% full (resting)
diff --git a/tk-delay.h b/tk-delay.h
index e62aa4c..78cb188 100644
--- a/tk-delay.h
+++ b/tk-delay.h
@@ -53,11 +53,12 @@ void _delay_4ms(uint8_t n) // because it saves a bit of ROM space to do it this
#ifdef USE_DELAY_S
void _delay_s() // because it saves a bit of ROM space to do it this way
{
- #ifdef USE_DELAY_MS
- _delay_ms(1000);
- #endif
#ifdef USE_DELAY_4MS
_delay_4ms(250);
+ #else
+ #ifdef USE_DELAY_MS
+ _delay_ms(1000);
+ #endif
#endif
}
#endif
diff --git a/tk-random.h b/tk-random.h
index d559659..b2ff296 100644
--- a/tk-random.h
+++ b/tk-random.h
@@ -22,7 +22,10 @@
uint8_t pgm_rand() {
static uint16_t offset = 255;
- offset = (offset + 1) & 0x3ff | 0x0100;
+ // loop through ROM space, but avoid the first 256 bytes
+ // because the beginning tends to have a big ramp which
+ // doesn't look very random at all
+ offset = ((offset + 1) & 0x3ff) | 0x0100;
return pgm_read_byte(offset);
}