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

have

consider

Honestly, I hadn't looked at it until now. Since he uses structs and a long divide, I'm not real surprised on the space requirements. Personally, I don't use C on a PIC since the hardware is not really up for it without allot of hoop jumping by the compiler. The 18F type PICs are more capable in this regard. So to each his own. I've used C on

8052's and I liked it, but it was a good compiler too (keil).

any

hardware

Everybody messes up software, 'cept me of course. ;-) I'm surprised that John seemed to take offense to my comment. I really wasn't trying to upset anyone, hence the smiley.

I would say that it's pretty selfless of Bruno to maintain a web site for the benefit of others.

Reply to
Anthony Fremont
Loading thread data ...

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

Reply to
Lee Philips

a écrit dans le message de news: snipped-for-privacy@p10g2000cwp.googlegroups.com...

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

formatting link

Reply to
BrunoG

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.
--
--
kensmith@rahul.net   forging knowledge
Reply to
Ken Smith

depends on the PIC

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

Bye. Jasen

Reply to
Jasen Betts

"Ken Smith" a écrit dans le message de news: duio2h$uo$ snipped-for-privacy@blue.rahul.net...

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

formatting link

Reply to
BrunoG

Why would that confuse anyone?

Reply to
cbarn24050

a écrit dans le message de news: snipped-for-privacy@e56g2000cwe.googlegroups.com...

They could believe that it is possible. I'm afraid this discussion could bore other people, so if you want to continue it, please give at least some technical argument or discuss it in private :

formatting link

Thanks, Bruno

Reply to
BrunoG

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

Reply to
Anthony Fremont

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

Reply to
Silvester

ys.html

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

Reply to
cbarn24050

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

formatting link

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.

--

----== Posted via Newsfeeds.Com - Unlimited-Unrestricted-Secure Usenet News==----
http://www.newsfeeds.com The #1 Newsgroup Service in the World! 120,000+
Newsgroups
----= East and West-Coast Server Farms - Total Privacy via Encryption =----
Reply to
default

--
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?
Reply to
John Fields

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

formatting link

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.

Reply to
John_H

--
_Always_ has been, for me! :-)
Reply to
John Fields

formatting link

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

Reply to
The Real Andy

his

elays.html

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.

Reply to
cbarn24050

a écrit dans le message de news: snipped-for-privacy@e56g2000cwe.googlegroups.com...

Good cbarn you are right, this time I do agree with you.

This is the same with only 7 lines :

formatting link

Thanks

Bruno

Reply to
BrunoG

formatting link

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

Reply to
Rich Grise

One thing I don't like about this is that the callback happens at interrupt level. This will force the callback user to lock his data structures, and possibly cause interrupt latency problems if the 'user' isn't careful about how long he keeps control in that callback.

PIC programs are nearly always busy loops, which check for timers or port changes, and do something in response. Having an interrupt that ticks away the timers, and sets a bit for the busy loop to check makes more sense, and is easier to use in a broad range of projects. You can supply an API to check the bit, or just document the bitmap, which can then be used as a quick way to test whether any timer has expired.

--
Regards,
  Bob Monsen

Insanity: doing the same thing over and over again and expecting
different results.
    Albert Einstein, (attributed)
Reply to
Bob Monsen

ElectronDepot website is not affiliated with any of the manufacturers or service providers discussed here. All logos and trade names are the property of their respective owners.