Maker Pro
Maker Pro

PIC : how to make multiple non-blocking delays with one timer

L

Lee Philips

Hey is that your real name or are you just a Twilight Zone fan?
 
B

BrunoG

uiu said:
Can you explain what "non-blocking" means?

Thanks!

Non-blocking is the opposite of blocking :
using blocking delay, the next code instructions will have to wait the end
of the delay to be executed (the execution of the main program is
suspended),
whereas using non-blocking delay, the next code instructions will be
executed after the start of the delay, and the delayed user code will be
called after the delay completion. Meanwhile the execution of the main
program continues.

Bruno
http://www.micro-examples.com/public/microex-navig/doc/099-timers-delays.html
 
B

BrunoG

I wasn't trying to humiliate anyone either, he asked for comments. The
fact is needing multiple delays in a program is very commonplace and
it's normaly done with a few lines. What the author produced, however
well meaning, was just terrible. Thats not a problem for most people,
they just delete it in a heartbeat but a real beginner doesn't know any
better. Iv'e shown him how to do it, if he did it again that way he
would see for himself but his pride has been hurt, that was never my
intention, and so he's gone on the defensive. Your right about hardware
engineers messing up software but then again so do software engineers.

Cbarn, I have nothing to defend. Your assumption about shortening this
code within 50 bytes may put beginners and newbies into confusion.
This is not the best service they can get from here.

Bruno
http://www.micro-examples.com/public/microex-navig/doc/099-timers-delays.html
 
K

Ken Smith

Hi,

I had many requests about pic timers, so that I wrote a little C example to
show how to make multiple non-blocking asynchronous delays with only one pic
timer :

http://www.micro-examples.com/public/microex-navig/doc/099-timers-delays.html

Is there something about a PIC that makes linked lists impractical?

The normal way to do this sort of thing is to only count away the shortest
time delay. The delays need to be in some sorted form for this to work so
a linked list is normally the way to go.

BTW: If you are doing this sort of thing in 8051 land, it is usually a
good idea to put the routines address onto the stack and do a RETI so that
the routine can be interrupted.

1000 = 250*4 so your shift can be whole bytes.
 
J

Jasen Betts

Is there something about a PIC that makes linked lists impractical?

depends on the PIC
The normal way to do this sort of thing is to only count away the shortest
time delay. The delays need to be in some sorted form for this to work so
a linked list is normally the way to go.

if there are potentially many, a heap may be better.

Bye.
Jasen
 
B

BrunoG

Ken Smith said:
Is there something about a PIC that makes linked lists impractical?

The normal way to do this sort of thing is to only count away the shortest
time delay. The delays need to be in some sorted form for this to work so
a linked list is normally the way to go.

Yes you are right, linked lists are used in OS kernels to schedule tasks,
and could be used on the PIC with mikroC.

The fact is, writing program examples leads to make choices between their
clarity and effectiveness, and too much novelties in the same program may
muddle the user with a heavier source code.

BTW, linked lists are very important and they deserve their own example
in the very near future !

Bruno
http://www.micro-examples.com/public/microex-navig/doc/099-timers-delays.html
 
A

Anthony Fremont

Lee Philips said:
Hey is that your real name or are you just a Twilight Zone fan?

;-) What about you? I thought you died in 1999?
 
S

Silvester

Electronics is not my field, so I scoured the internet to find counter
circuits, but none of what I found really hits my exact needs.


I'm looking for a 2 or 3 digit counter that will count down from a
predefined number to zero - with a RESET switch to send the count back
to
the max number.
From what little I know of binary, I firgure I could use DIP switches
to set
the maximum number that the count starts at - a bank of 8 DIP switches
gives me a max of 255.

I need to count objects passing a certain point and I figured I use a
LED emitter and receiver pair, probably IR.


Can any one offer me some help?

Silvester
 
D

default

Electronics is not my field, so I scoured the internet to find counter
circuits, but none of what I found really hits my exact needs.


I'm looking for a 2 or 3 digit counter that will count down from a
predefined number to zero - with a RESET switch to send the count back
to
the max number.

to set
the maximum number that the count starts at - a bank of 8 DIP switches
gives me a max of 255.

I need to count objects passing a certain point and I figured I use a
LED emitter and receiver pair, probably IR.


Can any one offer me some help?

Silvester


Do you want to build it or buy it? There's some simple to implement
IC's that contain presettable up/down counters used with BCD encoded
switches that contain most of what you need like the counters, digital
comparators, and latched display drivers. Plenty of "robot" sites on
the web with fairly easy to implement TV remote control style
circuitry for break beam or reflective detectors.

If you don't need a display and never intend to change the count it
may be less costly to build a discrete logic counter - but if it were
me, I'd use one of the Intersil counters.

Likewise you can get a hold of an industrial controls catalog and buy
a multifunction counter with display and optical sensor.

