strange adc question


Closed Thread
Results 1 to 2 of 2
  1. #1
    Join Date
    Oct 2005
    Posts
    14

    Unhappy strange adc question

    I need some help here, i'm getting crazy

    i want to read 2 adc channels and sent the data serial out,

    if it moves uit of center ( >140 or <115) of any of 2 channels it should sent the data out

    But when channel X goes out of center up over 140 and it returns to center within 0,5 second (very fast center => Up => center), it should sent a "short"signal once .

    but somehow i can't seem to get it work al the time

    Here's what comes closes en work 80%, because after a up over 140 longer than 0,5 seconds it does not reset after it reaches center again, then i first got to move X under 115 for it actually resets the tip1 counter.

    what am i doing wrong, or who has a simpler solution, because i want it to work on 4 different directions with different short out commands

    My try so far:

    pic16F876 at 8 mhz:


    clear
    define osc 8
    include "modedefs.bas"
    DEFINE HSER_RCSTA 90h
    DEFINE HSER_TXSTA 24h
    DEFINE HSER_SPBRG 51

    DEFINE ADC_BITS 8
    TRISA = 255
    ADCON1 = 0
    trisb=%11000000
    trisc=%00000001
    portb=0

    joy_x var byte
    joy_y var byte

    uit_x var byte
    uit_y var byte

    tip1 var word
    tip2 var word
    tip1=0
    tip2=0

    main:

    ADCIN 2, uit_x
    adcin 3, uit_y




    if (uit_x > 145) then 'x out of center going up
    pause 100
    tip1=tip1+1
    if tip1 < 10 then tip2=1 'shorter than 0,5 second
    endif
    if (uit_x < 140) and tip2=1 then 'x is back to center
    hserout ["short"]
    pause 10
    portb.1=1
    pause 100
    portb.1=0
    tip2=0
    endif


    if (uit_x > 140) or (uit_x < 115)or (uit_y > 140) or (uit_y < 115) then
    portb.0=1
    hserout ["data",uit_x,uit_y]
    portb.0=0
    if (uit_x < 140) and (uit_x > 110) and (tip1 > 11) then tip1=0
    endif

  2. #2
    Join Date
    Jan 2006
    Location
    Istanbul
    Posts
    1,185


    Did you find this post helpful? Yes | No

    Default

    Hi Maus,

    If you want to send a signal once, then have a flag variable.
    Once you sent the short signal then set the flag; ShortFlag = 1.

    The next time loop comes back, you check the flag status, thus you won't send the signal again.


    -------------------
    "If the Earth were a single state, Istanbul would be its capital." Napoleon Bonaparte

Similar Threads

  1. PIC16F690 ADC question
    By matador29b in forum mel PIC BASIC Pro
    Replies: 2
    Last Post: - 23rd October 2009, 23:03
  2. Strange ADC behaviour
    By ruijc in forum mel PIC BASIC Pro
    Replies: 28
    Last Post: - 12th December 2007, 20:03
  3. Newbie HPWM / ADC question
    By Johan in forum mel PIC BASIC Pro
    Replies: 8
    Last Post: - 25th June 2007, 12:52
  4. ADC question
    By Srigopal007 in forum mel PIC BASIC Pro
    Replies: 11
    Last Post: - 8th June 2007, 09:52
  5. A question about ADC (using Pic16f876)
    By mimmmis in forum mel PIC BASIC Pro
    Replies: 2
    Last Post: - 2nd April 2007, 16:26

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