[an error occurred while processing this directive]
|
;----------------------------------------------------------------------------;Start ADC:
;Input: YL - ADC MUX (0,0,0,0,Bs,A2,A1,A0)
; YH - ADC G and DR (0,G2,G1,G0,Dr3,Dr2,Dr1,Dr0)StADC: Port_ADC_0
ldi temp,cWREG+rSTATUS ;start write from MUX register
rcall SPI_RW
ldi temp,0x0A ;write 11 registers
rcall SPI_RWldi temp,0x00
rcall SPI_RW ;1 - write STATUS register
mov temp,YL
rcall GetMUX
rcall SPI_RW ;2 - write MUX register
mov temp,YH
andi temp,0x70
swap temp
rcall SPI_RW ;3 - write ADCON register
mov temp,YH
rcall GetDR
rcall SPI_RW ;4 - write DRATE register
ldi temp,0xE0
rcall SPI_RW ;5 - write IO register (dummy)
ldi temp,0x00
rcall SPI_RW ;6 - write OFC0
ldi temp,0x00
rcall SPI_RW ;7 - write OFC1
ldi temp,0x00
rcall SPI_RW ;8 - write OFC2
mov temp,YH
rcall GetFSC
mov temp,XL
rcall SPI_RW ;9 - write FSC0
mov temp,XH
rcall SPI_RW ;10 - write FSC1
mov temp,YL
rcall SPI_RW ;11 - write FSC2; ldi temp,cSYNC
; rcall SPI_RW ;SYNC command
ldi temp,cWAKEUP
rcall SPI_RW ;WAKEUP command
Port_ADC_1
ldi Pro,P_Adc ;start process
ret;Get MUX register code:
;Input: temp - 0,0,0,0,Bs,A2,A1,A0
;Out: temp - PSEL3,PSEL2,PSEL1,PSEL0,NSEL3,NSEL2,NSEL1,NSEL0GetMUX: mov XL,temp
andi XL,0x07
table TabMUX ;table base
add ZL,XL ;add offset
adc ZH,XL
sub ZH,XL
lpm XH,Z ;read table
swap XH
bbrc temp,bBs,nbs
ori XH,0x03 ;N - AIN3 (Bias)
rjmp xbs
nbs: ori XH,0x08 ;N - AINCOM
xbs: mov temp,XH
ret;ADC MUX table:
TabMUX: .db 0x01,0x02,0x04,0x00,0x05,0x03,0x06,0x07
;Get DRATE register code:
;Input: temp - 0,G2,G1,G0,Dr3,Dr2,Dr1,Dr0
;Out: temp - DR7..DR0GetDR: andi temp,0x0F
table TabDR ;table base
add ZL,temp ;add offset
adc ZH,temp
sub ZH,temp
lpm temp,Z ;read table
ret;ADC DRATE table:
TabDR: .db 0xF0,0xE0,0xD0,0xC0,0xB0,0xA1,0x92,0x82
.db 0x72,0x63,0x53,0x43,0x33,0x23,0x13,0x03;Get FSC registers code:
;Input: temp - 0,G2,G1,G0,Dr3,Dr2,Dr1,Dr0
;Out: XL - FSC0 code
; XH - FSC1 code
; YL - FSC2 codeGetFSC: andi temp,0x0F ;temp = offset
lsl temp ;offset x 4
lsl temp
table TabFSC
add ZL,temp ;add offset
adc ZH,temp
sub ZH,temp
lpm XL,Z+
lpm XH,Z+
lpm YL,Z+
ret;FSC table for different data rates:
TabFSC: .dd 0x44AC08,0x44AC08,0x44AC08,0x44AC08
.dd 0x494008,0x494008,0x494008,0x3A99A0
.dd 0x4651F3,0x3A99A0,0x4651F3,0x3A99A0
.dd 0x4651F3,0x2EE14C,0x2EE14C,0x2EE14C;Read ADC:
;Out: cpADC - ADC codeRdADC: Port_ADC_0
ldi temp,cRDATA
rcall SPI_RW ;RDATA command
ldi temp,10
rcall Del_uS ;delay 10 uS
ldi temp,0x00
rcall SPI_RW ;read MSB
sts cpADC+2,temp
ldi temp,0x00
rcall SPI_RW ;read Mid-Byte
sts cpADC+1,temp
ldi temp,0x00
rcall SPI_RW ;read LSB
sts cpADC+0,temp
Port_ADC_1
ret;----------------------------------------------------------------------------
;Read/write byte via SPI:
;Input: temp - data byte
;Out: temp - data byteSPI_RW: out SPDR,temp
wspi: in temp,SPSR
bbrc temp,SPIF,wspi
in temp,SPDR
ret;--------------------------------------------------------
E-mail: info@telesys.ru