ADC Question


Closed Thread
Results 1 to 8 of 8

Thread: ADC Question

Hybrid View

  1. #1
    Join Date
    May 2012
    Location
    Merseyside, UK
    Posts
    237

    Smile ADC Question

    Hi Thank you for reading

    I am attempting to read a 4-20mA signal into a PIC ADC across a 250R Resistor (1-5v) ultimately to trigger a couple of digital outputs (set points) !

    All is OK.... But I would like to add some hysteresis around the process signal so as to dampen the digitals around the transition time.

    My question is how do I do it ?

    Been away from PBP to long !! Thank you reading again

    BR
    Andy

  2. #2
    Join Date
    May 2013
    Location
    australia
    Posts
    2,631


    Did you find this post helpful? Yes | No

    Default Re: ADC Question

    Code:
    if abs(setpoint -reading) > hysteresis   then  
        do something
    else
        do somethingelse
    endif

  3. #3
    Join Date
    May 2012
    Location
    Merseyside, UK
    Posts
    237


    Did you find this post helpful? Yes | No

    Default Re: ADC Question

    Hi Richard

    Thank you for fast answer ... But I still not understanding ...


    How does the ABS work in the code ... Also I assume hysteresis is a constant !

    BR
    Andy

  4. #4
    Join Date
    May 2013
    Location
    australia
    Posts
    2,631


    Did you find this post helpful? Yes | No

    Default Re: ADC Question

    How does the ABS work in the code
    abs works as it normally does , read the pbp manual for a detailed explanation


    I assume hysteresis is a constant !
    only if you want it to be

    I would like to add some hysteresis around the process signal
    I'm assuming by your initial question that by hysteresis you mean ; set point plus or minus a small amount .
    therefore a trigger event occurs when the reading is outside the (setpoint -+ hysteresis) range

    there are many more possibilities

  5. #5
    Join Date
    Oct 2005
    Location
    Sweden
    Posts
    3,604


    Did you find this post helpful? Yes | No

    Default Re: ADC Question

    Hi,
    Here's another aproach
    Code:
    ON CON 1
    OFF CON 0
    Hysteresis CON 5
    Setpoint CON 120
    
    Solenoid VAR PortB.0
    
    InputSignal VAR BYTE
    
    ' With the above value we will turn the output ON when the SetPoint reaches 125 and OFF when it reaches 115.
    
    If (Solenoid = OFF) AND (InputSignal >= (Setpoint + Hysteresis)) THEN
      Solenoid = ON
    ENDIF
    
    IF (Solenoid = ON) AND (InputSignal <= (Setpoint - Hysteresis)) THEN
      Solenoid = OFF
    ENDIF
    /Henrik.

  6. #6
    Join Date
    May 2012
    Location
    Merseyside, UK
    Posts
    237


    Did you find this post helpful? Yes | No

    Default Re: ADC Question

    Hi Henrik

    Thank you for help re:- my coding... Us HW people suffer with S/W issues... Cant see what is happening if cant prod it with Fluke

    Anyway got it working today... See below :-

    Code:
    '****************************************************************
    '*  Name    : TRIP.BAS                                      *
    '*  PIC     : PIC16F688                         *
    '*  Author  : [select VIEW...EDITOR OPTIONS]                    *
    '*  Notice  : Copyright (c) 2015 [select VIEW...EDITOR OPTIONS] *
    '*          : All Rights Reserved                               *
    '*  Date    : 29/10/2015                                        *
    '*  Version : 1.0                                               *
    '*  Notes   : 322 Words used                                    *
    '*          :                                                   *
    '*                                                              *
    '*  Process Signal  AN0                                         *
    '*  Alarm Preset    AN1                                         *
    '*  Trip Preset     AN2                                         *
    '*  Delay Trip Dly  RC2                                         *
    '*  Alarm Relay     RC3                                         *
    '*  Trip Relay      RC4                                         *
    '*  Reset Trip P/B  RC5                                         *
    '****************************************************************
    
    DEFINE OSC 8              ' Set RC Clock to 8 Megs
    CMCON0 = 7                  'Disable both comparators    
    
    'Define ADCIN parameters
    Define  ADC_BITS     10    ' Set number of bits in result
    Define  ADC_CLOCK    3     ' Set clock source (3=rc)
    Define  ADC_SAMPLEUS 50    ' Set sampling time in uS
    ANSEL = %00000111          ' Enable ADC channels AN2-AN0
    ADCON1 = %10000000         ' Set PORTA analog and right justify result
    
    'Analogs
    PROC_SIG Var word           ' Create PROC_SIG to store result
    ALARM_TRIM Var word         ' Create ALARM_TRIM to store result
    TRIP_TRIM Var word          ' Create TRIP_TRIM to store result
    
    'Digitals
    ALARM_RLY VAR PORTC.3       ' Alarm Relay
    TRIP_RLY VAR PORTC.4        ' Trip Relay
    TRIP_RST VAR PORTC.5        ' Trip Reset PB
    TRIP_DLY VAR PORTC.2        ' Trip Delay Link
    
    'Constants
    RLY_OFF CON 0               ' Relay Off
    RLY_ON CON 1                ' Relay On
    HYS CON 25                  ' 25 = 1/8Volt
    
    
    START:
    LOW TRIP_RLY                ' Ensures Trip Rly off
    LOW ALARM_RLY               ' Ensures Alarm Rly off
    
    Gosub ANALOG_READ
    If (ALARM_RLY = RLY_OFF) AND (PROC_SIG >= (ALARM_TRIM + HYS)) THEN ALARM_RLY = RLY_ON
    If (ALARM_RLY = RLY_ON) AND (PROC_SIG <= (ALARM_TRIM - HYS)) THEN ALARM_RLY = RLY_OFF
    If (TRIP_RLY = RLY_OFF) AND (PROC_SIG >= (TRIP_TRIM + HYS)) and TRIP_DLY = 0 THEN goto D_TRIP
    If (TRIP_RLY = RLY_OFF) AND (PROC_SIG >= (TRIP_TRIM + HYS)) AND TRIP_DLY = 1 THEN goto L_TRIP
    GOTO START
    
    
    L_TRIP:                     ' Latching Trip
    high TRIP_RLY               ' Latch Trip Relay
    IF TRIP_RST = 0 THEN GOTO START     'Release If PB Reset  Pressed   
    Goto L_trip
    
    D_TRIP:                     ' Delayed Trip
    HIGH TRIP_RLY               ' Latch Trip Relay
    PAUSE 1000                  ' Pause for T_Delay
    GOTO START
    
    ANALOG_READ:                ' Read analogs
    ADCIN 0, PROC_SIG           ' Read channel 0 to PROC_SIG
    ADCIN 1, ALARM_TRIM         ' Read channel 1 to ALARM_TRIM
    ADCIN 2, TRIP_TRIM          ' Read channel 2 to TRIP_TRIM
    RETURN
    
    END
    Anything you see wrong in my attempt above do tell ..... Is there a correct order to list the defines / setup etc ?

    Thank you again for your help

    BR
    Andy

  7. #7
    Join Date
    May 2013
    Location
    australia
    Posts
    2,631


    Did you find this post helpful? Yes | No

    Default Re: ADC Question

    you might need another read of the hardware manual for a 16f688
    'Define ADCIN parameters
    Define ADC_BITS 10 ' Set number of bits in result
    Define ADC_CLOCK 3 ' Set clock source (3=rc)
    Define ADC_SAMPLEUS 50 ' Set sampling time in uS
    ANSEL = %00000111 ' Enable ADC channels AN2-AN0
    ADCON1 = %10000000 ' Set PORTA analog and right justify result ?????????????
    this will REALLY be
    ADCON1 = %10000000 ' Set Conversion Clock = FOSC/2 and bit 7 does nothing

    you need

    ADCON0.7=1 ' right justify result




Similar Threads

  1. ADC Question
    By Art in forum General
    Replies: 0
    Last Post: - 24th January 2012, 02:35
  2. ADC question again
    By Bobbo_ZA in forum mel PIC BASIC Pro
    Replies: 12
    Last Post: - 7th May 2010, 13:02
  3. ADC question
    By Srigopal007 in forum mel PIC BASIC Pro
    Replies: 11
    Last Post: - 8th June 2007, 09:52
  4. A question about ADC (using Pic16f876)
    By mimmmis in forum mel PIC BASIC Pro
    Replies: 2
    Last Post: - 2nd April 2007, 16:26
  5. ADC question
    By schu4647 in forum mel PIC BASIC Pro
    Replies: 2
    Last Post: - 28th May 2006, 14:15

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