16F877 elapsed time control


Closed Thread
Results 1 to 18 of 18

Hybrid View

  1. #1
    Join Date
    Nov 2003
    Location
    Wellton, U.S.A.
    Posts
    5,924


    Did you find this post helpful? Yes | No

    Default

    First off the ADC needs setup, here is an example.
    http://www.microengineeringlabs.com/...pbp/adcin8.bas

    Voltage...
    Lets say you are using an 8 bit ADC. Voltage reference is VDD and the PIC is running at 5 volts.
    There are 256 steps, 0 to 255.
    The ADC value of 255 will represent full scale and be 5 volts.
    The ADC value of 127 will represent 2.5 volts.
    Looking for 3 volts? The ADC vale would be 153.
    Want more accuracy? The 10 bit ADC has 1024 steps.

    Your loop. After the set up.
    Code:
    loop: 	
    ADCIN 0, adval				' Read channel 0 to adval
    IF adval <= 153 then gosub Xlabel    '3 volt and less trigger
    IF adval = 255 then gosub Zlabel    '5 volt trigger	    
    Pause 100       				' Wait .1 second
    Goto loop       				' Do it forever
    
    Xlabel:
    'Do something
    Return
    
    Zlabel:
    'Do someting
    Return
    End
    That is the basics.
    Dave
    Always wear safety glasses while programming.

  2. #2
    Join Date
    Jan 2009
    Posts
    8


    Did you find this post helpful? Yes | No

    Default

    thanks alot
    another newbie question
    can i use tmrcon istead of for loop
    such as;
    CalcTime var word
    Define LCD_DREG PORTC
    Define LCD_DBIT 4
    Define LCD_RSREG PORTB
    Define LCD_RSBIT 0
    Define LCD_EREG PORTB
    Define LCD_EBIT 2
    DEFINE LCD_BITS 4
    DEFINE LCD_LINES 2

    DEFINE ADC_BITS 10
    DEFINE ADC_CLOCK 3
    DEFINE ADC_SAMPLEUS 50

    TRISA = %11111111 ' Set PORTA to all input
    ADCON1 = %00000000 ' Set PORTA analog

    ADCINFO VAR BYTE


    '================================================= =======================

    T1CON.0=0
    TMR1H = 0
    TMR1L = 0
    ADCON1 = 0


    ADC_READ:
    PAUSE 500

    timeloop:
    ADCIN 0, ADCINFO
    IF ADCINFO => 511 THEN GOSUB STARTTIMER
    IF ADCINFO == 980 THEN GOSUB STOPTIMER
    PAUSE 100
    GOTO timeloop

    STARTTIMER:
    T1CON.0=1
    RETURN

    STOPTIMER:
    T1CON.0=0
    RETURN

    GOTO ADC_READ

    CLEARWDT
    CalcTime.Highbyte=TMR1H
    CalcTime.Lowbyte=TMR1L

    Loope:
    LCDOUT $FE, 1
    LCDOUT "t:", CalcTime
    Pause 500
    Goto loope

    GOTO ADC_READ
    END

  3. #3
    Join Date
    Sep 2004
    Location
    montreal, canada
    Posts
    6,898


    Did you find this post helpful? Yes | No

    Default

    euh yeah, but the above will never do something else than reading the ADCs?

    What do you want to do exactly?
    Steve

    It's not a bug, it's a random feature.
    There's no problem, only learning opportunities.

  4. #4
    Join Date
    Jan 2009
    Posts
    8


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by mister_e View Post
    euh yeah, but the above will never do something else than reading the ADCs?

    What do you want to do exactly?
    hmm i want it to read the adc s and there will be a voltage change from 2.5 v to 4.8 V my aim is to measure the time elapsed between 4.8 and 2.5 volts and write it to lcd

    thanks alot for helping

  5. #5
    Join Date
    Sep 2004
    Location
    montreal, canada
    Posts
    6,898


    Did you find this post helpful? Yes | No

    Default

    Any idea of the time range between both voltage?

    Looks like a kind of ESR measurement to me
    Steve

    It's not a bug, it's a random feature.
    There's no problem, only learning opportunities.

  6. #6
    Join Date
    Nov 2003
    Location
    Wellton, U.S.A.
    Posts
    5,924


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by mister_e View Post
    Looks like a kind of ESR measurement to me
    Electron Spin Resonance ?
    http://hyperphysics.phy-astr.gsu.edu...ecule/esr.html
    Dave
    Always wear safety glasses while programming.

  7. #7
    Join Date
    Sep 2004
    Location
    montreal, canada
    Posts
    6,898


    Did you find this post helpful? Yes | No

    Default

    nope, ESR meter... you know this kind of handy meter to find faulty capacitor?
    Steve

    It's not a bug, it's a random feature.
    There's no problem, only learning opportunities.

Similar Threads

  1. using a pot to control a time range
    By glkosec in forum mel PIC BASIC Pro
    Replies: 4
    Last Post: - 17th June 2008, 19:59
  2. Serout2/serin2 Pbp Problem
    By SOMRU in forum mel PIC BASIC Pro
    Replies: 3
    Last Post: - 11th December 2006, 19:55
  3. Control unlimited servos at the same time
    By mrx23 in forum mel PIC BASIC Pro
    Replies: 7
    Last Post: - 19th September 2006, 14:14
  4. Calculating elapsed time, how?
    By Eng4444 in forum mel PIC BASIC Pro
    Replies: 1
    Last Post: - 1st June 2006, 09:00
  5. Button pressed time control
    By tanero in forum mel PIC BASIC Pro
    Replies: 12
    Last Post: - 15th August 2005, 15:17

Members who have read this thread : 0

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