Timers, Counters and Displays

Thread Starter

IGill

Joined Jan 5, 2013
27
Can anybody recommend a good book or website which explains various timers, counters and displays?

I've already done some experiments with 555s, decade counters and 7 segment displays, but it is all basic stuff.

There seams to be a plethora of all these components and I want to find out what does what with what. The problem with reading data sheets is that they kind of expect that you know what you are looking for before you read them and I don't.

You may ask what I want to build, but at present there is nothing specific. I want to try building a clock, a frequency timer, ultrasonic distance measurer and others. These are all ideas that are bouncing around in my head at present but they all require an understanding of timers and counters and if I want an output, displays.

Any help would be appreciated.
 

THE_RB

Joined Feb 11, 2008
5,438
For those projects you are best off working with a microcontroller, where you write code to do the timing/counting task you desire and just connect a display to it. Most microcontrollers can run from a xtal and will give very exact timings internally, if you write good code.
 

Thread Starter

IGill

Joined Jan 5, 2013
27
Thanks for that. I am really interested in the prospect of using microcontrollers and want to work my way toward this.

At the moment however, I am fairly new to electronics and if I jump straight into using mocrocontrollers will I be missing some important stages in my education?

How difficult is it to programme PICs? I have been using basic in one way or another since my first Commadore 64 in the 80s but I have never used C or assembler. I assume that the logic will be the same.
 

takao21203

Joined Apr 28, 2012
3,702
Not difficult if you understand the way they are built, A), and if you understand what you want to build B).

I recommend to get some 16f5x (16f54, 16f57, 16f59).

They are easy to work with.

Once you are familiar with the I/O ports, the clocking, and the ICSP, you can try with more advanced chips.

MPLABX includes source code templates, which do work and it saves you from not being able to get the ball rolling.

One thing, you need to uncheck "Calibrate Oscillator". For most PICs.

The datasheet for 16f5x also is only 50 pages. Download some other datasheets, and you see the difference. 300 pages- you don't always know where to look for what.

The digital I/O (tristate, accessed via register file) is all the same. Most of the programming for PICs is dealing with manipulating the digital I/O.

More complex PICs also have so-called peripherals. They are not essential actually to use PICs or getting started with them.

If you look at datasheets for 18F PICs, you see register banks stretching over pages. 16f5X- only a very few. Once you understand about it, move on.

C language is wrapping the low level access a bit but you still need to understand about the register file banks. For instance you do not need to set the banking bits manually as in assembler.

The difficulty is to fully understand what a PIC actually can do (and what not, perhaps). And even to know about the different PIC families.

If you fancy, maybe jumpstart with 18F. Get a demo board from Microchip for that, it will include source code already to look at.

I started using C one day, when I wanted to use an USB PIC. Was a matter of one day (even if it was not so easy as I did not use a ready made board).

Before of that I used assembler which I do not recommend.
 
Last edited:

THE_RB

Joined Feb 11, 2008
5,438
...
At the moment however, I am fairly new to electronics and if I jump straight into using mocrocontrollers will I be missing some important stages in my education? ...
Personally I think the sooner the better. Trying to make timers with logic chips and counters is very difficult compared to doing it with C code like this;

Rich (BB code):
Delay_exact_second();
secs = secs+1;
if(secs >= 60) 
{
secs = 0;
mins = mins+1;
}
...
How difficult is it to programme PICs? I have been using basic in one way or another since my first Commadore 64 in the 80s but I have never used C or assembler. I assume that the logic will be the same.
Like Takao I would also suggest starting in C, and getting a C compiler and a simple plug-n-play type programmer.

The programming is easy, you just plug it in and press "go". :)

Writing the code is a bit harder but if you start with some GOOD examples of simple C code projects from other people (like how to blink a LED, how to blink a LED at exactly 1 second, etc) you should find it easy enough to adapt their code to suit your timer tasks.

There will always be a steep part of the learning curve at first, but since you have BASIC language experience it should be easy enough.
 

takao21203

Joined Apr 28, 2012
3,702
The cold start with C can be challenging even you already have coding experience.

