Monday, December 19, 2011

ATTiny

As seen in

The displayed value was within the acceptable margin of error for the program. See the below screencaps of the oscilloscope to verify the measurements.

This

Shows the output of the LED's

The output is ask requested in Binary Coded Decimal, with the left 3 LED's displaying the 10's digit of a decimal number in binary and the right 4 LED's displaying the ones digit in binary. A lit LED is a 1.

Unfortunately, due to technical difficulties near the deadline, contiguous video showing the programming, oscilloscope, and lights is not available.

The program calculates the temperature by polling for 1's until the voltage drops to 0, then polling 0's until the voltage rises again. It then uses the formula 235-((400*T1)\T2) with T1 being the number of 1's polled and T2 being 0's. This effectively measures the relative amounts of time that the signal is high and low(1 and 0 respectively).

Using interrupts would likely prove to be more accurate, but due to time constraints, that method was not explored.

Sunday, December 18, 2011

ATTiny.asm

.include "tn2313def.inc"


; Variable Allocations
.def temp = R16
.def mask = R19
.def tmpc = R20

.def ones = R22
.def tens = R23


; zeros in [XH:XL]
; ones in [YH;YL]
; Total in [ZH,ZL]
; These are R27, R26, R29,R28, R31, and R30 respectively. don't use these registers for anything
;else


;********* INIT
; WARNING:: This overlaps the IVT
start: ldi mask,0b11110111 ; [UUUUIOOO]
out DDRB,mask ; port B set up
ldi mask,0b11111111 ; [UUOOOOUU]
out DDRD,mask ; port D set up
ldi mask,0b00001000 ; [UUOOOOUU]
out PORTB,mask ; port D set up



;******** STATE0
state0: ldi XH,0x00 ; ones <-- 1*25 ldi XL,0x19 ldi YH,0x00 ; zeros <-- 1 ldi YL,0x01 whl00: in temp,PINB ; block until 1 ldi mask,0b00001000 and temp,mask breq whl00 ;******** STATE1 :: COUNT THE NUMBER OF ONES whl10: adiw XL,0x0019 ; ONES <- ONES + 25 (Ones * 25) ldi temp,1 ;Delay(smaller is better) d10: nop dec temp brne d10 in temp,PINB ; block until 0 ldi mask,0b00001000 and temp,mask brne whl10 ;******** STATE2 :: COUNT THE NUMBER OF ZER0S whl01: adiw YL,0x0001 ; zeros <- zeros + 1 ldi temp,1 ;Delay(smaller is better) d01: nop dec temp brne d01 in temp,PINB ; block until 1 ldi mask,0b00001000 and temp,mask breq whl01 ;********* STATE 3 :: Calculations ; Shift down YL (the number of zeros/16) clc ror YH ror YL clc ror YH ror YL clc ror YH ror YL clc ror YH ror YL ; Now loop until Z equals [XH,XL] clr ZL clr ZH ldi tmpc,235 ldi mask, 0 RES: add ZL,YL ; calculates the temperature from the ratio of 1's to 0's adc ZH, mask dec tmpc cp ZH,XH brlo RES cp ZL,XL brlo RES ; CONVERT TEMP VALUE TO BCD mov ones,tmpc ;copies tmpc into ones(ones will be actively ;decremented) ldi tens, 0b00000000 ;initializes value of tens to 0 ldi R17, 0x0001 ;creates register 17 with value of 1 ldi R18, 0x000A ;creates register 18 with value of 10 BCD: add tens, R17 ;increments tens by 1 sub ones, R18 ;decrement ones by 10 to account for tens ;incremented cp ones, R18 ;compares ones to register 18 (10) for branch brsh BCD ;if ones >= 10, returns to BCD to repeat
;increment/decrement until ones<10


com tens ;stores the ones complement of tens in tens
out PORTB, tens ;output tens to port b

; OUTPUT THE ONES TO PORT D
com ones
lsl ones ;logical shift ones left 1
lsl ones ;and again This adjusts for the number of LED's
;being different than the number of bits
out PORTD, ones

;********* STATE 4 :: WAIT FOR A ZERO to start again
whl11: in temp,PINB ; block until 0
ldi mask,0b00001000
and temp,mask
brne whl11

rjmp state0

ATTiny



Adding 4 numbers with the Edsac


Adding 4 numbers with the EDSAC

That's the program, it's been so long I honestly don't remember exactly what everything does, I don't think I ever figured it out entirely anyway, but it works and the parts that I know that they do are commented.

Adding 4 numbers with the EDSAC

[Add 13+20+25+11]
[31]T123S
[32]E84S
[33]PS
[34]PS
[35]P10000S
[36]P1000S
[37]P100S
[38]P10S
[39]P1S
[40]QS
[41]#S
[42]A40S
[43]!S
[44]&S
[45]@S
[46]O43S
[47]O33S
[48]PS
[49]A46S
[50]T65S
[51]T129S
[52]A35S
[53]T34S
[54]E61S
[55]T48S
[56]A47S
[57]T65S
[58]A33S
[59]A40S
[60]T33S
[61]A48S
[62]S34S
[63]E55S
[64]A34S
[65]PS
[66]T48S
[67]T33S
[68]A52S
[69]A4S
[70]U52S
[71]S42S
[72]G51S
[73]A117S
[74]T52S
[75]P13S [store 13]
[76]P20S [store 20]
[77]P25S [store 25]
[78]P24S [store 24]
[79]PS
[80]E110S
[81]E118S
[82]P100S
[83]E95S
[84]O41S
[85]T129S
[86]O44S
[87]O45S
[88]A76S [Adds line 76 to line 75]
[89]A77S [Adds line 77]
[90]A78S [Adds line 78]
[91]A79S [Adds line 79]
[92]T48S
[93]A83S
[94]T75S [prints value at 75(69)]
[95]E49S
[96]ZS
[97]043S
[98]H76S
[99]V76S
[100]L64S
[101]L32S
[102]U77S
[103]S78S
[104]T79S
[105]A77S
[106]U78S
[107]T48S
[108]A80S
[109]T75S
[110]E49S
[111]O43S
[112]O43S
[113]A79S
[114]T48S
[115]A81S
[116]T75S
[117]E49S
[118]A35S
[119]A76S
[120]S82S
[121]G85S
[122]O41S
[123]ZS