Email: Password: Remember Me | Create Account (Free)

Back to Subject List

Old thread has been locked -- no new posts accepted in this thread
???
10/17/05 23:06
Read: times


 
#102521 - Need help on ADC coding
Hi all,

I'm currently using a nRF9E5 EVKIT from nordic. I have written a script but it doesn't seems to convert my analogue signals to digital. To check for my output, I used a serial cable and connected it to window's hyper terminal but all it send was a constant symbol which doesn't scales. Presented below is my script, please comment on it as much as you can. Thank you.

.equ CKCON, 0x8E
.equ EXIF, 0x91
.equ P0_DIR, 0x94
.equ P0_ALT, 0x95
.equ SPI_DATA, 0xB2
.equ SPI_CTRL, 0xB3
.equ SPICLK, 0xB4

ljmp start

start: acall init
start1: ;acall test
start2: ;acall test1
acall adc_init
acall read_adc
acall puts
ajmp start2

puts: mov a, #0
mov a, R5

putc: jnb TI, putc
clr TI
mov SBUF, a
ret


init: mov TH1, #243 ; 19200@16MHz (when T1M=1 and SMOD=1)
orl CKCON, #0x10 ; T1M=1 (/4 timer clock)
mov PCON, #0x80 ; SMOD=1 (double baud rate)
mov SCON, #0x52 ; Serial mode1, enable receiver
mov TMOD, #0x20 ; Timer1 8bit auto reload
setb TR1 ; Start timer1
orl P0_ALT, #0x06 ; Select alternate function on P01 and P02
orl P0_DIR, #0x02 ; Configure P01 (RxD) as input

mov SPICLK, #0x00 ; Max SPI clock
mov SPI_CTRL, #0x02
clr P2.3 ; RACSN = 0
mov a, #0x19 ; RRC + 0x09
acall spi_wr
acall spi_rd
orl a, #0x04
mov r0, a
setb P2.3 ; RACSN = 1
clr P2.3 ; RACSN = 0
mov a, #0x09 ; WRC + 0x09
acall spi_wr
mov a, r0
acall spi_wr
setb P2.3 ; RACSN = 1
ret

spi_rd:
spi_wr: anl EXIF, #0xdf ; Clear SPI interrupt
mov SPI_DATA, a ; Move byte to send into SPI_DATA
spi_rdwr1: mov a, EXIF ; Wait until...
jnb acc.5, spi_rdwr1; ...SPI_RX bit is set
mov a, SPI_DATA ; Move byte received into acc
ret

; AD conv. ------------------------------------------------------


adc_init: clr P2.3 ;RACSN = 0
mov a, #0x44 ;WAC
acall spi_wr

; try with different channels====================================================
mov a, #0x84 ; Supply voltage measurement (1000 0100)
;mov a, #0x24 ;AIN2, (0010 0100)
;mov a, #0x14 ;AIN1, (0001 0100)
;mov a, #0x04 ;AIN0, int_Vref, pwrup(100)
; try with different channels====================================================

acall spi_wr
mov b, a ; CSTARTN = 0
;mov a, #0x01 ;8 bit rez@Hbyte
mov a, #0x09 ;8 bit rez@Lbyte (1001)
acall spi_wr
setb P2.3 ;RACSN = 1
adc_conv: clr P2.3 ;RACSN = 0

; Use START_ADC_CONV function====================================================
; Doesn't seems to work...

;mov a, #0xC8 ;start conv @int VDD/3
;mov a, #0xC1 ;start conv @AIN1
;acall spi_wr
; Use START_ADC_CONV function===============================

mov a, #0x44 ;WAC
acall spi_wr
orl b, #0x01
mov a, b ;Start new conversion (0001 0101) CSTARN = 1
acall spi_wr
setb P2.3 ;RACSN = 1
acall delay14 ; conv time
ret

read_adc: mov a, EXIF
jnb acc.4, read_adc ;wait until EOC = 1
mov EXIF, #0xEF
clr a
clr P2.3 ;RACSN = 0
mov a, #0x41 ;RAD start at byte#0
acall spi_wr
setb P2.3 ;RACSN = 1
mov R5, a ;store converted value into R5
acall adc_init ;start new conversion
ret

test: mov R5, #50
ret
test1: inc R5
ret

delay14: mov r6, #5
delay15: djnz r6, delay15
ret

delay400: mov r7, #130
delay401: djnz r7, delay401
ret

;----------------------------------------------------------------




No replies in thread

Back to Subject List