1Hz Pulse Generator

Thread Starter

k1ng 1337

Joined Sep 11, 2020
940
Konnichiwa,

I made a 1Hz pulse generator for an ATmega328 based Real Time Clock. I am happy with the design and would like some feedback before I transfer it to a circuit board.

Questions:

1) Is there a practical advantage to adding more bypass capacitors of different values and types to the power rail to achieve a lower minimum impendence bandwidth?

2) Does it matter on which side the variable capacitor is placed?

1hz.png

Note: R1 is 10MΩ not 10mΩ.
 
Last edited:

Thread Starter

k1ng 1337

Joined Sep 11, 2020
940
Why? The ATMega can surely generate a 1Hz pulse itself.
I was having timing issues that were solved with an interrupt. I am also not aware of any clocks using this chip that do not rely on an external trigger.

Use a CD4060 counter/oscillator to get 4hz in one IC.
or
DC4040 + CD4040
The 5 decade counters serve the same logic function. I had them on hand so I decided to use them up. I can't say for certain how much error is introduced having 5 chips in series but it has so far been negligible.
 

Papabravo

Joined Feb 24, 2006
21,159
An ATmega does NOT require an external trigger to generate a one second pulse. I'm pretty certain of that. Care to make a small wager?
 

Thread Starter

k1ng 1337

Joined Sep 11, 2020
940
An ATmega does NOT require an external trigger to generate a one second pulse. I'm pretty certain of that. Care to make a small wager?
For use as a Real Time Clock? There was significant time drift even with a 16MHz crystal. Obviously due to the execution time of code and methods used. I'm not at the level yet to work around this. Understanding how the timers work is hard enough. :p
 

Ian0

Joined Aug 7, 2020
9,668
You could always put the trimmer capacitor on the 16MHz oscillator.

Understanding microcontroller timers is well worth the effort. You can make them do some really clever things, and save a lot of code. NXP's SCT on the LPC800 and LPC1500 series is a marvel.
Unfortunately, they are not always clearly documented, but the microcontroller manual at register level is always clearer than the "drivers".
 

DickCappels

Joined Aug 21, 2008
10,153
1) Is there a practical advantage to adding more bypass capacitors of different values and types to the power rail to achieve a lower minimum impendence bandwidth?

Atmel recommended an electrolytic capacitor in parallel with a ceramic capacitor. 10 uf and .01 uf seem to work nicely. I have had pretty good success using 0.33 uf tantalum capacitors alone, but that was with older AVR controllers and haven't tried it in recent years.

2) Does it matter on which side the variable capacitor is placed?
Not that I can think of in the circuit you posted.

What is the 1 Hz used for?

The crystal oscillator in the 'mega328 can run at 32768 Hz if you like, and it can switch clock sources on the fly if needed.

As already pointed out, you don't need all of those extra chips. You are going to eventually learn how to do in firmware whatever it is that you want to do. Is there a better time to learn than now?

It is good that you switched from 10 milliohms to 10 megohms, those low value resistors are expensive! : -)
 

Sensacell

Joined Jun 19, 2012
3,432
For use as a Real Time Clock? There was significant time drift even with a 16MHz crystal. Obviously due to the execution time of code and methods used. I'm not at the level yet to work around this. Understanding how the timers work is hard enough. :p
An MCU can keep time perfectly without the code execution affecting the time accuracy.
You need to use the internal hardware timer/counter resources to divide the clock down, not a software based timing loop.

At worst, an interrupt might need to deal with counter roll-over events, which would happen a some relatively low frequency.
 

Papabravo

Joined Feb 24, 2006
21,159
For use as a Real Time Clock? There was significant time drift even with a 16MHz crystal. Obviously due to the execution time of code and methods used. I'm not at the level yet to work around this. Understanding how the timers work is hard enough. :p
I'm not sure why you think a 16 MHz crystal is better or worse than any other crystal, but that is OK for now. Your skills with a processor will improve over time and it will become clear to you how to do this.
 

Thread Starter

k1ng 1337

Joined Sep 11, 2020
940
Thanks everyone for the comments. All things considered, I am going to go ahead with the original plan unless there are objections to the circuit posted. The goal of this project was to build a Real Time Clock for a multiplexed display which has been done. I can now make use of the other features of the chip without having to worry about timing.

Using the circuit posted affords some interesting opportunities such as an insulated temperature controlled enclosure. Since I used high quality components for every portion of this project, it will be interesting to see the long term stability of the components in a practical device.

There will be headers on the I2C and SPI pins to allow for programming of the chip as well as synchronizing the time via a Raspberry Pi internet connection.

I'm not sure why you think a 16 MHz crystal is better or worse than any other crystal, but that is OK for now. Your skills with a processor will improve over time and it will become clear to you how to do this.
In this case the 32.786kHz crystal is 20ppm vs the 16MHz crystal at 50ppm! I am inclined to use the components I have instead of buying more. For a grand total of $10-15, I'll have a pretty nifty clock.
 
Last edited:

MrChips

Joined Oct 2, 2009
30,711
Why are you using CD4017 divide-by-10 Johnson counters?
CD4060 has built-in circuitry for the xtal and has up to 13 stage divider.
You will need to add a CD4020 or CD4040 to get 1Hz output.

The problem is neither with 32768Hz crystal nor 16MHz crystal on an MCU.
Timing on an MCU is not affected by code or interrupts if done properly.
If you are already using an MCU such as ATmega328 then you do not need an external 1Hz clock.
 

Papabravo

Joined Feb 24, 2006
21,159
Why are you using CD4017 divide-by-10 Johnson counters?
CD4060 has built-in circuitry for the xtal and has up to 13 stage divider.
You will need to add a CD4020 or CD4040 to get 1Hz output.

The problem is neither with 32768Hz crystal nor 16MHz crystal on an MCU.
Timing on an MCU is not affected by code or interrupts if done properly.
If you are already using an MCU such as ATmega328 then you do not need an external 1Hz clock.
I think the TS answered this question by saying he uses what he has on hand regardless of any other consideration. Nothing wrong with being an iconoclast.
 

Thread Starter

k1ng 1337

Joined Sep 11, 2020
940
I think the TS answered this question by saying he uses what he has on hand regardless of any other consideration. Nothing wrong with being an iconoclast.
How does this make me an iconoclast? Achieving the timing goal without an interrupt is beyond my capabilities. I also did attempt the above before I made this topic so I do not appreciate this comment as I put a good deal of thought into the project.

Would you rather me buy new components and redesign the project to appease posters who make comments that are not germane to the topic title?

Certainly confused by your post..
 

Papabravo

Joined Feb 24, 2006
21,159
How does this make me an iconoclast? Achieving the timing goal without an interrupt is beyond my capabilities. I also did attempt the above before I made this topic so I do not appreciate this comment as I put a good deal of thought into the project.

Would you rather me buy new components and redesign the project to appease posters who make comments that are not germane to the topic title?

Certainly confused by your post..
No, I'm fine with what you are doing.

The primary definition of iconoclast is:

a person who attacks cherished beliefs or institutions.
The "cherished belief" that you have upended is that problems need to be solved by minimizing sone "cost" function. This usually involves minimum number of components, minimum board space, minimum time to completion and so on. It was a compliment.

I will cop to a mild poke @MrChips
 
Last edited:
Top