Forum: Mikrocontroller und Digitale Elektronik ASM Anpassen an Attiny 2313


von Michael W. (schumi)


Lesenswert?

Tach'chen

Habe eine Frage bzgl. des At90s2313 bzw. Attiny2313.

Und zwar habe ich hier eine Schaltung liegen die eigentlich mit einem 
At90s2313 und einem externen 8 MHZ Quarz betrieben wird, hat immer super 
funktioniert.

DAs ganze ist ein Interface welches aus meiner Modellflug Fernbedienung 
(PPM) ein Joystick signal für meinen Gameport macht

Ok dachte ich mir und besorgte mir den Attiny 2313 da dieser als 
Nachfolger ja abwärtskompatibel mit dem At90s2313 sein soll. Habe 
(T)WinAVR von www.rowalt.de womit ich auch den At90s2313 immer 
beschrieben habe. Twin-Avr erkennt & beschreibt den Attiny2313 auch mit 
dem HEX file vom At90s2313. Nach dem Brennen kommt die Fehlermeldung :

"Not enough space to store the calibration byte(s) in EEprom. 
Programming user Data to flash an EEprom sucessfull "

Wenn ich nach dem Brennen den Atiny dann in die Schaltung Stecke 
funktioniert diese danach erwartungsgemäß nicht damit.

Hat evtl jemand lust mir das ganze wieder lauffähig zu bekommen, bzw. 
einen Tip zugeben wie ich es hinbekomme??

Hier nochmal das ASM:



;*********************************************************************** 
****
;* Autor: Vitaly Putin
;* Title:  RC 2 Joy
;* Version:  1.0.3.1
;* Last updated: 01.05.2003
;* Target: Atmel AVR  AT90S2313
;*
;*
;*
;*********************************************************************** 
****

.include "2313def.inc"

    ; Max joystick pulse length = 2000 mks
.equ Startpulselen = 3000 ; Min Start Pulse Length , Mks
.equ Pulsemiddle = 1500 ; Channel Pulse Middle , Mks
;.equ MinPulseLen   = 700 ; Min channel pulse length, mks
;.equ ChDiv         = 3 ; Channel data div
    ; Other useful settings :
.equ Minpulselen = 850 ; Min Channel Pulse Length , Mks
.equ Chdiv = 2 ; Channel Data Div

.equ X1 = 1 ; Joystick Output Pins Masks
.equ Y1 = 2
.equ X2 = 4
.equ Y2 = 8

.equ Button1 = 0b00000100 ; Button 1 Pin Mask
.equ Button2 = 0b00001000 ; Button 2 Pin Mask
.equ Button3 = 0b00010000 ; Button 3 Pin Mask
.equ Button4 = 0b01000000 ; Button 4 Pin Mask

.equ Channels = $60 ; Channel Data Store Here

;***** Global Register Variables

.def Tmr1_templ = R3
.def Tmr1_temph = R4
.def Icr1_templ = R5
.def Icr1_temph = R6

.def Ch1tmpl = R16 ; Channel 1 - Low Byte
.def Ch1tmph = R17 ; Channel 1 - High Byte
.def Ch2tmpl = R18 ; Channel 2 - Low Byte
.def Ch2tmph = R19 ; Channel 2 - High Byte
.def Ch3tmpl = R20 ; Channel 3 - Low Byte
.def Ch3tmph = R21 ; Channel 3 - High Byte
.def Ch4tmpl = R22 ; Channel 4 - Low Byte
.def Ch4tmph = R23 ; Channel 4 - High Byte

.def Temp = R24 ; Temporary Storage Register

.def Ch_state = R30 ; Channels Output State Temporarily Store
.def Div = R31 ;

;*************************

.listmac
.macro Testchannel ; 4 Cycles
 Sub @0 , Div
 sbci @1, 0
 brge PC+2
 cbr ch_state, @2
.endm

.macro Checkbuttons
 ldd temp, Y+(2*(@0-1))
 subi temp, low(PulseMiddle)
 ldd temp, Y+(2*(@0-1))+1
 sbci temp, high(PulseMiddle)
 brlo PC+2
 sbr ch_state, @1
.endm

.macro Directchannel
 ldd @0, Y+(2*(@2-1))
 ldd @1, Y+(2*(@2-1))+1
 subi @0, LOW(MinPulseLen)
 sbci @1, HIGH(MinPulseLen)
.endm

.macro Reversechannel
 ldd @0, Y+(2*(@2-1))
 ldd @1, Y+(2*(@2-1))+1
 com @0
 com @1
 subi @0, low(-(PulseMiddle*2-MinPulseLen)-1)
 sbci @1, high(-(PulseMiddle*2-MinPulseLen)-1)
.endm

;***** Interrupt Vectors
 rjmp RESET   ;Reset Handle
.org Icp1addr
 rjmp Timer_capture_1

.org Oc1addr
 ldi XL, Channels
 reti   ; 9 cycles