It is for instance also known as the "Combined Language".

C language offers assembler-like capabilities, namely to do pointer arithmetic. The big advantage is platform independence.

You can do almost everything what you can do in assembler.

The main drawback is execution speed. Lately multi-core CPUs are used- that was the solution.

It is nearly unthinkable to program a parallel GPU in it's native assembler.

High-level abstraction and virtualization are essential.

You could if you are ambitious look at the NVIDIA website for CUDA. It is quite an interesting technology.

The advance of economic controllers opens so many new types of circuits, and we are just at the beginning.

One day small controllers will be standard like today 74xx is a well established, well known and understood standard.

Build some 74xx stuff but see the purpose and don't get caught by it. Once you understand the basics, move on.
 

Thread Starter

IGill

Joined Jan 5, 2013
27
Thank you both very much for your advice.

I have looked at the data sheet and done some digging and I think that I am going to try a PICkit 2 Starter Kit. This seams to have all I need to try and get my head around the basics of using PICs.

At the same time I am going to look into using some 74xx ICs so that I can learn both systems.

Again, thanks for the help.
 

Brownout

Joined Jan 10, 2012
2,390
Thank you both very much for your advice.

I have looked at the data sheet and done some digging and I think that I am going to try a PICkit 2 Starter Kit. This seams to have all I need to try and get my head around the basics of using PICs.

At the same time I am going to look into using some 74xx ICs so that I can learn both systems.

Again, thanks for the help.
Get the PIC3 starter kit. PIC2 is obsolete. BTW, I think you're right to try electronics before microcontrollers. There are pleanty of tutorials on 555 timers, etc. and anything you don't understand, just ask. You might start by googling 555 timer and Tony Van Roon. He put up some execellent articles.

PS: I just did this, and here is my personal favorite: http://www.sentex.ca/~mec1995/gadgets/555/555.html Just ask about anything you don't understand.
 

takao21203

Joined Apr 28, 2012
3,702
STM8 is a good alternative to students, hobbyists, and beginners.

As the investment is much lower.

I won't advice against mixing classic analogue stuff with controllers from the start.

The Microchip forum is mainly meant to be for professional users, also producing a bulk of PCBs.

Freescale even- you won't find many hobby users there at all.

They both have a mature customer base already.

In recent years Microchip produced things like the USB stack, which are a workable starting point. Quite good, saves you a lot of unneccessary work. Just design your original application.

PICKIT3 can be bought as clone for about 30 dollar. I have the original here with red case, and it is way more stable than the PICKIT2 (which I managed to render unuseable after a while). It can be a bit pricy but it is worth to look around or even get it directly from Microchip.

It can really program all PICs so a very useful tool. Only can recommend it.

If you don't want to pay so much for a start, get the STM8, for instance to see if you want to use controllers from the beginning on.
 

ErnieM

Joined Apr 24, 2011
8,377
The PICkit 2 starter kit is a fine place to start. I have both the PICkit 2 and 3 and prefer the 2... though I do get stuck using the 3 for the newer PICs. There are several formal lesson plans to run the hardware on the board... a button, LED, and a pot as I remember. The lessons are in assembler, I don't think they have them in C. While some advise to start with assembler I don't see it as any great advantage, but it is a fine place to start, and you can then have the challenge of rewriting the tutorial tasks in C.
 

thatoneguy

Joined Feb 19, 2009
6,359
I also suggest the PICKit 2, and BoostC to start out. BoostC (free version) has a ton of examples and supports PIC12-PIC18.

Once you need something more advanced, get the PICKit 3 and C32 or similar.

Otherwise, you will sink a good deal of money into something you may not like.
 

Brownout

Joined Jan 10, 2012
2,390
Microchip direct has the pickit 2 starter kit priced the same as the pickit 3. Pickit 3 is a more updated version, and can program more chips.
 

Thread Starter

IGill

Joined Jan 5, 2013
27
Is the assembler language easier to pick up that C?

It seams that I have three things to learn.

1) what any particular PIC will do,
2) how to integrate this into the use of other ICs and components
3) learn how to program the PICs

