Help Me Pls,sampling!!!!!!!


Closed Thread
Results 1 to 2 of 2
  1. #1
    Join Date
    Aug 2008
    Posts
    2

    Default Help Me Pls,sampling!!!!!!!

    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 PIC16F887,your help will be appreciated

  2. #2
    Join Date
    May 2004
    Location
    NW France
    Posts
    3,611


    Did you find this post helpful? Yes | No

    Wink

    Hi, Hazda

    First of all ... no need to "bomb" the forum with the same question. Once is enough.

    second ... here we talk PicBasicPro, and not assembler ...


    For what you should do, it's simple : just use a timer interrupt ( see "compare" feature of pics ... and add 1 ms to the value at each interrupt.) to initiate both conversions every 1 ms AND synchronize the timer reset with mains zero crossing.

    Here is an example ( in MkBasic ! )

    Code:
    program Timer1ModeComparaison
    
    ' Pic 16F877 @ 8 Mhz
    
    dim comparaison as word
    
    sub procedure interrupt
         comparaison = comparaison + 500
         CCPR1L = comparaison          ' Ecriture poids faibles CCPR1L
         CCPR1H = word(comparaison >>8)' Ecriture poids forts CCPR1H
         PORTB = PORTB xor %00000001   ' Changement d'etat sortie Toggle output
         PIR1 = %00000000
         PIE1 = %00000100
         INTCON = %11000000
    end sub
    
    main:
         comparaison = 0
         TRISB = 0                      ' PORT B en sortie
         PORTB = 0
         T1CON = 1                      ' Validation timer 1 ; Timer1 ON
         CCP1CON = %00001010            ' Definition mode comparaison ; compare mode
         PIE1 = %00000100               ' Autorisation it comparaison       ; Compare interrupt enable
         INTCON = %11000000
         while true                     ' Boucle sans fin ; endless loop
         wend
    end.
    it outputs a 1 Khz signal on Portb.0 ... but ,instead, could initiate your conversions !!!

    Alain
    ************************************************** ***********************
    Why insist on using 32 Bits when you're not even able to deal with the first 8 ones ??? ehhhhhh ...
    ************************************************** ***********************
    IF there is the word "Problem" in your question ...
    certainly the answer is " RTFM " or " RTFDataSheet " !!!
    *****************************************

Members who have read this thread : 1

You do not have permission to view the list of names.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts