Author Topic: Simple cheap 1Hz Oscillator - low accuracy fine  (Read 14950 times)

0 Members and 1 Guest are viewing this topic.

Offline GarthyDTopic starter

  • Regular Contributor
  • *
  • Posts: 85
  • Country: au
    • Adventures in Electronics
Re: Simple cheap 1Hz Oscillator - low accuracy fine
« Reply #50 on: September 10, 2017, 02:49:49 am »
Could you not use an external divider to divide the CPLD's clock down most of the way? A pair of SN74HC4020s for example? With a 1Hz clock you then need to trigger a reset pulse of the appropriate length.

Thankyou for the suggestion. It might be a bit costly compared to the other solutions mentioned, both in terms of price and space. However, it could work well on a project that needed multiple power-of-two clocks.
 

Offline Beamin

  • Super Contributor
  • ***
  • Posts: 1567
  • Country: us
  • If you think my Boobs are big you should see my ba
Re: Simple cheap 1Hz Oscillator - low accuracy fine
« Reply #51 on: September 23, 2017, 04:21:17 pm »
Could you not use an external divider to divide the CPLD's clock down most of the way? A pair of SN74HC4020s for example? With a 1Hz clock you then need to trigger a reset pulse of the appropriate length.

Thankyou for the suggestion. It might be a bit costly compared to the other solutions mentioned, both in terms of price and space. However, it could work well on a project that needed multiple power-of-two clocks.
So I have been watching this for a while didn't know there was so many ways to do it. I would have done the multivibrator but I like to make analoge things. Which worked best for you?
Max characters: 300; characters remaining: 191
Images in your signature must be no greater than 500x25 pixels
 

Offline GarthyDTopic starter

  • Regular Contributor
  • *
  • Posts: 85
  • Country: au
    • Adventures in Electronics
Re: Simple cheap 1Hz Oscillator - low accuracy fine
« Reply #52 on: September 23, 2017, 09:46:59 pm »
So I have been watching this for a while didn't know there was so many ways to do it. I would have done the multivibrator but I like to make analoge things. Which worked best for you?

No final decision yet. I should be posting an update "soon". The two main causes for delay are: Waiting for the parts to arrive (I ordered many mentioned in this thread, and they only recent arrived), and researching and experimenting with a secondary MCU solution to see how it fits in with the rest of the design (if it fits well, the timing aspect is provided as a side benefit). I'll go into more detail in the update as there are too many unknowns right now.
 

Online BrianHG

  • Super Contributor
  • ***
  • Posts: 7660
  • Country: ca
Re: Simple cheap 1Hz Oscillator - low accuracy fine
« Reply #53 on: September 23, 2017, 10:12:31 pm »
I'd vote on the secondary 40cent 8 pin PIC.  You can use it to provide your 1 second watchdog reset, and, also a low voltage supervisory reset by using an ADC input to monitor your voltage source which in my designs, I find useful to stop other electronics when necessary.
 

Offline GarthyDTopic starter

  • Regular Contributor
  • *
  • Posts: 85
  • Country: au
    • Adventures in Electronics
Re: Simple cheap 1Hz Oscillator - low accuracy fine
« Reply #54 on: September 24, 2017, 03:38:51 am »
.. and, also a low voltage supervisory reset by using an ADC input to monitor your voltage source which in my designs, I find useful to stop other electronics when necessary.

Funny you should mention that. Part of what I'm experimenting with is replacing voltage monitoring and power control with the secondary MCU. Being able to replace some of this is what could make the MCU approach (otherwise the most expensive solution) viable.

Anyway. update "soon".
 

Offline stj

  • Super Contributor
  • ***
  • Posts: 2153
  • Country: gb
Re: Simple cheap 1Hz Oscillator - low accuracy fine
« Reply #55 on: September 24, 2017, 05:58:31 pm »
i would just use a pic 10F series 6pin smd microcontroller.
 