.org Aciaddr
;***** AC Interrupt Vector
 ldi ch_state,0b00001111
 Out Ddrd , Ch_state ; Port D Data Direction Register – Ddrd
     ; Calculating channel data 1-4
 Directchannel Ch1tmpl , Ch1tmph , 1 ; Cannel 1
 Reversechannel Ch2tmpl , Ch2tmph , 2 ; Cannel 2
 Reversechannel Ch3tmpl , Ch3tmph , 3 ; Cannel 3
 Directchannel Ch4tmpl , Ch4tmph , 4 ; Cannel 4
     ; Channels 5-8 output
 ldi ch_state, 0b00000000

 Checkbuttons 5 , Button1 ; Channel 5
 Checkbuttons 6 , Button2 ; Channel 6
 Checkbuttons 7 , Button3 ; Channel 7
 Checkbuttons 8 , Button4 ; Channel 8

 ldi Div, ChDiv
 Out Ddrb , Ch_state ; New Buttons State Output
 ldi ch_state,0b00001111
 ldi temp,0b00000010  ; Comparator Interrupt on Falling Output Edge
 Out Acsr , Temp ; Ac Interrupt Disable
Outloop:
 sei
 cli
     ; Joystick pulse generation
     ; 4 cycles per channel, 23 cycles total
     ; if MinPulseLen   = 700:
     ; ~2156 mks max time, ChDiv = 2
     ; ~1438 mks max time, ChDiv = 3
     ; ~1078 mks max time, ChDiv = 4
     ; if MinPulseLen   = 850 :
     ; ~1869 mks max time, ChDiv = 2

 Testchannel Ch1tmpl , Ch1tmph , X1 ; Channel 1 Output
 Testchannel Ch2tmpl , Ch2tmph , Y1 ; Channel 2 Output
 Testchannel Ch3tmpl , Ch3tmph , Y2 ; Channel 3 Output
 Testchannel Ch4tmpl , Ch4tmph , X2 ; Channel 4 Output
     ; New channell state setup
 Out Ddrd , Ch_state
 ldi Div, ChDiv
 cpi ch_state, 0b00000000 ; All channels done?
 brne OutLoop
 sei
Waitpulseend:
 sbis ACSR, ACI
 rjmp WaitPulseEnd

 ldi temp,0b00011011  ; Comparator Interrupt on Rising Output Edge
 Out Acsr , Temp ; Ac Interrupt Enable
 reti

;***** Timer1 Interrupt Vector
Timer_capture_1:
 in icr1_tempL, ICR1L ; Timer 1 reloading & correction
 in icr1_tempH, ICR1H
 in tmr1_tempL, TCNT1L
 in tmr1_tempH, TCNT1H
 Sub Tmr1_templ , Icr1_templ
 sbc tmr1_tempH, icr1_tempH
 Out Tcnt1h , Tmr1_temph
 Out Tcnt1l , Tmr1_templ
 st X+, icr1_tempL
 st X+, icr1_tempH
 ldi Div, (ChDiv * 2)
 reti    ; 13+8 = 21 cycles

;*********************************************************************** 
****
;*
;* PROGRAM EXECUTION STARTS HERE
;*
;*********************************************************************** 
****

Reset:
 ldi temp,RAMEND
 Out Spl , Temp

 clr XH  ; Channels data pointer in X
 ldi XL, Channels
 clr YH  ; Channels data pointer in Y
 ldi YL, Channels+2

 ldi temp, HIGH(StartPulseLen) ; Timer/Counter1 Output Compare Register 
A – OCR1AH and OCR1AL
 Out Ocr1ah , Temp
 ldi temp, LOW(StartPulseLen)
 Out Ocr1al , Temp

 ldi temp,0
 Out Tccr1a , Temp ; Timer / Counter1 Control Register A – Tccr1a
    ; Bits 7,6 – COM1A1, COM1A0: Compare Output Mode1, Bits 1 and 0
    ; Bits 5..2 – Res: Reserved Bits
    ; Bits 1,0 – PWM11, PWM10: Pulse Width Modulator Select Bits

 ldi temp,0b00000010
 Out Tccr1b , Temp ; Timer / Counter1 Control Register B – Tccr1b
                 ; Bits 2,1,0 – CS12, CS11, CS10: Clock Select1, Bits 2, 
