>Thus spake Kerzer Computers (
kerzer
KILLspamSAMARA.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
>
.....clydeKILLspam
.....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/
>
>