Offline Raj

  • Frequent Contributor
  • **
  • Posts: 689
  • Country: in
  • Self taught, experimenter, noob(ish)
Re: Simple cheap 1Hz Oscillator - low accuracy fine
« Reply #56 on: September 25, 2017, 05:55:47 pm »
get an attiny ,write a code like-

         LDI R16, 0XFF
        LDI R17, 0X00
   OUT DDRx, R16
          L1:   OUT PORTx, R16
nop
nop
nop
   OUT PORTx, R17
nop
nop
nop
JMP  L1






keep adding the nop(s) till the frequency is ok
« Last Edit: September 25, 2017, 05:58:37 pm by Raj »
 

Offline mikeselectricstuff

  • Super Contributor
  • ***
  • Posts: 13694
  • Country: gb
    • Mike's Electric Stuff
Re: Simple cheap 1Hz Oscillator - low accuracy fine
« Reply #57 on: September 25, 2017, 06:43:52 pm »
get an attiny ,write a code like-
...
keep adding the nop(s) till the frequency is ok
:palm:
Youtube channel:Taking wierd stuff apart. Very apart.
Mike's Electric Stuff: High voltage, vintage electronics etc.
Day Job: Mostly LEDs
 

Offline Raj

  • Frequent Contributor
  • **
  • Posts: 689
  • Country: in
  • Self taught, experimenter, noob(ish)
Re: Simple cheap 1Hz Oscillator - low accuracy fine
« Reply #58 on: September 25, 2017, 06:49:50 pm »
get an attiny ,write a code like-
...
keep adding the nop(s) till the frequency is ok
:palm:

Trolling aside, a loop is must,attiny doesn't have that much space, use "brne" command to set up a loop
« Last Edit: September 25, 2017, 07:05:00 pm by Raj »
 

Offline Beamin

  • Super Contributor
  • ***
  • Posts: 1567
  • Country: us
  • If you think my Boobs are big you should see my ba
Re: Simple cheap 1Hz Oscillator - low accuracy fine
« Reply #59 on: September 25, 2017, 09:56:06 pm »
get an attiny ,write a code like-
...
keep adding the nop(s) till the frequency is ok
:palm:
Please explain besides it seems really lazy but I only know how to copy and paste code into the Arduino so I want to learn.
Max characters: 300; characters remaining: 191
Images in your signature must be no greater than 500x25 pixels
 

Offline MattHollands

  • Frequent Contributor
  • **
  • Posts: 313
  • Country: gb
    • Matt's Projects
Re: Simple cheap 1Hz Oscillator - low accuracy fine
« Reply #60 on: September 25, 2017, 10:10:22 pm »
...now that you've introduced the attiny, you need a secondary watchdog to make sure that the attiny doesn't get stuck. A watchdog watcher. Luckily attinys often have them built in but it feels superfluous and just another device to program.
Read about my stuff at: projects.matthollands.com
 

Offline GarthyDTopic starter

  • Regular Contributor
  • *
  • Posts: 85
  • Country: au
    • Adventures in Electronics
Re: Simple cheap 1Hz Oscillator - low accuracy fine
« Reply #61 on: September 25, 2017, 10:26:35 pm »
So it's ATtinys all the way down then? ;)
 

Offline MattHollands

  • Frequent Contributor
  • **
  • Posts: 313
  • Country: gb
    • Matt's Projects
Re: Simple cheap 1Hz Oscillator - low accuracy fine
« Reply #62 on: September 25, 2017, 11:33:12 pm »
get an attiny ,write a code like-
...
keep adding the nop(s) till the frequency is ok
:palm:
Please explain besides it seems really lazy but I only know how to copy and paste code into the Arduino so I want to learn.

NOP is the "no operation" command for a cpu. It consumes a clock cycle, but achieves nothing other than killing time. Therefore if you want to achieve a 1Hz pulse from a 1MHz clock (for example), you can set the pin high in the first instruction, perform 499,999 NOPs, set the pin low, do 499,999 NOPs. However, this obviously takes a ridiculous amount of memory that the attiny doesn't have if you write out each NOP (at least one byte per command comes out to a megabyte of instructions).

