Continue to Site

Welcome to our site!

Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

  • Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

One Second Time Base

Status
Not open for further replies.
I assumed he wanted timekeeping accuracy so that would rule out the LM393 which has an accuracy of 10% or worse.

The MCU is still an option but it would need a crystal so the counter might be more convenient.


Hi there Hero,

Are we talking about the same chip, the LM393? That's the 8 pin version of the LM339 more or less right? How did you get an 'accuracy' of 10 percent? That depends on the circuit right?
LM339's are used for time bases for some frequency converters, even some high powered ones
that's why i ask Did i get the part number wrong perhaps?

I was saying before that if the accuracy doesnt have to be super perfect, the internal osc of the PIC can be used. That will get the initial setting close, and a little code adjustment can tune it in very close to the desired frequency. The temperature stability is pretty good too, within 1 percent over the temperature range, so at room temperature it will be very stable.
Yes, the crystal will guarantee near perfect operation though.
 
Here you go, 1 second ticker for a 16F628 in HiTech C.
Code:
#include <htc.h>
#include <pic.h>
#include<stdio.h>

__CONFIG(XT & WDTDIS & PWRTEN & BOREN & LVPDIS & UNPROTECT);

main()
{
unsigned char count;
    CMCON=7;                //turn off comparators
    TRISA=0b11111110;       //A0 output
    T2CON=0b01001101;       //Timer2 on and pre=4, post=10
    PR2=249;                //timer 2 period
    while(1)                // Loop forever
    {
        while(!TMR2IF);     //wait for timer rollover
        TMR2IF=0;           //reset flag
        count++;            //count rollovers
        if(count==50){      //0.5 seconds passed?
            count=0;        //yes, so reset count
            RA0=!RA0;       //and toggle output
        }
    }
}

Edit, forgot to mention, it's easier on the 628 as it has more timers. To use a 509 requires a different approach.

Mike.
 
Last edited:
Hi there Hero,

Are we talking about the same chip, the LM393? That's the 8 pin version of the LM339 more or less right? How did you get an 'accuracy' of 10 percent? That depends on the circuit right?
LM339's are used for time bases for some frequency converters, even some high powered ones
that's why i ask Did i get the part number wrong perhaps?
Yes, they're both the same, it's just that the LM393 is an 8 pin version and if he wants a compact solution, there'd be no point in using the 14 pin version, since he'd only be using on quarter of the IC anyway.

Typical capacitors hav an accuracy of 10%, especially in the value range required to give a 1Hz output.

I was saying before that if the accuracy doesnt have to be super perfect, the internal osc of the PIC can be used. That will get the initial setting close, and a little code adjustment can tune it in very close to the desired frequency. The temperature stability is pretty good too, within 1 percent over the temperature range, so at room temperature it will be very stable.
Yes, the crystal will guarantee near perfect operation though.
I think a PIC and crystal is probably the best option, the only advantage the counter has, is you don't need to program anything.

Jack,
What do you need the 1Hz reference for?

Surely there are other elements you could integrated in to the MCU?
 
I think a PIC and crystal is probably the best option, the only advantage the counter has, is you don't need to program anything.

Jack,
What do you need the 1Hz reference for?

Surely there are other elements you could integrated in to the MCU?

Hi Hero:

Since I have the programmer and will be doing a lot more in that area, I am going to go with the PIC option for now. Pommie's sample code will be most helpful as I will study it line by line to understand how it works.

The beauty of your original suggested circuit is, as you say, you do not have to program anything and this information will be most helpful to others reading this.

My little startup project here is for a clock/timer circuit. Back in the late 70's I built a Radio Shack clock which I still have but I think a lightning surge killed it shortly after completion and the transformer buzzes. For fun, I tried to revive it but the chip for it is way obsolete and I can not find the circuit layout for it anywhere. So, I can take it apart for it's charlieplexed display to experiment with elsewhere.

Later, I can build a nice frequency counter (something I'll need) to learn more and will most likely be looking for a highly accurate, inexpensive and stable time base. My hope is that this is a good start.
 
Yes, they're both the same, it's just that the LM393 is an 8 pin version and if he wants a compact solution, there'd be no point in using the 14 pin version, since he'd only be using on quarter of the IC anyway.

Typical capacitors hav an accuracy of 10%, especially in the value range required to give a 1Hz output.


I think a PIC and crystal is probably the best option, the only advantage the counter has, is you don't need to program anything.

Jack,
What do you need the 1Hz reference for?

Surely there are other elements you could integrated in to the MCU?

Hi Hero,

Oh yes, i see your point now. I was assuming that there was some form of adjustment available, such as a pot or parallel resistors to set the frequency to near exact. That's the way it's done in many real work applications.
I was more or less saying that with some form of adjustment the accuracy can be very good. For long term stability a silver mica is a good choice (including said adjustment feature too of course).
 
Last edited:
Status
Not open for further replies.

Latest threads

New Articles From Microcontroller Tips

Back
Top