From a83c3cfeb35ae6bd308cb0ce17af1e510de6e476 Mon Sep 17 00:00:00 2001 From: Selene ToyKeeper Date: Sat, 10 Oct 2015 00:15:01 -0600 Subject: Made a simple program to blink out temperature measurements. Added some basic temperature stuff to header files. --- tk-attiny.h | 3 +++ tk-voltage.h | 14 ++++++++++++++ 2 files changed, 17 insertions(+) diff --git a/tk-attiny.h b/tk-attiny.h index 4fee640..6390416 100644 --- a/tk-attiny.h +++ b/tk-attiny.h @@ -70,6 +70,9 @@ #define ADC_DIDR ADC1D // Digital input disable bit corresponding with PB2 #define ADC_PRSCL 0x06 // clk/64 +//#define TEMP_DIDR ADC4D +#define TEMP_CHANNEL 0b00001111 + #endif // FET_7135_LAYOUT #ifdef FERRERO_ROCHER_LAYOUT diff --git a/tk-voltage.h b/tk-voltage.h index 5eaf0d4..8421ef3 100644 --- a/tk-voltage.h +++ b/tk-voltage.h @@ -23,6 +23,20 @@ #include "tk-attiny.h" #include "tk-calibration.h" +#ifdef TEMPERATURE_MON +inline void ADC_on_temperature() { + // TODO: (?) enable ADC Noise Reduction Mode, Section 17.7 on page 128 + // (apparently can only read while the CPU is in idle mode though) + // select ADC4 by writing 0b00001111 to ADMUX + // 1.1v reference, left-adjust, ADC4 + ADMUX = (1 << V_REF) | (1 << ADLAR) | TEMP_CHANNEL; + // disable digital input on ADC pin to reduce power consumption + //DIDR0 |= (1 << TEMP_DIDR); + // enable, start, prescale + ADCSRA = (1 << ADEN ) | (1 << ADSC ) | ADC_PRSCL; +} +#endif // TEMPERATURE_MON + #ifdef VOLTAGE_MON inline void ADC_on() { // disable digital input on ADC pin to reduce power consumption -- cgit v1.2.3 From 2e98cc7eed993f6d65ca5d57f358ffc8cb86c21c Mon Sep 17 00:00:00 2001 From: Selene ToyKeeper Date: Mon, 12 Oct 2015 22:22:28 -0600 Subject: Oops, forgot to add tk-random header. --- tk-random.h | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) create mode 100644 tk-random.h diff --git a/tk-random.h b/tk-random.h new file mode 100644 index 0000000..db6c939 --- /dev/null +++ b/tk-random.h @@ -0,0 +1,28 @@ +#ifndef TK_RANDOM_H +#define TK_RANDOM_H +/* + * Smaller, pseudo-random function(s). + * + * Copyright (C) 2015 Selene ToyKeeper + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + * + */ + +uint8_t pgm_rand() { + static uint8_t *offset = 0; + return pgm_read_byte(offset++); +} + +#endif // TK_RANDOM_H -- cgit v1.2.3 From e9bfbbbe4d4853d127019260fafc2620b13f3a1f Mon Sep 17 00:00:00 2001 From: Selene ToyKeeper Date: Mon, 12 Oct 2015 22:45:04 -0600 Subject: Made pgm_rand() more erratic (beginning of PROGMEM is boring for this purpose), made random strobe smaller and better-looking. --- tk-random.h | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/tk-random.h b/tk-random.h index db6c939..d559659 100644 --- a/tk-random.h +++ b/tk-random.h @@ -21,8 +21,9 @@ */ uint8_t pgm_rand() { - static uint8_t *offset = 0; - return pgm_read_byte(offset++); + static uint16_t offset = 255; + offset = (offset + 1) & 0x3ff | 0x0100; + return pgm_read_byte(offset); } #endif // TK_RANDOM_H -- cgit v1.2.3 From b26ab711ec9c8da79575a26ace75f73109d3afb7 Mon Sep 17 00:00:00 2001 From: Selene ToyKeeper Date: Sun, 18 Oct 2015 16:42:17 -0600 Subject: Removed the need to specify header file paths. Makes it easier to put all the files into one dir for building outside the repository. --- bin/build-25.sh | 2 +- bin/build.sh | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/bin/build-25.sh b/bin/build-25.sh index 9a3de00..618b94a 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" +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' diff --git a/bin/build.sh b/bin/build.sh index 935310a..0d53b57 100755 --- a/bin/build.sh +++ b/bin/build.sh @@ -8,7 +8,7 @@ export ATTINY=13 export MCU=attiny$ATTINY export CC=avr-gcc export OBJCOPY=avr-objcopy -export CFLAGS="-Wall -g -Os -mmcu=$MCU -c -std=gnu99 -DATTINY=$ATTINY" +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' -- cgit v1.2.3