Permalink
Browse files

Fix register conflicts in tlc and tlcTest.S. Debug output on port D, …

…pin 6. Test program runs, but no output on TLC yet.
  • Loading branch information...
1 parent a2428d3 commit bb5f5848418a55ea5ef0291ce5a74a62bd9f7e9d @pilotniq pilotniq committed May 26, 2011
Showing with 59 additions and 38 deletions.
  1. +1 −1 config-erl.h
  2. +6 −6 main.S
  3. +6 −3 makefile
  4. +11 −1 reg_mnemonics.h
  5. +35 −27 tlc.S
View
@@ -38,7 +38,7 @@
;; 10-> 6, 9
;; 11-> 5, 9
-.equ NUMBER_TLC_CHIPS, 2
+.equ NUMBER_TLC_CHIPS, 1
.global NUMBER_TLC_CHIPS
.equ MINUTES_PER_STEP, 5
View
@@ -12,13 +12,13 @@
;; r6 = TLC SPI Byte type
;; r7 = scratch used in interrupt processing
;; r10 = channel # parameter to TLC_setChannelTargetIntensity
-;; r11: low byte of channel parameter
-;; r12: high byte of channel parameter
-;; r17 = minutes past hour
-;; r18 = hours (0-11)
-;; r19 = temp, can be overwritten by any function, but not overwritten
+;; N r11: low byte of channel parameter
+;; N r12: high byte of channel parameter
+;; I r17 = minutes past hour
+;; I r18 = hours (0-11)
+;; N r19 = temp, can be overwritten by any function, but not overwritten
;; in interrupt handlers
-;; r20 = string nybble address for setting
+;; r20 = scratch for interrupt handling
;; r21 = scratch for interrupt handling
;; r24:r25 = timer counter
;; r26:r27 X, used in TLC_setChannelTargetIntensity.
View
@@ -6,10 +6,13 @@ AS = avr-as
#ASFLAGS = -Wa,mmcu=atmega168
LD = avr-ld
LDFLAGS = -nostdlib
+# USBPORT = /dev/parport0
+USBPORT = /dev/tty.usbserial-A6008gHF
+AVRDUDE_PARAMS = -b 19200
main.o: main.S
-tlc.o: tlc.S
-tlcTest.o: tlcTest.S
+tlc.o: tlc.S config.h
+tlcTest.o: tlcTest.S config.h
tlcTest: tlcTest.o tlc.o
avr-ld -nostdlib tlcTest.o tlc.o -o tlcTest
@@ -24,7 +27,7 @@ tlcTest.hex: tlcTest
avr-objcopy -O ihex tlcTest tlcTest.hex
tlctest-flash: tlcTest.hex
- avrdude -c avrisp -p m168 -P /dev/ -U flash:w:tlcTest.hex
+ avrdude -c avrisp -p m168 -P $(USBPORT) $(AVRDUDE_PARAMS) -U flash:w:tlcTest.hex
flash: wordClock.hex
avrdude -c usbasp -p m168 -P /dev/parport0 -U flash:w:wordClock.hex
View
@@ -6,14 +6,24 @@
/* New data to send over SPI */
#define HAVE_NEW_DATA r3
/* 62.5Hz time counter */
-#define TICK_COUNTER r24
+#define REG_TICK_COUNTER r20
+#define REG_TICK_COUNTER_LOW r20
+#define REG_TICK_COUNTER_HIGH r21
/*
* Parameters to TLC functions
*/
#define REG_TLC_CHANNEL_NUMBER r10
#define REG_TLC_CHANNEL_INTENSITY_LOW r22
#define REG_TLC_CHANNEL_INTENSITY_HIGH r23
+#define REG_I_CHANNEL_INDEX r19
+/*
+ * Used in TLC SPI Timer interrupt for storing current LED value
+ * I in name stands for interrupt time variable
+ */
+#define REG_I_LED_CURRENT_LOW r24
+#define REG_I_LED_CURRENT_HIGH r25
+
#define XL r26
#define XH r27
#define YL r28
View
@@ -86,6 +86,8 @@ TLC_init:
;; then just blanks
cbi BLANK_PORT, BLANK_PIN
+ ;; Must initialize current and target to 0 here, unless RAM is 0
+ ;; by default
ret ; return from subrutine
;; Should send next byte if there is more data to be sent
@@ -216,33 +218,36 @@ TLC_spiTimerInterrupt:
;; save status byte
in r0, 0x3f
push r0
-
+ push XL
+ push XH
+
;; Check if any diffs are not zero
;; X = r26:r27 current value
;; Y = r28:r29 target value
- ldi r26, lo8( currentChannelValues )
- ldi r27, hi8( currentChannelValues )
+ ldi XL, lo8( currentChannelValues )
+ ldi XH, hi8( currentChannelValues )
- ldi r28, lo8( targetChannelValues )
- ldi r29, hi8( targetChannelValues )
+ ldi YL, lo8( targetChannelValues )
+ ldi YH, hi8( targetChannelValues )
- ldi r19, 2 * 16 * NUMBER_TLC_CHIPS
+ ldi REG_I_CHANNEL_INDEX, 2 * 16 * NUMBER_TLC_CHIPS
clr r9 ; R9 is change counter
checkDiffsLoop:
- ld TICK_COUNTER, Y+ ; Target Low byte
- ld r0, X+ ; Current Low byte
- sub TICK_COUNTER, r0 ; TICK_COUNTER = TICK_COUNTER - r0
+ /* Calculate target - current */
+ ld r0, Y+ ; r0=Target Low byte
+ ld REG_I_LED_CURRENT_LOW, X+ ; r0=Current Low byte
+ sub r0, REG_I_LED_CURRENT_LOW ; r0=lo8(target-current)
- ld r25, Y+ ; Target Low byte
- ld r0, X+ ; Current Low byte
- sbc r25, r0 ; r25 = r25 - r0. r7:r8=diff
+ ld r0, Y+ ; Target Low byte
+ ld REG_I_LED_CURRENT_HIGH, X+ ; Current High byte
+ sbc r0, REG_I_LED_CURRENT_HIGH ; r25 = r25 - r0. r7:r8=diff
brne modify
doneModifying:
- dec r19
+ dec REG_I_CHANNEL_INDEX
brne checkDiffsLoop
rjmp allUpdated
@@ -254,25 +259,26 @@ modify:
brmi decrease
inc r9
- sbiw r26, 2 ; r26=X Move x ptr back to value we just compared
- adiw TICK_COUNTER, 1
- st X+, TICK_COUNTER
- st X+, r25
+ sbiw XL, 2 ; r26=X Move x ptr back to value we just compared
+ adiw REG_I_LED_CURRENT_LOW, 1
+ st X+, REG_I_LED_CURRENT_LOW
+ st X+, REG_I_LED_CURRENT_HIGH
rjmp doneModifying
decrease:
inc r9
- sbiw r26, 2 ; Move x ptr back to value we just compared
- sbiw TICK_COUNTER, 1
- st X+, TICK_COUNTER
- st X+, r25
+ sbiw XL, 2 ; Move x ptr back to value we just compared
+ sbiw REG_I_LED_CURRENT_LOW, 1
+ st X+, REG_I_LED_CURRENT_LOW
+ st X+, REG_I_LED_CURRENT_HIGH
rjmp doneModifying
allUpdated:
tst r9
breq allDiffsZero
+
rjmp startSending
allDiffsZero:
@@ -287,19 +293,21 @@ allDiffsZero:
startSending:
dec r3 ; decrement counter of times to write
- ldi r30, lo8(currentChannelValues)
- ldi r31, hi8(currentChannelValues)
+ ldi ZL, lo8(currentChannelValues)
+ ldi ZH, hi8(currentChannelValues)
- ldi r19, 16 * NUMBER_TLC_CHIPS
- mov SPI_CHINDEX, r19
+ ldi REG_I_CHANNEL_INDEX, 16 * NUMBER_TLC_CHIPS
+ mov SPI_CHINDEX, REG_I_CHANNEL_INDEX
- ldi r19, 1 ; Byte Type
- mov r4, r19
+ ldi REG_I_CHANNEL_INDEX, 1 ; Byte Type
+ mov r4, REG_I_CHANNEL_INDEX
lpm r0, Z
out SPDR, r0 ; Initiates transmission
returnFromInterrupt:
+ pop XH
+ pop XL
;; restore status register
pop r0
out 0x3f, r0

0 comments on commit bb5f584

Please sign in to comment.