Dear Forum members,
I tried to implement ADC1 single scan on AIN2,AIN3,AIN4 (STM8S103F3 pins PC4,PD2,PD3). The ADC scans and readings are stored in the ADC buffers 2,3,and4. The readings display AIN2 and AIN4.properly with expected value but AIN3 always displays 0. I have connected AIN2,AIN3 and AIN4 to 3.3V . AIN2 and AIN4 displays 1023 but AIN3 displays0. Please find attached the STVD project if simulation is needed. The configuration is as below. Please advice where i have gone wrong?
Thanks
Sajeev
mov CLK_CKDIVR,#$00 ; cpu clock no divisor = 16mhz
ADC_INIT:
mov ADC_CR1,#$21 ; ADC prscaler iis clk/4 = 010 ; ADON ,0b01000001
mov ADC_CSR,#$04 ; select channel-2 , channel-3 and chaneel 4, PC4,PD2,PD3
mov ADC_CR2,#$0A ; enable scan mode -bit1,result right align bit 3
bset ADC_CR3,#7 ; enable buffer for result storage
mov ADC_TDRL,#$1C ; disable schmitt trigger #2,disable schmitt trigger #3,disable schmitt trigger #4
bres ADC_CR1,#1 ; single conversion mode
ADC_READ:
bset ADC_CR1,#0 ; ADON
con_not_finish:
ld a,ADC_CSR ; copy ADC flag register to A
and a,#$80 ; AND with 0x80 contents of flag register
jreq con_not_finish ; loop label con_finish if anding results0, bit7 set if conversion finished
ld a,ADC_DB2RL ; copy ADC lower result register to A ,(buffer2)
ld result1,a ; store in result1
ld a,ADC_DB2RH ; copy ADC higher result register to A( ,buffer2)
ld result2,a ; store MSB in result2
ld a,ADC_DB3RL ; copy ADC lower result register to A ,(buffer3)
ld result3,a ; store in result3
ld a,ADC_DB3RH ; copy ADC higher result register to A ,(buffer3)
ld result4,a ; store MSB in result4
ld a,ADC_DB4RL ; copy ADC lower result register to A, (buffer4)
ld result5,a ; store in result5
ld a,ADC_DB4RH ; copy ADC higher result register to A, (buffer4)
ld result6,a ; store MSB in result6
bres ADC_CR3,#6 ; clear overrun flag
mov ADC_CSR,#$04 ; clear ADC conversion finish flag, and restore max chanel
ADC2:
ldw X,#$0000 ; load 0 in X
ldw buffer14,x ; store 0 in buffer14,buffer15
ldw X,result2 ; load X with contents of result2,result1 MSB-LSB
ldw buffer16,x ; store word in buffer16,buffer17
call bin_to_ascii ; procedure to convert binary value to ASCII , to be converted values in buffer15,16,17 msb to lsb , result in buffers to buffers+11
pointerX #buffers ; point X to buffers register , start point of ascii value storage, ascii values in buffers
mov temp1,#11 ; temp1 as counter, 10 values to be printed
call write_from_buffers1
ADC3:
ldw X,#$0000 ; load 0 in X
ldw buffer14,x ; store 0 in buffer14,buffer15
ldw X,result4 ; load X with contents of result2,result1 MSB-LSB
ldw buffer16,x ; store word in buffer16,buffer17
call bin_to_ascii ; procedure to convert binary value to ASCII , to be converted values in buffer15,16,17 msb to lsb , result in buffers to buffers+11
pointerX #buffers ; point X to buffers register , start point of ascii value storage, ascii values in buffers
mov temp1,#11 ; temp1 as counter, 10 values to be printed
call write_from_buffers1
ADC4:
ldw X,#$0000 ; load 0 in X
ldw buffer14,x ; store 0 in buffer14,buffer15
ldw X,result6 ; load X with contents of result2,result1 MSB-LSB
ldw buffer16,x ; store word in buffer16,buffer17
call bin_to_ascii ; procedure to convert binary value to ASCII , to be converted values in buffer15,16,17 msb to lsb , result in buffers to buffers+11
pointerX #buffers ; point X to buffers register , start point of ascii value storage, ascii values in buffers
mov temp1,#11 ; temp1 as counter, 10 values to be printed
call write_from_buffers1
delay: ; apprx 3 second delay
mov buffer3,#255
L2:
ldw X,#65535
L1:
decw X
jrne L1
dec buffer3
jrne L2
jp ADC_READ ; jump to ADC_READ label to restart scan ADC