PDA

View Full Version : Help With Sampling



hazda
- 24th August 2008, 11:08
Im having a problem in understanding how to set the sampling rate using the PIC16F887,i did read the data sheet own how to set the ADC and im still a bit confused.Basically what i need to do is to sample two sinusoidal signals which are at 50Hz (voltage and current).I want to sample this ac inpututs 20 times per 50Hz cycle.After each period(i.e 1/50Hz) i want to multipy the corresponding voltage and current to get the instantaneous power and display it on the onboard LEDs.This is the code i already have:

#include <p16F887.inc>
__CONFIG _CONFIG1, _LVP_OFF & _FCMEN_OFF & _IESO_OFF & _BOR_OFF & _CPD_OFF & _CP_OFF & _MCLRE_OFF & _PWRTE_ON & _WDT_OFF & _INTRC_OSC_NOCLKOUT
__CONFIG _CONFIG2, _WRT_OFF & _BOR21V

org 0x0

;------------- Voltage signal----------------------------

volts
movlw B'01000001' ;configure A/D converter
movwf ADCON0 ;turn A/D on
movlw b'10001110' ;RA0 = analog input
movwf ADCON1


volts_again
bsf ADCON0,GO ;start conversion
again
btfsc ADCON0,GO
goto again
movf ADRESH,W ;ADRESH --> WREG


;------------- Current signal--------------------------------------------

current
movlw B'01000001' ;configure A/D converter
movwf ADCON0 ;turn A/D on
movlw b'00001110' ;RA0 = analog input
movwf ADCON1

current_again
bsf ADCON0,GO ;start conversion
again1
btfsc ADCON0,GO
goto again1
movf ADRESH,W ;ADRESH --> WREG

please help me with the following

1.how can i implement taking 20 samples for each 50Hz cycle on the code
2.will the adc of the voltage and current occur simultaneously?if not how do i run the first adc of the voltage signal and there after run the second adc of the current signal,such that i will be able to multiply the corresponding digital votages and currents to get the correct intantaneous power

IM USING PIC16F887your help will be appreciated