Weird Random problem


Closed Thread
Results 1 to 2 of 2
  1. #1
    Join Date
    Nov 2007
    Posts
    24

    Question Weird Random problem

    Code:
    Auto_Whistle:
       'Check for auto whistle (shares V_Bat input)
       'ADCIN Batt_Whis_ADCIN,V_Mon        
       'if ((V_Mon < ADC_Low) and (Whistle_Off_Flag = 0) and (Percent <  50)) then      <<<<<<< This is the problem line
       if ((Reed_SS_Bell = 0) and (Whistle_Off_Flag = 0) and (Percent < 50)) then
          LOW LED       'Turn LED off for diagnostics
          high Sound_Whistle
          pause 750                       
          low Sound_Whistle
       endif
    return
    The above code works great. 50% of the time the "whistle" will blow, which is the goal.

    Code:
    R_Num_Seed = R_Num_Seed + 1
       Random R_Num                         'shake the dice
       Percent = (R_Num//100)+1             'scale 1 to 100
    R_Num and R_Num_Seed are words'
    Percent is a byte.
    The random code itself has been tested and proven in several other places with different PICs.

    If I use the two commented out line for the ADC input, the result is the whistle blows about 95% of the time. Something with the ADC code is screwing up random. The actual hardware input doubles as a logic input and an analog input. I am using a PIC 18F14K22. AN2 is the analog input.
    Is something in ADC stuff clobbering the random function?

  2. #2
    Join Date
    Nov 2007
    Posts
    24


    Did you find this post helpful? Yes | No

    Default Re: Weird Random problem

    Well, I finally gave up on this code. I had the same problem with another variation of this code and fixed that one. But the first is still a head -scratcher. I'm sure it has nothing to do with ADC inputs though. Just my own doing.

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