If assembler is easier than C, I think it may be better so start off with this. Once I have got to grips with the 3 steps above, then progress to using C.

Does this sound like a good plan?
 

Thread Starter

IGill

Joined Jan 5, 2013
27
I have done quite a few projects with 555 chips and know how versatile they are. Thanks for the suggestions and link, its very useful.
 

Brownout

Joined Jan 10, 2012
2,390
Is the assembler language easier to pick up that C?
No. Assembly will drive you crazy. C is easier, more portable and universal. We have some assembly evangelists who will disagree

It seams that I have three things to learn.

1) what any particular PIC will do,
2) how to integrate this into the use of other ICs and components
3) learn how to program the PICs
Start with the easiest, #3. When you get to the other, there is lots of help available here.

If assembler is easier than C, I think it may be better so start off with this. Once I have got to grips with the 3 steps above, then progress to using C.

Does this sound like a good plan?
I would start with C, and then move to assembly if necessary. I've never had any reason to program in assembly, as C does a fine job and is much much easier. Any assembly programming I've done was strictly achedemic.
 

ErnieM

Joined Apr 24, 2011
8,377
Is the assembler language easier to pick up that C?

It seams that I have three things to learn.

1) what any particular PIC will do,
2) how to integrate this into the use of other ICs and components
3) learn how to program the PICs

If assembler is easier than C, I think it may be better so start off with this. Once I have got to grips with the 3 steps above, then progress to using C.

Does this sound like a good plan?
Ummm... it depends if you've done any programming as of yet. Assembler is the very hardest way to write a program, as the instructions themselves hardly do anything, so even the simplest task involves writing a larger routine. Assembler can add and subtract 8 bit numbers... to do anything else you need to write the code to do that.

On the one hand PIC16 and lower chips only have 33 instructions to learn, PIC18 and above have lots more. I've never taken the time to learn PIC18 assembly, I use C for that.

Either the PICkit 2 or 3 come with a small board with a PIC to program, which is as simple as plugging the PICkit into it, which also will power the circuit.

I would say learning C is simpler for a beginner, less land mines and it does more. So I would advise you for the PICkit 3 demo, but don't think the 2 is a bad or wrong choice either. Just a preference.

My long winded comparison of PICkit 2 vs 3.
 

takao21203

Joined Apr 28, 2012
3,702
C and assembler are not totally different languages.

C is a way to automatize it. No longer is it neccessary to partition memory manually.

C is providing basic types such as char, int, and long all over the existing hardware platforms. Be it a small 8bit hobby circuit, or a software on a Windows PC. It is portable.

8086 assembler is not so bad for instance you can do a multiplication or address memory.

PIC RISC assembler requires you to use 20 instructions for each C line. The readability is very poor.

It is quite ridiculous to program PIC in their native assembler manually. Not for small programs maybe but as soon as you have 2000 lines or so, you will get a problem. The more tricky and optimized the assembler code you write, the harder to remember.

In a single line: Forget about it all together. If you learned C of course you will be able to understand what an assembler instruction is doing.
 

tshuck

Joined Oct 18, 2012
3,534
C and assembler are not totally different languages.
They are entirely different languages!
In a single line: Forget about it all together. If you learned C of course you will be able to understand what an assembler instruction is doing.
What!? This is completely backwards! Understanding assembly will allow the C user understand the underlying mechanics. C obfuscates the mechanics of moving and swapping register contents in order to accomplish a more complex C instruction like pow() or string concatenation.

The PIC understands opcodes derived from the assembly, not C.

I will however agree that C is easier for a beginner, though a true understanding of the mechanics of the device can be attained from learning assembly first.
 

Brownout

Joined Jan 10, 2012
2,390
understanding of the mechanics of the device can be attained from learning assembly first.

Don't know about that. My first language was BASIC. However, I still recomment a noob start with C and then move to assembly only after getting a firm grasp on the higher C language. If for no ohter reason than this; C get him up and running, and he is much less likely to bug out (pun intended) He can still understand the mechanics by playing with assembly later, if need be. I never needed to learn it to that level to accomplish what I want.
 
Top