Varying voltage from a sensor into a PIC16F887 and store it

Thread Starter

quantumlab

Joined Dec 4, 2008
19
Hi,
i am currently trying to input a varying voltage from a sensor into a PIC and store it in its memory. I am using PIC16F887. What would be the simpliest way of achieving our goal using assembly code? I would appreciate any help. Thanks
 

beenthere

Joined Apr 20, 2004
15,808
Apply the voltage to a PIC pin that can be configured as an input to the internal A to D converter (assuming there is one). Convert that input as often as needed.
 

Thread Starter

quantumlab

Joined Dec 4, 2008
19
Thanks for the reply. What code do i need to 'convert the input as many times as needed'? What code do i need to store the values at say twice a second?
 

beenthere

Joined Apr 20, 2004
15,808
If my catalog is correct, the PIC you have has an A to D converter with 12 inputs. The relevant section in the manual for the 16F887 will tell you how to select an input pin and configure it as an input to the A to D. It will also tell you what the command is to do a conversion. After that, it is just a matter of storing the value.

As to the time, there is another section that describes internal timer operation. Set on up to give interrupts at your desired interval. Do the conversion in the interrupt routine.
 

boff1

Joined Oct 15, 2008
26
Hi,
This is something I have done many times with a pic16f887. I use Jal compiler and can let you have code examples if you wish. I don't code in C or ASM.

cheers
 

Thread Starter

quantumlab

Joined Dec 4, 2008
19
Hi i have written the following code to recieve an analog input and store it in the general file registers. I am unsure yet as to what is involved with the interupt. I would like to simulate the code on MPLAB SIM. THe code is quickbuilding succesfully but when i simulate it i get the following error:

ADC-W0008: No stimulus file attached to ADRESL for A/D.

The code is shown below. Any help would be great


list p = 16f887
#include<p16f887.inc>
RESULTHI EQU 20 ;First counter
RESULTLO EQU 21 ; Second Counter
ORG 4 ; Interrupt vector address
ORG 5 ; Start of program memory
BANKSEL ADCON1 ;
CLRF TRISA
MOVLW B'10000000' ;right justify
MOVWF ADCON1 ;Vdd and Vss as Vref
BANKSEL TRISA ;
BSF TRISA,0 ;Set RA0 to input
BANKSEL ANSEL ;
BSF ANSEL,0 ;Set RA0 to analog
BANKSEL ADCON0 ;
MOVLW B'11000001' ;ADC Frc clock,
MOVWF ADCON0 ;AN0, On
;CALL SampleTime ;Acquisiton delay
;BSF ADCON0,GO ;Start conversion
;BTFSC ADCON0,GO ;Is conversion done?
;GOTO $-1 ;No, test again
BANKSEL ADRESH ;
MOVF ADRESH,W ;Read upper 2 bits
MOVWF RESULTHI ;store in GPR space
BANKSEL ADRESL ;
MOVF ADRESL,W ;Read lower 8 bits
MOVWF RESULTLO ;Store in GPR space
END
 

tpraja

Joined Apr 6, 2009
1
Hi Tooop,

Thanks for this circuit picture. It really help me to understand deeply. Cheers!
 
Top