Searching \ for 'two little ones and a BIG one, what ?... ALSO' in subject line. ()
Make payments with PayPal - it's fast, free and secure! Help us get a faster server
FAQ page: massmind.org/techref/index.htm?key=two+little+ones
Search entire site for: 'two little ones and a BIG one, what ?... ALSO'.

Truncated match.
PICList Thread
'two little ones and a BIG one, what ?... ALSO'
1997\01\06@061425 by Kerzer Computers

flavicon
face
I forgot to mention that the inputs need to be monitored all the time, and
call certain routines  depending on their status, all while the timers are
running.


Using a PIC16C84, How do detect two pulses in a  one second  time frame,
check that they are both longer than 100ms and wether or not  they occurred
in half a second or one  second. And to really complicate things, run two
independant timers, one between 1/2 and 4 hours, and the other between 3 and
10 minutes ? Each  one resetable by the pulse train in the begining of this
query ?Are you  able to give me some advice or some code please ? Please
mail me direct so the list does not get cluttered up. Thankyou

Gordon

1997\01\06@064159 by Clyde Smith-Stubbs

flavicon
face
Thus spake Kerzer Computers (spam_OUTkerzerTakeThisOuTspamSAMARA.CO.ZW):

> Using a PIC16C84, How do detect two pulses in a  one second  time frame,
> check that they are both longer than 100ms and wether or not  they occurred
> in half a second or one  second. And to really complicate things, run two
> independant timers, one between 1/2 and 4 hours, and the other between 3 and
> 10 minutes ? Each  one resetable by the pulse train in the begining of this
> query ?Are you  able to give me some advice or some code please ? Please
> mail me direct so the list does not get cluttered up. Thankyou

This is a reasonable question to answer on the list; that's the point of the
list, is that more more people can learn by listening.

I would approach this problem by performing everything in a big loop,
calling subroutines as appropriate, but doing things in a very fixed
order. The loop should be synchronized to the timer such that at
the beginning of the loop you wait for timer overflow, then reset the
timer to a value to overflow again in a certain time. This is the minimum
resolution of the system - in your case if 100ms is the smallest time you
need to measure, set the loop time to something less than this, e.g. 5ms.

Make the loop work like this:

       Wait for overflow;
       Reset timer;
       Update software timer 1;
       Update software timer 2;
       Check input status; if changed start a software timer
               to measure pulse length;
       etc...

Everything is timed from the basic loop duration - e.g. the 2 independent
timers are done as software timers, using however many bytes of counter as
needed, in units of 5ms or whatever the main loop is. Make sure you can
do everything in the loop in 5ms - if not, do some things only on alternate
loops or less often - use a state variable to divvy up the work, i.e. have
a byte that is incremented each loop time; if bit 0 of the state variable
is set, do things that you need done every second loop time, if bits 0-2
are all set do things you need done every 8th loop (40ms) etc.

This kind of structure will guarantee determinism (but be sure you do not
exceed the loop time - you can check for this by checking the hardware timer
value at the beginning of the loop - if it has already overflowed you took
too long - also toggle an output and watch it with a CRO - look for long
pulses) and is easy to add new tasks, without the overhead of true
multi-tasking. It is likely you will not need interrupts (which add
non-determinism) or at least use interrupts only for very minimal
stuff.



--
Clyde Smith-Stubbs    | HI-TECH Software,       | Voice: +61 7 3354 2411
.....clydeKILLspamspam@spam@htsoft.com      | P.O. Box 103, Alderley, | Fax:   +61 7 3354 2422
http://www.htsoft.com | QLD, 4051, AUSTRALIA.   |
---------------------------------------------------------------------------
Download a FREE beta version of our new ANSI C compiler for the PIC
microcontroller! Point your WWW browser at http://www.htsoft.com/

1997\01\06@083458 by Kerzer Computers

flavicon
face
I am really new at this, can you explain in more detail please ?


At 21:39 6/01/97 +1000, you wrote:
{Quote hidden}

1997\01\07@163618 by Bryan Hord

flavicon
face
Maybe I can help answer this one.  I hope this isn't too long for the list.
The project I worked on had eight timers and about seven inputs to process
in "real time".  The processor is the 16C57 so I'm sure you'll have greater
flexibility with the '84.

The main event loop is executed as fast as it takes to get throught the
instructions.  The time to get through the event loop is less than the loop
timer.

In this case the loop timer was set to about 7mS.  'check timers' and some
hardware configuring is done every cycle of the loop while only one state is
active.

All of this only works if you can afford a lower resolution of your time
measurment.  In this example the best resolution of a button press is 7mS.
If your timing requirements are minutes or hours then maybe +/- 7mS is OK.
You can also change the loop timer around to meet your needs.


It looks kind of like this:
________________________________________________________________