First option is inexpensive (in terms of money) time consuming,
educational and personally rewarding.

Second option is fast, expensive and easy. Check a Graingers catalog
for relatively cheap, ready made controls.

Build it for ~$50, buy it for ~$200

If you want to build it, look at
http://wwww.ges.cz/sheet/i/icm7217.pdf

The ICM7217 does it all in one IC and they show an LED example and LCD
adaptation.

I had an application that required a presettable count down timer to
switch a valve then start a second timer. (Intersil makes a modulus
60 counter as well as decade counters) Wiring and debugging took me
two days with the intersil parts, and another day to package it for
the lab to use. It was a breeze.

Doing the same thing with discrete logic elements would have taken me
a week or two.

I could send you schematics of my timers - but the data sheet gives
you what you need - my timer had a crystal controlled time base and
some logic circuits to stop one counter and start the second one.

Likewise I have some schematics of break beam and retro reflective
sensors.
 
J

John Fields

Electronics is not my field, so I scoured the internet to find counter
circuits, but none of what I found really hits my exact needs.


I'm looking for a 2 or 3 digit counter that will count down from a
predefined number to zero - with a RESET switch to send the count back
to
the max number.

to set
the maximum number that the count starts at - a bank of 8 DIP switches
gives me a max of 255.

I need to count objects passing a certain point and I figured I use a
LED emitter and receiver pair, probably IR.


Can any one offer me some help?

---
If you only need to count and reset and don't want a numerical
display, you could use:

http://www.semiconductors.philips.com/acrobat_download/datasheets/74HC40103_3.pdf

with, perhaps, an LED to signal that the counter had reached zero?
 
J

John_H

Silvester said:
Electronics is not my field, so I scoured the internet to find counter
circuits, but none of what I found really hits my exact needs.


I'm looking for a 2 or 3 digit counter that will count down from a
predefined number to zero - with a RESET switch to send the count back
to
the max number.

to set
the maximum number that the count starts at - a bank of 8 DIP switches
gives me a max of 255.

I need to count objects passing a certain point and I figured I use a
LED emitter and receiver pair, probably IR.


Can any one offer me some help?

Silvester

You could use a simple CPLD - programmable logic - to implement your
function to even include a 7-segment display driver if you need. The $49
development board from Xilinx

http://www.xilinx.com/xlnx/xil_prodcat_product.jsp?title=design_kit

should include everything you need to get a chip that does what you want.
If you wanted to buy the kit but not get into the details of logic design,
there are plenty of folks that could help, particularly at comp.arch.fpga
(even if it is a cpld).

You could use dip switches, 0-9 rotary swiches, even a "set" mode like on
your alarm clock though that method would lose its memory on power-cycle.

Logic design is fun these days.
 
M

Michael

Silvester said:
Electronics is not my field, so I scoured the internet to find counter
circuits, but none of what I found really hits my exact needs.

I'm looking for a 2 or 3 digit counter that will count down from a
predefined number to zero - with a RESET switch to send the count back
to
the max number.

to set
the maximum number that the count starts at - a bank of 8 DIP switches
gives me a max of 255.

I need to count objects passing a certain point and I figured I use a
LED emitter and receiver pair, probably IR.

Can any one offer me some help?

Silvester


Your project takes me back to the early 70's, when I designed and built such a
thing for my sister (and for my pleasure, of course). My circuit was a kitchen
timer. As I recall, I used TTL Up/Down decade counter chips, wired for Down
operation. Number of minutes was set by two thumbwheel switches. BCD of each
switch was latched into the respective counters upon power ON; counters were
decremented by 1 minute pulses from a counter driven by the AC line. When both
decade counters reached "0", decrement was disabled and a Sonalert was switched
on. Sis could hear that thing scream even when she was out in the back yard
mowing the grass.
 
T

The Real Andy

I allready gave you the algorithms, compile them and see for yourself.

In BrunoG's defence, what is being specified is no simple 50 line pic
assembler routine.
 
The said:
In BrunoG's defence, what is being specified is no simple 50 line pic
assembler routine.

Well Andy I didnt say the whole program would be 50 bytes, just the
parts that gives you the functionality, I hate that word, you simply
cut and paste them into your existing program. 50 lines? oh no, 50
bytes, thats 25 lines max.
 
R

Rich Grise

In BrunoG's defence, what is being specified is no simple 50 line pic
assembler routine.

Not in a PIC, no. But oh, for the days of the Motorola 68HC05/08/11 timer -
you could do an arbitrary number of timings in about a dozen lines of
code, plus maybe five lines per timer.

I did two interleaved timers on an 8008 in about 1974 or 5 or so. It's
almost trivial - you have one main loop that's calibrated, and each pass
decrement each counter and test, then either change the bit or do a
NOP or as many as you need to not mess up the timing.

But the Motorola timer is a dream, once you figure out how to use it. :)

Cheers!
Rich
 
Top