The way to do this in reality would be to make a loop which compiles to a much shorter program, for example:

for(int i = 0; i < large_number; i++)
{
//do nothing
}

In reality, you're better of using hardware timers inside the attiny so the attiny can go to sleep or do other things while the hardware timer generates the pulse.

Atmel AVRs, such as the attiny are generally programmed (at least this is how I do it) using Atmel Studio and compiled using the avr_gcc compiler.
Read about my stuff at: projects.matthollands.com
 

Offline GarthyDTopic starter

  • Regular Contributor
  • *
  • Posts: 85
  • Country: au
    • Adventures in Electronics
Re: Simple cheap 1Hz Oscillator - low accuracy fine
« Reply #63 on: September 25, 2017, 11:54:56 pm »
I think they're just having a little fun. Personally, I'm actually quite familiar with low-end AVRs, although I guess someone else reading it might be sent off on the wrong track.

For an ATtiny as a pure clock generator and nothing else, I'd set up one of the timer counters with an appropriate prescale and count, then use the ISR to write to PINx (not PORTx) so that it toggles rather than sets. Then I'd SLEEP to Idle endlessly.

Or if I was lazy (untested):

Code: [Select]
DDRx |= 1 << whatever;
for (;;)
{
  _delay_ms(1000);
  PINx |= 1 << whatever;
}

But this would be grossly underutilising the MCU and is probably the most expensive solution.

Anyway, more "soon".
 

Offline GarthyDTopic starter

  • Regular Contributor
  • *
  • Posts: 85
  • Country: au
    • Adventures in Electronics
Re: Simple cheap 1Hz Oscillator - low accuracy fine
« Reply #64 on: September 29, 2017, 06:47:04 am »
Okay, I'm finally able to provide a solid update.

For my project, I've settled on using a secondary MCU to handle the functionality I was after. I am fairly confident this will be the solution I will use in the end. By way of explanation:

Using a MCU to provide a clock on its own is overkill and is one of the weakest solutions for the clock problem on its own. However, if the MCU can also provide other functionality, perhaps replacing or simplifiying enough other circuitry, then the effective cost of the MCU can be reduced to the point where it is competitive. My aim was to eliminate this as an option early on, but it ended up being useful enough that is became the strongest solution.

Having worked with AVRs in the past, I looked at the ATtiny series. Cost-wise, they are fairly good for MCUs, but unfavourable when compared to most of the clock solutions in this thread. There are a number of problems with existing solutions in my project that a MCU could potentially improve: Battery monitoring, low-power mode, and power management. Battery monitoring is the easy one: Use ADC and act accordingly. Running the MCU at battery/input power directly makes power management simple. As for low power, I was able to get battery use way down by simply using the MCU to switch off the voltage regulators that go to the rest of the circuit, and then drop to the lowest power mode for the MCU. Getting battery use down to 1uA (of which 800nA was power flowing backward through a diode and out via a pulldown) was probably the tipping point for me.

In the end, there is no clock signal sent out to the CPLD. Instead, the CPLD indicates when the emergency reset is activated (ie. four buttons down), and the MCU decides when it has been held long enough. I actually changed this in the end to treat the four-button long-press sequence as an escape that puts you into a mode in which you can select an option, one of which is an emergency reset.

As mentioned previously, I ended up purchasing a number of components that were raised in the thread to experiment with, and can share my experiences with these.

Due to my unusual start into electronics (I went straight to AVRs) I've never had a chance to play with a 555. I took the opportunity to rectify this deficiency and had a bit of a play around with one. I made a 50% duty cycle oscillator both slow enough to drive a LED blinker, and then one too fast to see. I finally got some use out of my multimeter's frequency measurement mode with this last one.

