PDA

View Full Version : Strange output from ADC



vellamike
- 23rd January 2012, 02:51
I am trying to get the ADC module of the PIC16F870 to work. Unfortunately I am using somebody else's code as I have little experience with microcontrollers. The ADC works but seems to be susceptible to jumping from one "plateau" to another. At the bottom of this post I have included two images with examples of the voltage traces I'm getting when I input a sine wave or a triangle signal. I've also included the relevant code. Has anyone ever experienced this kind of thing? Please let me know if any more information is needed.


adcstart clrf temph clrf templ
clrf store
bcf portc,3 ;ADC CLK low
bcf portc,4 ;ADC CS LOW
bsf portc,5 ;ADC DIN HIGH START
bsf portc,3 ;CLKH1
bcf portc,3 ;CLKL1
bsf portc,5 ;DIN LOW=DIFFERENTAL MODE/single=High
bsf portc,3 ;CLKH2
bcf portc,3 ;CLKL2
return


adcfinish bcf portc,5 ;ADC DIN low
movlw d'4' ;CLK7-10
movwf adcclk2

;PROGRAM STARTSmain clrf sendreg
clrf highmanh
clrf highmanl
clrf templ
clrf temph
clrf store
bsf portc,4 ;ADC CS high
call longdly ;debounce
bcf portb,7 ;led off
call longdly ;debounce


div5 bsf portb,7 ;sample time
spaced movlw 0xf0 ;test data high
movwf store
call manconvert
call uart_out
nop
movlw 0xf0 ;test data high
movwf store
call manconvert
call uart_out
nop
call adcstart
call cha
call adcfinish
call adcstart
call chb
call adcfinish
call adcstart
call chc
call adcfinish
call adcstart
call chd
call adcfinish
call adcstart
call che
call adcfinish
bcf portb,7
goto div5
end
62386239

rsocor01
- 23rd January 2012, 06:26
Well, this forum is for PicBasic. Although, there are few people here that might be able to help you with asembly. And, yes indeed that's a very strange output you are getting there.

vellamike
- 23rd January 2012, 10:58
What would be a better forum to post to?

Dave
- 23rd January 2012, 12:05
Vellamike, For starters this is not the input to a PIC but the input from some external A/D converter isn't it? Looking at the code, I can see that you are manipulating the starting of the conversion and receiving the result. Unless you are going to also include the circuit and, components you are using, there is no way of helping you....

vellamike
- 23rd January 2012, 12:21
Vellamike, For starters this is not the input to a PIC but the input from some external A/D converter isn't it? Looking at the code, I can see that you are manipulating the starting of the conversion and receiving the result. Unless you are going to also include the circuit and, components you are using, there is no way of helping you....

The input is directly into the PIC which has it's own ADC module. What makes you think that I am getting the input from an external ADC?

I will post the circuit diagram in a bit as I don't have it available to me at the moment.

rsocor01
- 23rd January 2012, 16:16
What would be a better forum to post to?

You can try here

http://www.microchip.com/forums/f16.aspx