microcontroller as delay timer

Thread Starter

fisho

Joined Nov 4, 2008
18
Hi there

i'm working on a flour filler machine. 've designed the software and the hardware clean. it should generate a delay of exactly 0.54sec. every time a foot switch is pressed.it works fine for some time and then generates more or lesser delay thus affecting the specified amount of flour to be packed. i appreciate your help.

Fish
 

Thread Starter

fisho

Joined Nov 4, 2008
18
problem is this is a very old machine which has been working for over 25 years.no load cell no mechanical balance is sought in the design. there is a clutch and brake system to run or disable the feeder spindle .sorry for using too mechanical terms here.
 

Thread Starter

fisho

Joined Nov 4, 2008
18
the code is as shown below.there are push buttons to calibrate the exact time at start up. declaration part not shown here.

org 0000h
goto start
start bsf status,5
movlw 1fh
movwf trisa
movlw 60
movwf trisb
bcf status,5
clrf portb
clrf porta

pedal1 btfsc porta,4
goto pedal1
movlw 10
movwf temp1
bsf portb,7
call delay1
bcf portb,7


chk1 btfss porta,1
call incr1
btfss porta,3
call decr1
btfss porta,0
goto prog1
goto chk1
incr1 btfsc porta,4
goto incr1
movlw 1
addwf temp1,f
bsf portb,7
call delay1
bcf portb,7
return
decr1 btfsc porta,4
goto decr1
movlw 1
subwf temp1,f
bsf portb,7
call delay1
bcf portb,7
return

prog1 clrf portb
clrf porta

engage1 btfsc porta,4
goto engage1
clrf portb
bsf portb,7
call delay1
bcf portb,7
btfss porta,4
call beep
btfss porta,0
goto disch
call wait
goto engage1
disch bsf portb,7 ;manual discharging
btfss porta,0
goto engage1
goto disch
wait call delayx
return

beep btfss porta,4
goto beep

chkup btfsc porta,4
goto chkup
return
delay1 movlw 0
clrf count3
movf temp1,w
movwf count3
cycle movlw 71
movwf count2
clrf count1
dy2 decfsz count1,f
goto dy2
decfsz count2,f
goto dy2
decfsz count3,f
goto cycle
return
delayx movlw 1
movwf count3
clrf count2
clrf count1
dyx decfsz count1,f
goto dyx
decfsz count2,f
goto dyx
decfsz count3,f
goto dyx
return

end
 

BMorse

Joined Sep 26, 2009
2,675
why not use timer interrupts to generate delay timings???? would be a lot more "precise"....


What uC are you using?
What oscillator are you using?

Do you have a circuit schematic or sketch?


My .02
 

Thread Starter

fisho

Joined Nov 4, 2008
18
as i mentioned earlier portb bit 7 is used to drive an electromagnet via driver transistor.porta,0,1,2,3 &4 are inputs from pushbuttons and from pedal switch.

many thanks for quick response
 

Thread Starter

fisho

Joined Nov 4, 2008
18
Hi there

i'm working on a flour filler machine. 've designed the software and the hardware clean. it should generate a delay of exactly 0.54sec. every time a foot switch is pressed.it works fine for some time and then generates more or lesser delay thus affecting the specified amount of flour to be packed. problem is this is a very old machine which has been working for over 25 years.no load cell no mechanical balance is sought in the design. there is a clutch and brake system to run or disable the feeder spindle .sorry for using too mechanical terms here.
PIC 16f84a; 4Mhz crystal
 

Papabravo

Joined Feb 24, 2006
21,225
OK so you don't want to do interrupts, that's OK as long as you don't have much else going on. Here is the secret. You want a way of measuring FIXED intervals. I capitalize "FIXED" because that is the key. If you have a free runing timer register that gets incremented at some rate you need to:
  1. Sample the free running timer and save the value
  2. Add the FIXED offset to the value sampled in 1.
  3. Sit in a loop comparing the present value of the timer to the value that the timer will be when the fixed interval expires.
  4. When the present value is greater than or equal to the expiration time -- perform your action. BTW there needs to be a subtraction to perform this test.
  5. Add the FIXED offset to the saved expiration time (NOT the present value of the free running timer) and goto step 3.
If for some reason you get behind, chances are you will catch up on the next cycle. The jitter if any will be on the order of the time it takes to execute the wait loop. It should be within microseconds of 0.54 seconds. Is that good enough or do you require femtosecond accuracy?
 

Thread Starter

fisho

Joined Nov 4, 2008
18
how can i use the PIC 16F84A as a good delay timer without jitter.tried the following code portb,7 as output to drive solenoid for some specified period(0.54 sec)upon pressing a pedal switch. works fine for several cycles and then loses consistency

code is attached X-tal 4Mhz
 

Attachments

hgmjr

Joined Jan 28, 2005
9,027
fisho,

Please keep your related threads together.

If you spawn multiple threads on the same topic you will be unlikely to get a coherent response.

hgmjr
 

Papabravo

Joined Feb 24, 2006
21,225
how can i use the PIC 16F84A as a good delay timer without jitter.tried the following code portb,7 as output to drive solenoid for some specified period(0.54 sec)upon pressing a pedal switch. works fine for several cycles and then loses consistency

code is attached X-tal 4Mhz
I guess you did not like my answer. Did you at least understand my answer to your question?
 
Top