I next had an experiment with a 4060. I fed in the output from the 555 and hooked numerous outputs to my LED board, and admit to just admiring the result for a while. How odd that it doesn't have a Q11 output though. I hadn't realised/understood that you could supply two resistors and a cap directly to generate the input signal. Once I realised this, I hooked that up too and it worked great. Whilst I haven't tried two 4060s in tandem, I can imagine how it'd work. I think this would be an excellent solution if you needed multiple power-of-two clocks in a design. It's not expensive either- no wonder this was a popular solution.

I picked up, but haven't hooked up a MC1451B. I imagine the results would be similar to the 4060. The tradeoffs would be: Slighly smaller IC, can dynamically change the clock rate, can divide the clock further, but there is one clock out rather than ten, and it is more expensive.

I now have some standalone single-gate Schmitt triggers. I have reimplemented the delayed direct reset circuit I'd outlined previously using one of these. I haven't tied it all together to the CPLD, but adding in the Schmitt trigger should in theory eliminate the issues I was facing. Driving a MOSFET with a slowly discharging capacitor was never really a good idea. Having had a lot more time to search around for prices, it appears that this is one of the cheapest reliable solutions available (at the cost of accuracy). I think if the MCU solution falls over, this is probably the solution that fits in best with my project. It's also nice to have some standalone Schmitt triggers now- I didn't have any before.

I reimplemented the Schmitt trigger oscillator using a single gate Schmitt trigger rather than use the CPLD and a Schmitt trigger input. I haven't tied it all together to the CPLD, but the output of the circuit is digital, and in theory if I kept the relevant components out of the way of everything else I would be unlikely to run into the same problems I ran into previously, especially while breadboarding. I think that this is probably the strongest solution to the question originally posed at the start of the thread (cheap inexpensive low-accuracy 1Hz clock generator).

This thread has become an absolute treasure trove of information on oscillators and I really appreciate all of the input based on my initial simple question. I've learnt a lot, and I'm sure that others reading the thread have too. I have a collection of fallback solutions if the MCU idea doesn't work in the end. And most importantly, thanks to this thread, if I do need a standalone clock in the final design, or any other design I work on in the future, I have multiple viable options to choose from.

Thankyou all. :)
« Last Edit: September 29, 2017, 06:57:24 am by GarthyD »
 
The following users thanked this post: Ian.M, newbrain

Offline mikeselectricstuff

  • Super Contributor
  • ***
  • Posts: 13694
  • Country: gb
    • Mike's Electric Stuff
Re: Simple cheap 1Hz Oscillator - low accuracy fine
« Reply #65 on: September 29, 2017, 08:31:02 am »
Something else to consider - one common objection to using an MCU for simple functions is the hassle of programming it.
Now that Microchip own Atmel, you can use their programmming service to very cheaply pre-program ( and mark) parts, so they can be treated just like other off-the-shelf part.
Youtube channel:Taking wierd stuff apart. Very apart.
Mike's Electric Stuff: High voltage, vintage electronics etc.
Day Job: Mostly LEDs
 

Offline GarthyDTopic starter

  • Regular Contributor
  • *
  • Posts: 85
  • Country: au
    • Adventures in Electronics
Re: Simple cheap 1Hz Oscillator - low accuracy fine
« Reply #66 on: September 30, 2017, 11:29:20 am »

Something else to consider - one common objection to using an MCU for simple functions is the hassle of programming it.
Now that Microchip own Atmel, you can use their programmming service to very cheaply pre-program ( and mark) parts, so they can be treated just like other off-the-shelf part.

Thanks for the tip. Mass-programming is a problem that I really hope that I need to deal with one day. :)

As-is I can do in-system programming of the chip easily enough (I'm designing this in from the start). There are two other ICs on-board that need programming as well, so whatever I come up with will likely handle the three together.
 


Share me

Digg  Facebook  SlashDot  Delicious  Technorati  Twitter  Google  Yahoo
Smf