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.
Code: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 adcclk2Code:;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![]()





Bookmarks