Code:
$regfile = "m32def.dat"
$crystal = 48000000
$baud = 1200
'Timer config
Config Timer0 = Timer , Prescale = 8
Config Timer1 = Timer , Prescale = 1024
Enable Timer0
Enable Timer1
On Timer0 Readout:
On Timer1 Counts:
'Variablen
Dim Ainput As Integer
Dim Inpvolt As Integer
Dim Tint(2) As Byte
Dim Rest As Byte
Dim Temp As Integer
Dim Cnt As Byte 'Counter for Loops and so on
Dim Tvolt As Integer
Dim Setvolt As Integer
Dim Times As Dword
'ADC Config
Config Adc = Free , Prescaler = 64 , Reference = Aref
Start Adc
Enable Interrupts
'Functions
Declare Sub Writedac(byval Volt As Integer)
'Buttons
Config Pind.0 = Input
Config Pind.1 = Input
Config Pind.2 = Input
Config Pind.3 = Input
Bu Alias Pind.0
Bl Alias Pind.1
Bd Alias Pind.2
Br Alias Pind.3
'DAC Ausgänge
Config Pinb.0 = Output
Config Pinb.1 = Output
Config Pinb.2 = Output
Config Pinb.3 = Output
Cs Alias Portb.2
Sck Alias Portb.1
Sdi Alias Portb.0
Ldac Alias Portb.3
Config Spi = Soft , Dout = Sdi , Ss = Cs , Clock = Sck
Spiinit
Ldac = 0
'R / W Pin Von Lcd
Config Pinc.5 = Output
Rw Alias Pinc.5
Rw = 0
'LCD Config
Config Lcdpin = Pin , Db4 = Portc.3 , Db5 = Portc.2 , Db6 = Portc.1 , Db7 = Portc.0 , E = Portc.4 , Rs = Portc.6
Config Lcd = 16x2 , Chipset = Dogm162v5
Initlcd
Display On , Nocursor
Cls
Do
'Inpvolt=ainput-511
Setvolt = Ainput * 4
Call Writedac(setvolt)
Loop
'Timer0 interrupt
Readout:
Ainput = Getadc(0)
Timer0 = 142
Return
'TIMER1 interrupt
Counts:
Timer1 = 18661
Locate 1 , 1
Lcd "ATMega at 48MHz"
Incr Times
Locate 2 , 1
Lcd Str(times)
Return
Sub Writedac(byval Volt As Integer)
Tint(2) = Volt
Temp = Volt
Shift Temp , Right , 8
Tint(1) = Temp Or &B01110000
Spiout Tint(1) , 2
End Sub
Das ist der Code. Ich muss dazusagen auf dem Oszilloskop sieht man das die Pulse eigentlich zu kurz sind. Laut datenblatt des controllers 25ns welche wahrscheinlich schon unterschritten sind.
Die änderung von $crystal bewirkt nichts.
Habe leider keinen Schaltplan gemacht aber das Dog M 162 ist in 4-Bit 5V Modus wie im Datenblatt angegeben angeschlossen.
MfG Vader
Lesezeichen