Can you post your whole code? I am making a guess the problem is in the variable size some where. Or in the ADC setup. And the routine "INITIALIZE" seems to be missing.
When you post code. the use of code tags helps.
Can you post your whole code? I am making a guess the problem is in the variable size some where. Or in the ADC setup. And the routine "INITIALIZE" seems to be missing.
When you post code. the use of code tags helps.
Dave
Always wear safety glasses while programming.
'Definitions'
DEFINE OSC 4
DEFINE ADC_BITS 10 ' set number of bits in result
DEFINE ADC_CLOCK 3 ' set clock source
DEFINE ADC_SAMPLEUS 50 ' set sampling time for microseconds
'Definitions'
'Register Initializations'
ADCON0 = %10001011 ' set as right justified and turn on AD
ANSEL = %01001100 ' A to D on AN2 and AN3
CMCON = %00000111 ' set all pins to digital
TRISIO = %00011111 ' define Inputs and Outputs
GPIO = %00000000 ' set all pin states to off
WPU = %00000000 ' shut off weak pull ups
'Register Initializations'
'Variables'
LOAD_OUT VAR GPIO.5
OFF_COUNTER VAR WORD
ON_COUNTER VAR WORD
AD_AN2_VALUE VAR WORD
AD_AN3_VALUE VAR WORD
i var word
K VAR WORD
'TEST_TRIGGER VAR GPIO.3
'TEST_COUNTER VAR WORD
CYCLE_COUNTER VAR WORD
OFF_TIME VAR WORD
'Variables'
'************************************************* ***************************
'************************************************* ***************************
INITIALIZE:
GOSUB READ_A_D_AN2
GOSUB READ_A_D_AN3
MAIN:
GOSUB ON_RUN
pause 10
GOTO MAIN
ON_TIME:
PAUSE 250 ' low end pause time (0.25 sec)
for i = 0 to ON_counter step 1 ' high end pause loop time (25 sec)
GOSUB READ_A_D_AN2
GOSUB READ_A_D_AN3
PAUSE 27
nEXT I
RETURN
OFF_TIME_RUN:
' PAUSE 5000
for K = 0 to OFF_TIME step 1 'total pause loop time
GOSUB READ_A_D_AN3
GOSUB READ_A_D_AN2
GOSUB OFF_TIME_CALC
PAUSE 33
nEXT K
RETURN
ON_RUN:
LOAD_OUT = 1
GOSUB ON_TIME
GOTO OFF_RUN
OFF_RUN:
LOAD_OUT = 0
GOSUB OFF_TIME_CALC
GOSUB OFF_TIME_RUN
GOTO INITIALIZE
OFF_TIME_CALC:
OFF_TIME = (CYCLE_COUNTER - ON_COUNTER) '+ 100
IF OFF_TIME < 120 THEN OFF_TIME = OFF_TIME + 150
if OFF_TIME = 1024 THEN OFF_TIME = OFF_TIME + 180
' if OFF_TIME > 2000 THEN OFF_TIME = OFF_TIME - 50
RETURN
READ_A_D_AN2: 'used for ON Time Delay
PAUSEUS 50 ' wait 50 microsec
ADCIN 2, AD_AN2_VALUE ' read channel 2 to AD_AN0_VALUE
ON_COUNTER = AD_AN2_VALUE ' set counter to AD value
RETURN
READ_A_D_AN3: 'used for Cycle Time Delay
PAUSEUS 50 ' wait 50 microsec
ADCIN 3, AD_AN3_VALUE ' read channel 3 to AD_AN3_VALUE
CYCLE_COUNTER = AD_AN3_VALUE + 1024 ' set counter to AD value + 1024
RETURN
END
Hi, Glqosec
One good thing to know is what granularity ( resolution ) you need for ONtime and Cycle duration ...
Alain
************************************************** ***********************
Why insist on using 32 Bits when you're not even able to deal with the first 8 ones ??? ehhhhhh ...
************************************************** ***********************
IF there is the word "Problem" in your question ...
certainly the answer is " RTFM " or " RTFDataSheet " !!!
*****************************************
I can suggest the following approch:
Read cycle and ontime word variables
Compare the the two variables and adjust ontime to cycle if ontime is greater then cycle
IF ONTIME>CYCLE THEN ONTIME=CYCLE
If you don't want offtime=0 then you can add the proper offset
IF ONTIME>=CYCLE THEN ONTIME=(CYCLE-OFFSET)
Set high output pin
loop for for the cycle delay and check ontime
when loop reach ontime value set low output pin
continue the loop till you reach the cycle time.
Ontime will be adjustable and always within cycle time
Al.
Last edited by aratti; - 6th November 2008 at 16:07.
All progress began with an idea
Bookmarks