Start of program
       ;---- initialize all hardware ----
       blah
       blah
       blah

       ;=======================================
       ;=      TOP OF HEADSET EVENT LOOP      =
       ;=======================================
Top_of_event_loop

       ;---- reset watchdog timer ----
       clrwdt
       ;---- do some hardware checking ----
       blah
       blah
       blah

       ;---- check all timers ----
       PAGE_2
       goto    Check_Timers
timersReturn

       ;---- This is the state processing section
       ;---- A variable 'state' is compared to a constant 'STATEx'
       ;---- if they match then that 'State' is processed.
       ;---- Changeing states is done inside the current state.
       ;---- Check Program State ----
       movlw   STATE1
       subwf   state, W
       JNZ     stState2
       PAGE_2
       goto    State_1
stState2
       movlw   STATE2
       subwf   state, W
       JNZ     stState3
       PAGE_2
       goto    stState2
       .
       .
       .
       .
       ;---- add as many states as you want as long as the processing time
for any one         ;---- state doesn't take longer than the loop timer.
       .
       .
       .

stateReturn

      ;---- do some hardware checking ----
       blah
       blah
       blah

       ;---- check battery ----
       goto    Check_Battery_Low
Check_Battery_Low_Return
       ;---- check Shut Down ----
       goto    Check_ShutDn
Check_ShutDn_return


       goto    Top_of_event_loop

       ;=======================================
       ;=      END OF HEADSET EVENT LOOP      =
       ;=======================================

_______________________________________________________________

Here are the inputs and timers routine.  There is one example of the battery
input signal and associated debounce and shutdown timer but you can add a
lot more inputs and timers in here if you need them.

________________________________________________________________

;*************************************************************
;       GOTO:   Check_Timers
;*************************************************************
Check_Timers
       BANK_0
       movf    RTCC, W                 ; get timer value
       subwf   RTCC_last, Same         ; if RTCC_last > RTCC, C=1, Z=0 (overflo
w)
                                       ; if RTCC_last = RTCC, C=1, Z=1
                                       ; if RTCC_last < RTCC, C=0, Z=0
       movwf   RTCC_last               ; save for next time
       JZ      check_out               ; if RTCC_last = RTCC, then return...
       JNC     check_out               ; if RTCC_last < RTCC, then return...

       ;==================================
       ;    PROCESS 8ms TIMER EVENT!!!
       ;==================================

       ;--------------------------------
       ;    DEBOUNCE VARIOUS SIGNALS
       ;--------------------------------

       ;==== debounce Battery Low signal ====

       ;---- set C to port value ----
       btfsc   PORT_LOWBATT, _LOWBATT
       STC
       btfss   PORT_LOWBATT, _LOWBATT
       CLC
       ;---- shift into 'battlow_history' byte and mask unused bits ----
       rlf     battlow_history, W
       andlw   7fh                     ; 7 bits = 7 * 8ms debounce = 56ms
       movwf   battlow_history
       ;---- if all bits are same, then set 'battery_low' flag ----
       btfsc   STATUS, Z               ; skip if battlow not 0
       bcf     flag2, battery_low      ; *** battery_low = 0 ***
       movlw   7fh
       subwf   battlow_history, W
       btfsc   STATUS, Z               ; Z set if all 1's
       bsf     flag2, battery_low      ; *** battery_low = 1 ***

;------------------------------
;    PROCESS VARIOUS TIMERS
;------------------------------

       ;==== process 'Battery_low_timer' ====
       ;---- is timer > 0? ----
       movf    Battery_low_timer_l, Same
       JNZ     battlow_active                  ; timer active...
       movf    Battery_low_timer_h, Same
       JZ      battlow_done                    ; timer not active...
battlow_active
       ;---- decrement 16-bit timer ----
       DJNZ    Battery_low_timer_l, battlow_done
       movf    Battery_low_timer_h, Same
       JZ      battlow_expired                 ; if timer expired...
       decf    Battery_low_timer_h, Same       ; else decrement
       decf    Battery_low_timer_l, Same       ; (decr to prevent timer=0)
       goto    battlow_done                    ; and we're done...
battlow_expired
       ;---- Battery low timer expired!  Beep the speaker ----
       PAGE_3                          ; routine located in ROM page 3
       movlw   BEEP_BATTLOW
       call    Beep                    ; Beep(batterylow)
       PAGE_2                          ; back to ROM page 2
       BANK_1                          ; and back to RAM bank 1
battlow_done

check_out
       BANK_0                          ; restore RAM bank to 0
       PAGE_0
       goto    timersReturn


At 01:10 PM 1/6/97 +0200, you wrote:
snip
{Quote hidden}

-----------------------------------------------------------------------------
EraseMEbryanspam_OUTspamTakeThisOuTwllink.com
Wireless Link Corporation
-----------------------------------------------------------------------------

More... (looser matching)
- Last day of these posts
- In 1997 , 1998 only
- Today
- New search...