1 and 0
    ;CS12 CS11 CS10 Description
    ;0    0    0    Stop, the Timer/Counter1 is stopped.
    ;0    0    1    CK
    ;0    1    0    CK/8
    ;0    1    1    CK/64
    ;1    0    0    CK/256
    ;1    0    1    CK/1024
    ;1    1    0    External Pin T1, falling edge
    ;1    1    1    External Pin T1, rising edge
                 ; bit 4 -
                 ; bit 5 -
                 ; Bit 6 – ICES1: Input Capture1 Edge Select
                 ; Bit 7 – ICNC1: Input Capture1 Noise Canceler (4 CKs)

 ldi temp,0b00000001
 Out Tccr0 , Temp ; Timer / Counter0 Control Register – Tccr0
    ; Bits 7..3 – Res: Reserved Bits
    ; Bits 2,1,0 – CS02, CS01, CS00: Clock Select0, Bit 2,1 and 0
    ; CS02 CS01 CS00 Description
    ; 0    0    0    Stop, the Timer/Counter0 is stopped.
    ; 0    0    1    CK
    ; 0    1    0    CK/8
    ; 0    1    1    CK/64
    ; 1    0    0    CK/256
    ; 1    0    1    CK/1024
    ; 1    1    0    External Pin T0, falling edge
    ; 1    1    1    External Pin T0, rising edge

 ldi temp,0b01001000
 Out Timsk , Temp ; Timer / Counter Interrupt Mask Register – Timsk
    ; Bit 7 – TOIE1: Timer/Counter1 Overflow Interrupt Enable
    ; Bit 6 – OCIE1A: Timer/Counter1 Output Compare Match Interrupt 
Enable
    ; Bit 5,4 – Res: Reserved Bits
    ; Bit 3 – TICIE1: Timer/Counter1 Input Capture Interrupt Enable
    ; Bit 2 – Res: Reserved Bit
    ; Bit 1 – TOIE0: Timer/Counter0 Overflow Interrupt Enable
    ; Bit 0 – Res: Reserved Bit

 ; Analog Comparator setings
 ldi temp,0b00001011
 Out Acsr , Temp ; Analog Comparator Control And Status Register
    ; Bit 7 – ACD: Analog Comparator Disable
    ; Bit 6 – Res: Reserved Bit
    ; Bit 5 – ACO: Analog Comparator Output
    ; Bit 4 – ACI: Analog Comparator Interrupt Flag
    ; Bit 3 – ACIE: Analog Comparator Interrupt Enable
    ; Bit 2 – ACIC: Analog Comparator Input Capture Enable
    ; Bits 1,0 – ACIS1, ACIS0: Analog Comparator Interrupt Mode Select
    ;  0 0 Comparator Interrupt on Output Toggle
    ;  0 1 Reserved
    ;  1 0 Comparator Interrupt on Falling Output Edge
    ;  1 1 Comparator Interrupt on Rising Output Edge

    ; All buttons released
 ldi temp,0b00000000
 Out Ddrb , Temp ; Port B Data Direction Register – Ddrd
 ldi temp,0b00000000
 Out Portb , Temp ; Port B Data Register

 ldi temp,0b00000000
 Out Ddrd , Temp ; Port D Data Direction Register – Ddrd
 ldi temp,0b01000000
 Out Portd , Temp ; Port D , Disable Pull -up Resistors On Channels 
Output
    ; enable pull-up resistors on TX input

    ; data memory
 ldi temp, low(PulseMiddle)
 std Y+0,  temp
 std Y+2,  temp
 std Y+4,  temp
 std Y+6,  temp
 ldi temp, high(PulseMiddle)
 std Y+1,  temp
 std Y+3,  temp
 std Y+5,  temp
 std Y+7,  temp
 ldi temp, low(MinPulseLen)
 std Y+8,  temp
 std Y+10, temp
 std Y+12, temp
 std Y+14, temp
 ldi temp, high(MinPulseLen)
 std Y+9,  temp
 std Y+11, temp
 std Y+13, temp
 std Y+15, temp

 sei   ; Enable Interrupt

Mainloop:
 rjmp MainLoop

von Hobbylöt (Gast)


Lesenswert?

.include "2313def.inc"
.device ATiny2313

von Kernspalter (Gast)


Lesenswert?

Und die Fusebits richtig setzen...

von Michael Wirger (Gast)


Lesenswert?

Danke für die antworten ;)

wo trage ich .device attiny2313 ein?

Und wie setze ich die Fusebits richtig bei diesem Atmel typen das er wie 
ein at90s2313 behandelt wird? Bin wirklich noch am Anfang meines "AVR" 
verständnisses :[

Wäre super nett wenn mir jemand dabei unter die Arme greifen könnte.

von Michael Wirger (Gast)


Lesenswert?

Ich arbeite mit TwinAvr von www.rowalt.de und habe mir dort unter config 
schon 3 attinys 2313 geschreddert durch verändern der häckchen.

von Michael Wirger (Gast)


Lesenswert?

Hi,
kann mir keiner hier helfen??

von unsichtbarer WM-Rahul (Gast)


Lesenswert?

Vielleicht hilft dir das hier:
"AVR091: Replacing AT90S2313 by ATtiny2313"
http://www.atmel.com/dyn/resources/prod_documents/doc4298.pdf

Bitte melde dich an um einen Beitrag zu schreiben. Anmeldung ist kostenlos und dauert nur eine Minute.
Bestehender Account
Schon ein Account bei Google/GoogleMail? Keine Anmeldung erforderlich!
Mit Google-Account einloggen
Noch kein Account? Hier anmelden.