| 
 | 
 
 | 
 
Der MICRO8 benutzt ein digitales Potentiometer als digital-zu-analog-Konverter (DAC).
 
 
Die integrierte Schaltung CAT522 von Catalyst ( Datenblatt als PDF Datei )
 
 
Sie bietet 2 x 8bit aufgelöste Widerstände.
 
Man / WRD kann einen Festwert für den Anfang speichern.
 
 
Hier ein BASCOM Code-Schnipsel wie ein MICRO8 die Daten in den CAT522 bekommt:
 
 
'------------------------------------------------------------------------------
 
'name                     : MICRO8_U1.bas
 
'copyright                : (c) 2007, Werner Braun
 
'purpose                  : TubeTester (testing)
 
'micro                    : Mega8
 
'suited for demo          : yes , only
 
'commercial addon needed  : no
 
'version                  : ZERO , to be changed without notice
 
'------------------------------------------------------------------------------
 
$regfile = "m8def.dat"                                      ' we use the M8
 
$crystal = 3686400
 
$baud = 38400
 
$hwstack = 32
 
$swstack = 8
 
$framesize = 24
 
 
'The following info was inserted by the programmer.
 
'Press the Write PRG button and it will insert the current Lock,and Fusebit
 
'settings.
 
'The options are DIVIDE by 8 : disabled, External osc. selected
 
'$prog &HFF , &HEF , &HDF , &HFF
 
' generated. Take care that the chip supports all fuse bytes.
 
'It is advised to use the $prog only once to set the bits.
 
'So remark it after the chip has been programmed the first time
 
 
Dim Command As Byte
 
Dim Content As Byte
 
Dim Pointer As Byte
 
Dim Ulow(5) As Integer
 
Dim Uhigh(5) As Integer
 
Dim Ilow(5) As Integer
 
Dim Ihigh(5) As Integer
 
Dim Daclow As Byte
 
Dim Dachigh As Byte
 
Dim Dactemp As Integer
 
 
'Hardware:
 
'ATmega8
 
 
'Pin    kind   (used for)
 
 
'PB0 :  OUT    (CLK  CAT 522)
 
'PB1 :  OC1A   (PWM, AUX)
 
'PB2 :  OC1B   (PWM, AUX)
 
'PB3 ;  MOSI   (SPI)
 
'PB4 :  MISO   (SPI)
 
'PB5 :  SCK    (SPI)
 
'PB6 :  XTAL   (external Clock 3.6864Mc)
 
'PB7 :  OUT    (PRG CAT 522)
 
 
'PD0 :  RXD    (UART serial in)
 
'PD1 :  TXD    (UART serial out)
 
'PD2 :  INT0   (AUX)
 
'PD3 :  INT1   (AUX)
 
'PD4 :  XCK    (AUX)
 
'PD5 :  OUT    (DI   CAT 522)
 
'PD6 :  OUT    (CS   CAT 522)
 
'PD7 :  IN     (RDY  CAT 522)
 
 
'PC0 .  ADCin0 (Ihigh)
 
'PC1 :  ADCin1 (Ilow)
 
'PC2 :  ADCin2 (Ulow)
 
'PC3 :  ADCin3 (Uhigh)
 
'PC4 :  IN     (Ipolarity)
 
'PC5 :  IN     (Upolarity)
 
'PC6 :  RESET
 
'PC7 :
 
 
 
' DAC:
 
' CAT 522 is a digital potentiometer (DPP) used as a (2 x 8bit) DAC
 
' PB0 = CLK
 
Config Portb.0 = Output
 
Ddrb.0 = 1
 
' PD7 = RDY from CAT 522
 
Config Portd.7 = Input
 
Ddrd.7 = 0
 
' PD6 = CS
 
Config Portd.6 = Output
 
Ddrd.6 = 1
 
' PD5 = DI
 
Config Portd.5 = Output
 
Ddrd.5 = 1
 
' PB7 = PRG
 
Config Portb.7 = Output
 
Ddrb.7 = 1
 
' U1 is +/-volt, 127 is first aprx. to zero volt
 
' put 127 to both DACs
 
Daclow = 127
 
Dachigh = 127
 
' temp. out should have PRG low
 
Portb.7 = 0
 
' temp. out should have CS high
 
Portd.6 = 1
 
Gosub Send_to_dac
 
 
...
 
 
Send_to_dac:
 
 
   ' CAT 522 gets data when clock rises
 
   ' CAT 522 needs 1 startbit
 
   ' CAT 522 reads address A0 A1 next for output 1 or 2
 
   ' CAT 522 gets LSB first
 
   ' put Highbyte first, be fast
 
   ' rotate 8bits left 4 times
 
   Dactemp = Dachigh * 8
 
   ' add startbit + address
 
   Dactemp = Dactemp + 7
 
   Shiftout Portd.5 , Portb.0 , Dactemp , 3 , 13
 
   ' put Lowbyte second, less effect
 
   ' rotate 8bits left 4 times
 
   Dactemp = Daclow * 8
 
   ' add startbit + address
 
   Dactemp = Dactemp + 5
 
   Shiftout Portd.5 , Portb.0 , Dactemp , 3 , 13
 
   ' bit 12 and 13: wait CAT522 needs a two cycles rest.
 
 
Return
 
...  | 
 
  |