The above code works great. 50% of the time the "whistle" will blow, which is the goal.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
R_Num and R_Num_Seed are words'Code:R_Num_Seed = R_Num_Seed + 1 Random R_Num 'shake the dice Percent = (R_Num//100)+1 'scale 1 to 100
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?




Bookmarks