YHDC current sensor - the theory please


+ Reply to Thread
Results 1 to 5 of 5
  1. #1
    Join Date
    Aug 2006
    Location
    SWITZERLAND (french speaking)
    Posts
    940

    Default YHDC current sensor - the theory please

    Hi All,

    I'm resuming a project I started more than one year ago; it is about to use a YHDC current sensor.

    Name:  YHDC small.jpg
Views: 26
Size:  7.0 KB


    For now, I have a 16F18446 carrying a 12 bits ADC that I hope sufficient just to put me on the track and avoid the usage of an external higher resolution ADC chip adding "difficulties".

    The YHDC sensor I have on my bench is a 100A:50mA model.

    I found a lot of these drawings like this one below but I can't make them work or better said, I don't know how to "read" their output.

    Name:  ARDUINO.jpg
Views: 28
Size:  21.1 KB



    Do I have to sample let's say a 30 to 50 times or so to grab an alternance, find out both zero-crossing values (or as close as possible) and then extract the higher value in between?

    What is the correct way to do this?

    Thanks for any explanation on this one
    Attached Files Attached Files
    Roger

  2. #2
    Join Date
    Nov 2005
    Location
    Bombay, India
    Posts
    970


    Did you find this post helpful? Yes | No

    Default Re: YHDC current sensor - the theory please

    If you are trying to read the magnitude of current flowing in the primary of the current transformer(CT), you would like to first amplify the AC output of CT using an op-amp. Then do a DC peak conversion on the output of the op-amp. Read this value. It will be proportional to the current flowing in the primary. The ADC on the PIC can now read this DC value in a poll.

  3. #3
    Join Date
    May 2013
    Location
    australia
    Posts
    2,684


    Did you find this post helpful? Yes | No

    Default Re: YHDC current sensor - the theory please

    a simple digital peak detector will give a reasonable result,

    eg
    2v p-p input offset to approx 1.5v for a vcc of 3.3v for adc

    Name:  RigolDS0.jpg
Views: 10
Size:  160.1 KB


    [arduino ide serial plotter]
    at a 200us sample rate
    Name:  peak200.jpg
Views: 10
Size:  107.3 KB

    at 1000us sample rate , its still not bad
    Name:  peak1000.jpg
