PDA

Archiv verlassen und diese Seite im Standarddesign anzeigen : ATtiny 2313 Einstellung



Picht
15.08.2007, 17:09
Hallo,
in der Bascom Samples ist ein VU Meter mit Bargraphanzeige
zu finden. Leider noch mit ein AT90S2313 declariert.
Der ATtiny2313 will nicht mit den Einstellungen.Ich nehme mal an
der Comperator muss neu definiert werden.
Wie kriege ich den Code zum laufen


'--------------------------------------------------------------------------------
'name : BG30dB_LED.bas
'copyright : (c) 1995-2005, MCS Electronics
'purpose : create a logarithmic LED bar graph dB (VU) meter
'micro : AT90S2313-10
'suited for demo : yes
'commercial addon needed : no
'use in simulator : possible
'
' Author : Ger langezaal
'
'---[ Small program description ]-----------------------------------------------
'
' This program is written to create a logarithmic LED bar graph dB (VU) meter
' with peak-hold and drop-down. Scale range is 30dB in 3dB steps.
' Log conversion is done with the analog comparator on a RC discharge curve.
' C1 is charged each 4mS with PB0 as output on a Timer0 Interrupt.
' Then PB0 is set to AIN0 (analog comparator +input) Timer1 is reset
' and start counting, C1 will be discharged by R1.
' Timer1 is counting until AIN0 < AIN1.
' Analog Comparator Output = ACSR bit 5.
' Timer1 value is in T1 stored for calculation.
'
' Display mode is set with PD6 (pin 11).
' 1 = bar mode
' 0 = dot mode (for low current applications)

'---[ LED to AVR connections ]--------------------------------------------------
'
' AVR Resistor Cathode dB
' Port pin Ohm LED nr Scale
' PD5 9 >--[680]--> 11 +6
' PD4 8 >--[680]--> 10 +3
' PD3 7 >--[680]--> 9 0
' PD2 6 >--[680]--> 8 -3
' PD1 3 >--[680]--> 7 -6
' PD0 2 >--[680]--> 6 -9
' PB7 19 >--[680]--> 5 -12
' PB6 18 >--[680]--> 4 -15
' PB5 17 >--[680]--> 3 -18
' PB4 16 >--[680]--> 2 -21
' PB3 15 >--[680]--> 1 -24
' PB2 14 >--[680]--> 0 infinit
'
' All LED Anodes to +5 Volt
'
'---[ Analog comparator inputs ]------------------------------------------------
'
'
' Meter DC input >-------[ R2 ]-------> PB1 (AIN1 pin 13)
' |
' GND <---------||-----
' C2
'
' ---[ R1 ]---
' GND <----| |----> PB0 (AIN0 pin 12)
' -----||-----
' C1
' R1 = 10k 5%
' R2 = 10k
' C1 = 47nF 5%
' C2 = 47nF
'
'---[ DC input versus Timer1 and Led position ]---------------------------------
'
' Measured Timer1 values for calculation:
' DC input = 3500mV Timer1 = 192 ( +6dB)
' DC input = 312mV Timer1 = 1544 (-15dB) 21dB = factor 11.22
' 21dB = 1543 - 192 = 1351 Timer1 counts
' 3dB = 1351 / 7 = 193 Timer1 counts
'
' Input mv Timer1 LED pos dB scale
' 3500 192 11 +6
' 2477 385 10 +3
' 1753 578 9 0
' 1241 771 8 -3
' 879 965 7 -6
' 622 1158 6 -9
' 440 1351 5 -12
' 312 1544 4 -15
' 220 1737 3 -18
' 156 1930 2 -21
' 110 2123 1 -24
' <110 >2123 0 infinit
'
'---[ Compiler and hardware related statements ]--------------------------------

$regfile = "2313def.dat" 'register file for AT90S2313
$crystal = 10000000 '10MHz crystal
$hwstack = 32 ' default use 32 for the hardware stack
$swstack = 10 'default use 10 for the SW stack
$framesize = 40 'default use 40 for the frame space

Ddrb = &B11111100 'PB0 and PB1 are analog inputs
Portb.0 = 0 'disable input pullup
Portb.1 = 0 'disable input pullup

Ddrd = &B10111111 'config PD6 as input
Portd = &B11111111 'output high and enable input pullup

Acsr.7 = 0 'enable analog comparator ACSR bit 7 = 0

'---[ Variables ]---------------------------------------------------------------

Dim Peak_pos As Byte
Dim Peak_hold As Byte
Dim Drop_hold As Byte
Dim Led_pos As Word
Dim Bar_pattern As Word
Dim T1 As Word

'---[ Constants ]---------------------------------------------------------------

Const Peak_hold_time = 200
Const Drop_down_time = 40
Const Led_max = 11 'Led 0 - 11
Const T1_fs = 192 'full scale Timer1 value
Const T1_step = 193 '3dB step Timer1 value
Const T1_range = T1_step * Led_max + T1_fs 'Calculate Timer1 range

Displ_mod Alias Pind.6 'display mode 1 = Dot 0 = Bar
Ac_out Alias Acsr.5 'analog comparator output = ACSR bit 5

'---[ Timer Configuration ]-----------------------------------------------------

Config Timer0 = Timer , Prescale = 256 'On Interrupt Timer
Config Timer1 = Timer , Prescale = 8 'R/C Timer
Config Watchdog = 1024 'reset after 1 Sec no reset watchdog
Enable Interrupts
Enable Timer0
Enable Timer1
On Timer0 Dc_input_sample 'on overflow timer0 jump to label
Timer0 = 0
Timer1 = 0
Start Timer0
Start Timer1

anbei mal den "kopf" des Code's
Ist ja in den Samples zu finden

Wigbert

peterfido
15.08.2007, 19:36
Bei mir kompiliert Bascom es, wenn ich bei $regfile = "ATtiny2313.DAT" eintrage.

Was läuft denn nicht?

krulli
15.08.2007, 19:49
naja, und die Fuses mußt du logischerweise auf externen Quarz setzen...

Picht
15.08.2007, 19:58
Bei mir kompiliert Bascom es auch mit
"attiny2313.dat"Sorry, hätte ich hinschreiben können
Das ist ja das Problem. Sim. auch nichts zu sehen
aber es leuchtet keine LED bei NF am Eingang
Mit dem AT90S2313 alles Wunderbar,richtiges "Mäusekino"
Der Tiny taktet auch mit 10 Mhz. Also Fuse richtig.(Haken in Sut0)
Die Pins sind doch identisch. Zig mal so gemacht.

Dieses Rgister setzen:

Acsr.7 = 0
'enable analogcomparatorACSR bit 7 = 0

Ac_out Alias Acsr.5
'analog comparator output = ACSR bit 5

können die so bleiben.Kann im DBL nichts negatives erkennen.

Wigbert

Picht
16.08.2007, 08:13
Hallo,
ich habe festgestellt das der Watchdog mit den Tiny nicht funktioniert.
Also mit dem AT90S2313 wird die Schleife regelmässig geresettet.
Was der Tiny nicht macht.Was muss ich beim Tiny mit dem Watchdog
machen.

Wigbert

peterfido
16.08.2007, 17:58
Ich würde zu Testzwecken mal den Watchdog rausnehmen. Meinen M 644 bekomme ich nur mit Watchdog zum laufen, wenn ich am Anfang des Codes den Watchdog abschalte, denn dafür bleiben nur 4 Takte Zeit. Dann muss der Watchdog regelmäßig zurückgesetzt werden, wenn er aktiviert ist. Ich mache das immer in der Hauptschleife.



$asm

Wdt_off:
; Turn off global interrupt
cli
; Reset Watchdog Timer
wdr
; Clear WDRF in MCUSR
in r16, MCUSR
andi r16, wdrf;(0xff & (WDRF))
Out Mcusr , R16
; Write logical one to WDCE and WDE
; Keep old prescaler setting to prevent unintentional time-out
in r16, WDTCSR
ori r16,wdce; (1<<WDCE) | (1<<WDE)
Out Wdtcsr , R16
; Turn off WDT
ldi r16,wde; (0<<WDE)
Out Wdtcsr , R16

$end Asm


Watchdog initialisierung beim Mega 644.

Picht
16.08.2007, 19:41
Der Watchdog ist es wohl auch nicht.
Ich hab ihn mal komplett raus genommen und der AT90S2313
resettet sich immer noch regelmäßig.
Der ATtiny läuft einfach durch. Kann ich das irgendwie Debuggen?
Wie sehe ich ob Timer arbeiten?
Es ist zum Kotz...

Wigbert

Picht
16.08.2007, 20:23
Hallo Leute,

hab den Fehler gefunden. Der Attiny kennt den Befehl:

'Start Timer0
'Start Timer1

nicht und muss entfernt werden

peterfido dank dir für den Code.

Wigbert