]> localhost Git - chickenFan.git/commitdiff
Tested to work. master origin/HEAD origin/master 1.0
authorMichael McMaster <michael@codesrc.com>
Wed, 14 Nov 2012 11:11:32 +0000 (21:11 +1000)
committerMichael McMaster <michael@codesrc.com>
Wed, 14 Nov 2012 11:11:32 +0000 (21:11 +1000)
Finished.

BOM.ods [new file with mode: 0644]
Makefile
chickenFan.c
chickenFan.hex

diff --git a/BOM.ods b/BOM.ods
new file mode 100644 (file)
index 0000000..e3d5fbd
Binary files /dev/null and b/BOM.ods differ
index 36c577b25a7036e94dd1ed1efeb7442647c1073a..999e6c66e63e692bc10a8a9e7ba7e76104cd8ce8 100644 (file)
--- a/Makefile
+++ b/Makefile
@@ -23,8 +23,8 @@ chickenFan.elf: chickenFan.c
        avr-gcc -Wall -Os -std=c99 -mmcu=attiny25 $^ -o $@
 
 # Use with arduinoisp example sketch. See http://hlt.media.mit.edu/?p=1706
        avr-gcc -Wall -Os -std=c99 -mmcu=attiny25 $^ -o $@
 
 # Use with arduinoisp example sketch. See http://hlt.media.mit.edu/?p=1706
-.PHONY: program
-program: chickenFan.hex
+.PHONY: burn
+burn: chickenFan.hex
        avrdude -P /dev/ttyUSB0 -b 19200 -c avrisp -p t25 -v -e -U flash:w:chickenFan.hex
 
 .PHONY: clean
        avrdude -P /dev/ttyUSB0 -b 19200 -c avrisp -p t25 -v -e -U flash:w:chickenFan.hex
 
 .PHONY: clean
index 2cb98ac9a950553d37f2984a02116f7227f0955d..9a20904f2b022f4b33796d4c478d71c34be9e3e0 100644 (file)
@@ -32,6 +32,7 @@
 //             required for avr-libc delay functions.
 //
 // avr-libc: tested with 1.8.0
 //             required for avr-libc delay functions.
 //
 // avr-libc: tested with 1.8.0
+//
 
 // 1 MHz internal oscillator. Assumes default fuse settings.
 #define F_CPU 1000000UL
 
 // 1 MHz internal oscillator. Assumes default fuse settings.
 #define F_CPU 1000000UL
 
 #define SETBIT(port, bitnum) port |= _BV(bitnum)
 #define CLRBIT(port, bitnum) port &= (uint8_t) ~_BV(bitnum)
 
 #define SETBIT(port, bitnum) port |= _BV(bitnum)
 #define CLRBIT(port, bitnum) port &= (uint8_t) ~_BV(bitnum)
-#define READBIT(port, bitnum) (!!(port & _BV(bitnum)))
+#define READBIT(port, bitnum) (port & (_BV(bitnum)))
 
 
 // One-Wire active-low protocol
 #define ONEWIRE_PIN PB0
 
 
 // One-Wire active-low protocol
 #define ONEWIRE_PIN PB0
-#define ONEWIRE_LOW() {SETBIT(DDRB, ONEWIRE_PIN); CLRBIT(PORTB, ONEWIRE_PIN); }
-#define ONEWIRE_HI() CLRBIT(DDRB, ONEWIRE_PIN)
+#define ONEWIRE_LOW() SETBIT(DDRB, ONEWIRE_PIN);
+#define ONEWIRE_HI() CLRBIT(DDRB, ONEWIRE_PIN);
 #define ONEWIRE_READ() READBIT(PINB, ONEWIRE_PIN)
 
 static void oneWireInit()
 #define ONEWIRE_READ() READBIT(PINB, ONEWIRE_PIN)
 
 static void oneWireInit()
@@ -69,6 +70,9 @@ static void oneWireInit()
                // Ok, we're -supposed- to check that the slave device
                // also pulls the line low, but we just assume it will
                // and wait until it has finished.
                // Ok, we're -supposed- to check that the slave device
                // also pulls the line low, but we just assume it will
                // and wait until it has finished.
+
+               // Tests with a CRO show the DS18B20 holding the line low
+               // for 100us. (datasheet says 60-240us)
        }
        _delay_us(480);
 }
        }
        _delay_us(480);
 }
@@ -78,21 +82,21 @@ static void oneWireWrite(uint8_t value)
        // LSB first, active low
        for (int i = 0; i < 8; ++i)
        {
        // LSB first, active low
        for (int i = 0; i < 8; ++i)
        {
-               ONEWIRE_LOW();
-
                if (value & _BV(i))
                {
                if (value & _BV(i))
                {
-                       // Min 1uS delay taken care of by ifcondition.
-                       // Don't tempt fate by waiting too long.
-
+                       ONEWIRE_LOW();
                        ONEWIRE_HI();
                        _delay_us(60);
                }
                else
                {
                        ONEWIRE_HI();
                        _delay_us(60);
                }
                else
                {
+                       ONEWIRE_LOW();
                        _delay_us(60);
                        ONEWIRE_HI();
                        _delay_us(60);
                        ONEWIRE_HI();
+                       // Ensure the weak pullup has time to work
+                       _delay_us(4);
                }
                }
+
                _NOP(); // 1uS recovery time. Probably not needed.
        }
 }
                _NOP(); // 1uS recovery time. Probably not needed.
        }
 }
@@ -106,14 +110,21 @@ static uint8_t oneWireReadBit()
        // we need to read it towards the END of that 15uS
        // period.
 
        // we need to read it towards the END of that 15uS
        // period.
 
-       ONEWIRE_LOW(); // Up to 4 cycles ?
-       _NOP(); // Ensure we wait 1us
+       ONEWIRE_LOW(); //2 cycles
        ONEWIRE_HI(); // 2 cycles
        ONEWIRE_HI(); // 2 cycles
+
+       // We -start- going high 5 cycles after going low.
+       // 2.5V ~ 2ms later. 5V ~ 4ms later.
+       // Need to leave sufficient time for the weak 10k pullup
+       // to raise the bus or else we'll read 0 instead of 1,
+       // but still sample early enough before the time slot
+       // runs out.
+       _NOP();
+       _NOP();
        _NOP();
        _NOP();
        _NOP();
        _NOP();
        _NOP();
        _NOP();
        _NOP();
        _NOP();
-       _NOP(); // Up to 12 cycles since the pin went low.
        uint8_t bit = ONEWIRE_READ(); // 2 cycles for I/O access?
 
        _delay_us(60); // Ensure we wait out the rest of the read slot.
        uint8_t bit = ONEWIRE_READ(); // 2 cycles for I/O access?
 
        _delay_us(60); // Ensure we wait out the rest of the read slot.
@@ -121,13 +132,18 @@ static uint8_t oneWireReadBit()
        return bit;
 }
 
        return bit;
 }
 
-static uint8_t oneWireRead()
+uint8_t oneWireRead()
 {
        uint8_t result = 0;
 {
        uint8_t result = 0;
+       uint8_t mask = 1;
        // LSB first, active low
        // LSB first, active low
-       for (int i = 0; i < 8; ++ i)
+       for (uint8_t i = 0; i < 8; ++i)
        {
        {
-               result |= oneWireReadBit() << i;
+               if (oneWireReadBit())
+               {
+                       result |= mask;
+               }
+               mask <<= 1;
        }
        return result;
 }
        }
        return result;
 }
index 02c9f9d623300449e8449343ae087ccef6fdc6a2..b36c2625161c31bc1f54869ef2b080558cb72743 100644 (file)
@@ -1,20 +1,19 @@
 :100000000EC013C012C011C010C00FC00EC00DC072\r
 :100010000CC00BC00AC009C008C007C006C011242C\r
 :100000000EC013C012C011C010C00FC00EC00DC072\r
 :100010000CC00BC00AC009C008C007C006C011242C\r
-:100020001FBECFEDCDBF3CD07DC0EACFB89AC098FF\r
-:1000300080EA8A95F1F7B8980000B099FECF80EA7F\r
-:100040008A95F1F7089520E030E090E0B89AC098E2\r
-:10005000AC01022E02C0559547950A94E2F740FF85\r
-:1000600005C0B89844E14A95F1F704C044E14A95C7\r
-:10007000F1F7B89800002F5F3F4F2830310531F776\r
-:100080000895B89AC0980000B898000000000000D9\r
-:100090000000000086B394E19A95F1F7817008950D\r
-:1000A000BC9AC498C3DF8CECCEDF84E4CCDFE9DFFC\r
-:1000B0008823E9F3BBDF8CECC6DF8EEBC4DFC0E046\r
-:1000C000D0E010E0DEDF0C2E01C0880F0A94EAF7C2\r
-:1000D000182B2196C830D105A9F7C0E0D0E000E088\r
-:1000E000D0DF0C2E01C0880F0A94EAF7082B219666\r
-:1000F000C830D105A9F7802F8295807F12951F7097\r
-:10010000812B893114F0C49A03C0883109F0C49856\r
-:100110008FE79AE126E0815090402040E1F700C04F\r
-:080120000000C0CFF894FFCFEE\r
+:100020001FBECFEDCDBF4CD073C0EACFB89A80EAE7\r
+:100030008A95F1F7B8980000B099FECF80EA8A95CA\r
+:10004000F1F7089520E030E090E0AC01022E02C00C\r
+:10005000559547950A94E2F7B89A40FF05C0B898BD\r
+:1000600044E14A95F1F706C044E14A95F1F7B898A2\r
+:1000700000C000C000002F5F3F4F2830310529F736\r
+:100080000895B89AB8980000000000000000000031\r
+:10009000000086B394E19A95F1F7817008951F935B\r
+:1000A000CF93DF93D8E011E0C0E0EBDF8111C12BEB\r
+:1000B000110FD150D1F78C2FDF91CF911F9108955F\r
+:1000C000BC9AC498B3DF8CECBDDF84E4BBDFD9DF1E\r
+:1000D0008823E9F3ABDF8CECB5DF8EEBB3DFDFDF3A\r
+:1000E000C82FDDDF8295807FC295CF708C2B893140\r
+:1000F00014F0C49A03C0883109F0C4982FE78AE14C\r
+:1001000096E0215080409040E1F700C00000DACF37\r
+:04011000F894FFCF91\r
 :00000001FF\r
 :00000001FF\r