Views: 10
Size:  139.7 KB


    Code:
    '****************************************************************'*  Name    : peak_detector_ADC_16F18446.pbp
    '*  Author  : richard
    '*  Notice  : 
    '*          : All Rights Reserved
    '*  Date    : 
    '*  Version : 1.0
    '*  Notes   :
    
    
    
    
    
    
    
    
     '====== PIC 16F18446 FUSES ========================================================================
      #CONFIG
        __config _CONFIG1, _FEXTOSC_OFF & _RSTOSC_HFINT32 & _CLKOUTEN_OFF & _CSWEN_ON & _FCMEN_ON
        __config _CONFIG2, _MCLRE_ON & _PWRTS_PWRT_64 & _LPBOREN_OFF & _BOREN_SBOREN & _BORV_LO & _ZCDDIS_OFF & _PPS1WAY_OFF & _STVREN_ON
        __config _CONFIG3, _WDTCPS_WDTCPS_31 & _WDTE_SWDTEN & _WDTCWS_WDTCWS_7 & _WDTCCS_LFINTOSC
        __config _CONFIG4, _BBSIZE_BB512 & _BBEN_OFF & _SAFEN_OFF & _WRTAPP_OFF & _WRTB_OFF & _WRTC_OFF & _WRTD_OFF & _WRTSAF_OFF & _LVP_OFF
        __config _CONFIG5, _CP_OFF
      #ENDCONFIG 
    
    
    ' ====== REGISTERS =================================================================================
    
    
        ANSELA  = % 00100000
        ANSELC  = % 00000000
        TRISC   = % 11101111
        ADCON0  = % 10000100 'ADC is ON, RIGHT justified result 
    
    
    ' ====== DEFINES ===================================================================================
        DEFINE OSC 32
        DEFINE ADC_BITS 12     'Number of bits in ADCIN result
        DEFINE HSER_TXSTA 24h ' Enable transmit, BRGH = 1
        DEFINE HSER_CLROERR 1 ' Clear overflow automatically
        'DEFINE HSER_SPBRG 138 ' 57600 Baud @ 32MHz, -0.08%
        DEFINE HSER_SPBRG 68  ' 115200 Baud @ 32MHz, 0.64%
        SP1BRGH = 0
        BAUDCON.3 = 1         ' Enable 16 bit baudrate generator
        pause 500
        RC3PPS = 15          ;tx            PORTC.3 
        RA0PPS = 15          ;tx            PORTA.0      ;PK3
        RC4PPS = 0           ;rx            unused
        LED    VAR LATC.4
        clear
        new_read     var word
        State        Var BYTE 'serial Bd (baud per second)
        peak         var word
        last         var word
    
    
    ' ====== setup PROGRAM =============================================================================
        led = 1
        ADCIN 5, last  
        pause 1000
        HSEROUT ["ready ",13,10]
        led = 0    
         ;707 -3670
    ' ====== MAIN PROGRAM =============================================================================
    MAIN:
        ADCIN 5, new_read ' ADC 
        gosub getpeak
        HSerout ["ADC:",dEC new_read,",peak:",dEC peak,13,10]                    '    PLOTTER
        pauseus 200   ;   sample rate                         
    GOTO MAIN
    
    
    getpeak:
        if state==0 then    ;rising
           if   new_read < last  then
            state = 1;falling 
            peak =   last
           endif
        else        ;falling
           if   new_read > last   then 
            state = 0;rising 
            peak =   last
           endif
        ENDif
        last = new_read
    return
    Warning I'm not a teacher

  4. #4
    Join Date
    Aug 2006
    Location
    SWITZERLAND (french speaking)
    Posts
    940


    Did you find this post helpful? Yes | No

    Default YHDC current sensor - the theory please

    Peak detector! That's it!

    Thanks a lot for explaining and the code I can't wait to try when I'm back from office

    Though, why do I always read about 3.3V measuring circuits and not 5V?

    Also, a "peak detector" can be as simple as a resistor and a capacitor in parallel "smoothing" the output of the sensor, or like Jerson wrote, of the op-amp, right?

    If "yes", how do I dimension them? Are trials and readouts on the scope the best way to go?
    Roger

  5. #5
    Join Date
    May 2013
    Location
    australia
    Posts
    2,684


    Did you find this post helpful? Yes | No

    Default Re: YHDC current sensor - the theory please

    why do I always read about 3.3V measuring circuits and not 5V?
    my dev board has a 3.3v reg, otherwise can't see that it makes a difference


    a "peak detector" can be as simple as a resistor and a capacitor in parallel "smoothing" the output of the sensor, or like Jerson wrote, of the op-amp, right?
    not really , it needs a rectifier too. if the wave is not symmetrical the neg and pos peaks may be needed. plus it still needs adc code to read it in anyway


    Are trials and readouts on the scope the best way to go?
    almost essential, especially depending on the nature of the current being monitored,
    if the current is not sinusoidal and/or varies rapidly then its going to need filtering and other compensation to get any sort of reasonable calibration
    Warning I'm not a teacher

Similar Threads

  1. Current sensor output modification. PIC or opamp or something else?
    By retepsnikrep in forum mel PIC BASIC Pro
    Replies: 9
    Last Post: - 10th December 2020, 06:22
  2. Counter and interrupt theory
    By astouffer in forum mel PIC BASIC Pro
    Replies: 2
    Last Post: - 23rd January 2014, 02:21
  3. Replies: 8
    Last Post: - 5th May 2009, 21:10
  4. current sensor interfacing
    By hell_pk in forum mel PIC BASIC Pro
    Replies: 9
    Last Post: - 29th January 2009, 05:55
  5. PIC based mAh meter/current draw sensor
    By skimask in forum Off Topic
    Replies: 6
    Last Post: - 26th February 2008, 03:10

Members who have read this thread : 7

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