PDA

View Full Version : Weird Random problem



Del Tapparo
- 14th August 2012, 23:15
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.


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?

Del Tapparo
- 15th August 2012, 22:06
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.