[Boards: 3 / a / aco / adv / an / asp / b / bant / biz / c / can / cgl / ck / cm / co / cock / d / diy / e / fa / fap / fit / fitlit / g / gd / gif / h / hc / his / hm / hr / i / ic / int / jp / k / lgbt / lit / m / mlp / mlpol / mo / mtv / mu / n / news / o / out / outsoc / p / po / pol / qa / qst / r / r9k / s / s4s / sci / soc / sp / spa / t / tg / toy / trash / trv / tv / u / v / vg / vint / vip / vp / vr / w / wg / wsg / wsr / x / y ] [Search | Free Show | Home]

100hz clock pulse needed

This is a blue board which means that it's for everybody (Safe For Work content only). If you see any adult content, please report it.

Thread replies: 30
Thread images: 3

File: square-wave-on-oscilloscope.jpg (11KB, 620x349px) Image search: [Google]
square-wave-on-oscilloscope.jpg
11KB, 620x349px
any electronics people know the best way to a get 100hz clock pulse from 60hz mains?

the output of a full wave rectifier should be 120hz, right? so in theory, I should be able to divide that down to 100, but I don't quite know how.

I want to take this 100hz and make a clock display that will display the time down to the 1/100th of a second, so:
HH:MM:SS:XX, like a stop watch.

I plan on feeding this 100hz clock pulse to an arduino as an interrupt to advance the time.

google tells me how to get an arduino to generate 100hz, or how easy it is when I'm not in north america.
>>
You need a PLL/VCO. It's not straightforward.

Maybe instead you could use the 120 Hz and cheat by throwing away 20 cycles, if it doesn't have to be accurate in reality.
>>
>>1096140
well.. seeing that it's a clock, I'd like it to be as accurate as the mains AC will let it.

if I just feed 120hz to an arduino as an interupt, can I have it divide down to 100hz in code and have it reliable -- where it won't miss a pulse due to being busy doing some light number crunching or checking other input pins for status and updating LED output? or depending on how hard its working, I can't really rely on it keeping up with the clock pulse?
>>
>>1096145
120 Hz should give you plenty of time to do what you need to do, at least with AVR-GCC. For a 16 MHz chip, that's over 100k instructions. Dunno if Arduino has too much overhead or not.
>>
>>1096145
If you are going to use the Arduino, why don't you just add a crystal and use that?
>>
>>1096150
a crystal oscillator is an option, but I didn't want to have to use it if I already had a frequency source elsewhere. I haven't successfully gotten any kind of crystal oscillator circuit to work yet, so I'm not looking forward to having to resort to it.

but, if the arduino is doing the dividing down, the code might look something like this I think:

[code]
const int buttonPin = 2; // the number of the pushbutton pin
const int ledPin = 13; // the number of the LED pin

// variables will change:
volatile int buttonState = 0; // variable for reading the pushbutton status

void setup() {
// initialize the LED pin as an output:
pinMode(ledPin, OUTPUT);
// initialize the pushbutton pin as an input:
pinMode(buttonPin, INPUT);
// Attach an interrupt to the ISR vector
attachInterrupt(0, pin_ISR, CHANGE);
}

void loop() {
// digitalRead(buttonPin);, digitalWrite(ledPin, buttonState); doSomething(timekeeper); and other stuff
}

void pin_ISR() {
timekeeper = map(counter, 0 119, 0 99);
}
[/code]

in reality, I have about 6 buttons/switches to check the state of during the loop(), and tons of LEDs to control via shift-register ICs.

doing the frequency conversion in code will save me on parts and soldering, as long as I know the arduino can keep up and not miss pulses from the 120hz source, causing it to run slow and lose time.

I don't have a way to safely tap the mains AC frequency and channel it to an arduino for testing just yet. I'll be able to build a prototyping circuit this weekend. saturday I'll be heading out to the electronics surplus shop to get whatever parts I need. any parts suggestions or recommendations before I go would be greatly appreciated!
>>
>>1096154
I realize the code is critically wrong in some parts.. but it's getting late and I gotta get up for work early in the morning.

I'll leave the window auto-updating though, hopefully the thread will still be here later when I can get back to it.

thanks for the help so far.
>>
>>1096160
What you want to do is possible but so much harder than simply using a timer on the arduino.
Also depending on where you live it might be very difficult to get the frequency wanted out of mains. If you live in Europe or somewhere that uses 50 Hz just multiply it (Analog has ready made ICs for that). You will need a transformer, bridge and an IC for multiplication but it can be done. But if you live in the States.... They use 60Hz over there and getting 100 Hz out of that (not a harmonic) requires a PLL. Again harder than a simple timer.

Also playing around with mains voltage can kill you especially if you lack experience.

Finally if accuracy is your concern I have to remind you that mains frequency is NOT accurate but depends among others on network load.
>>
You could count each pulse every 6 times to get a 10 Hz signal with a 4017 for example, and let the arduino fill the last digits with it's own timer, you won't notice if they're off, as you can't barely see them.
>>
>>1096171
I'm in north america, so 60hz is what's immediately available here.

I was planning on using a step-down transformer to supply about 12v, then a full wave bridge rectifier to make it DC, split off so 12v goes to some 12v requiring parts, and the other part of the split will go to a buck converter to bring it down to 5v for the arduino.

for testing, I just need a wall wart that outputs AC, and I can work with isolated, safer lower voltages on a breadboard.

PLL is beyond my skill set. I may just do what >>1096196 says and divide down to 10hz with a 4017. I could cheat the final decimal place or maybe just omit it altogether.

also looking into RTC modules, maybe I can pull one off an old mainboard, but that may just be accurate down to the nearest second. it'd save on soldering extra 7-segmented led modules, and on coding and physical space on the display, though.
>>
>>1096145

As it's a clock, I'm going to make the reasonable assumption that you're going to have a shitton of spare CPU time.
Personally, I'd just use the ADC. Just give it some voltage through a resistor divider or small isolation transformer (or both) and just continuously look for zero crossing.

But, honestly, I don't have a clue why you want this. Mains isn't as stable in the short term as a crystal oscillator, so if you actually need good accuracy down to 10ms, you should be using one of those.

If you don't need that accuracy and it's just for aesthetic, just fake or interpolate your 100div/sec display from the 60Hz signal.
>>
>>1096603
>Personally, I'd just use the ADC. Just give it some voltage through a resistor divider or small isolation transformer (or both) and just continuously look for zero crossing.

Actually, duh, you don't even need to do that. AVRs have a pin-change interrupt (PCINT) that you can just set, then have your routine run every time it goes off.
>>
>>1096133
For such a slow clock, why not build a simple 555 timer and set the frequency to 100 hz? Granted, for a cleanish pulse, you would want to send the output of the timer in to something like a cheap hex inverter, but the 555, a resistor, a potentiometer, and a (non-electrolytic) cap, a hex inverter chip, all put together is only a few bucks. I suppose you will need a very small dc power supply in there too, but for such a slow speed the good old astable 555 timer seems like a very simple win.

The real problem will be actually setting the clock to the correct time, accurate to a fraction of a second. Maybe you can get GPS time to tell you what time it is at that resolution?
>>
>>1096145
Why does it have to use the AC signal from the line for your timebase? Get a 32.768kHz TCXO and run that through dividers to get 100Hz, the TCXO will be accurate down to single-digit PPM, that's all the accuracy you need.
>>
>>1096607
THIS

you dont need fucking arduino for everything. Get a 555 and 1 µF, 3.3 KΩ, 5.6 KΩ for 0.01 sec. period and 99.5172 Hz. @ 61.4 % duty cycle.

learn to use ICs
>>
Buy Practical Electronics for Inventors by Paul Scherz. Its $20 brand new for the newest edition. You'll learn a lot more than you would on 4chan
>>
>>1096570

Also why 100hz? And if you want something close to 100hz why get it from ac mains instead of just your on-board clock? You trying to precisely sync multiple devices or something?


But anyway here's how I would do it (I did something similar but it was based off a 1hz gps pulse)
Learn to configure your pwm registers.
Have your 5v 60hz drive an interrupt for calibration of the pwm
It may take some massageing of the data as the 60hz sign wave wont trigger the interupt (rising or falling) perfectly in sync each time.
>>
555 is going to be absolute ass for accuracy and stability, guys.
>>
>>1096603
yes, displaying down to the nearest 1/100th of a second is just for looks. it's an industrial looking alarm clock novelty.

>>1096605
I think that's what my plan was, if I can just get the 100hz signal. it doesn't have to be from the mains, I just figured it's there, maybe I should try to use it instead of cramming more circuitry into this project box.

>>1096607
I could 555 all day, dial in the frequency with a 20-turn trim pot, watching it on an oscilloscope... until it cools down at night or for the winter and it has to be re-tuned.

I'm gonna have a button that will reset the seconds, that way once I set the hour and minutes, I can sync it to my watch, that's about as accurate as I need it.

>>1096648
if I can get all the parts at the electronics shop today, I'll give it a try.

>>1096658
I don't need an arduino for time keeping, but it will make things so much easier for displaying it on eight 7-segmented led modules, as well as an alarm function.

I used to try and IC everything. I was actually against arduino when it was new because nobody was ever learning or using the fundamentals anymore.

this project however, has a lot of room for a lot of functionality with arduino that you won't find in other off-the-shelf alarm clocks. I'm saving the details for now as right now the issue is keeping accurate time, and displaying down to the 1/100th of a second.

>>1096659
is that the radio shack book author? I've been meaning to get those books, but been putting it off. I have $25 at amazon that I don't know what to spend it on, maybe that book will do.

>>1096661
I want the display read-out to look like a stop watch. which goes down to 1/100th of a second.

>>1096669
absolutely agreed. if the whole thing was just for show, or a prop or something, I would 555 it and CD426 each 7-segmented led module and skip the arduino.
>>
>>1096145
>as accurate as the mains AC will let it.

Mains AC isn't very accurate over a short period. It could be off by a few tenths of a percent.

Over longer periods, it is accurate. Utilities count the cycles during the day and speed up or slow down the system at night to make the number come out right. So electric clocks don't gain or lose time. But for a short term time base, get a crystal oscillator and programmable divider.
>>
>>1096133

The obvious solution is to PLL it to 600Hz and divide by 6.

The black magic solution would be to amplify the raw mains down to a set amplitude, use a tight window comparator set at half that amplitude to generate Dirac pulses at 120Hz, then filter out the 5th harmonic to get a 600Hz sine and divide that by 6.
>>
>>1096878
>Utilities count the cycles during the day and speed up or slow down the system at night to make the number come out right.
For real? Sounds pretty rad.
>>
I should point out that the atmega328p (the microcontroller) in the arduino actually has a built in oscillator that works at like 8 Mhz.

So the real question is why no use that instead.
>>
File: genie.jpg (81KB, 800x600px) Image search: [Google]
genie.jpg
81KB, 800x600px
>>1097017
>For real? Sounds pretty rad.

yeah, they sit an old guy next to the generator and he presses against the spinning flywheel with his boot to slow it down while comparing his pocket-watch against a GE clock radio.
>>
>>1097021
You might want to read the spec sheet first.
>>
File: RTC Module.jpg (8KB, 225x225px) Image search: [Google]
RTC Module.jpg
8KB, 225x225px
well, I ended up getting one of these while I was out getting parts yesterday:

pic related, it's a DS3231 RTC module.

reading up on it, there are some pretty nifty features on it, it'll take a bit of needed programming away from what I was planning based on what I read it can do on its own.

I'm still reading up on it and how to use it. so far it looks like the arduino has to poll it for time updates. I kinda wish it was an option to have it the other way around, where the RTC could tell the arduino that a new time is available every second.

that's the other thing, it keeps down to the nearest second as far as what it tells the arduino. I guess I could just have the arduino run the numbers on the last two digits on its own, since it's just for looks anyway. it'll be too fast to notice that it's off by a little bit.

I found this:
http://tronixstuff.com/2014/12/01/tutorial-using-ds1307-and-ds3231-real-time-clock-modules-with-arduino/
to start with. I can modify the code from there. but I need to find more documentation and examples on using the other features available.
>>
>>1096763
>yes, displaying down to the nearest 1/100th of a second is just for looks. it's an industrial looking alarm clock novelty.

Those use xtals, I'd reccomend you to use a xtal oscillator instead of doing stupid syncing on mains freq.
>>
For what reason can you not use the arduino's internal timers to get your 100Hz?

There's a crystal on there, even on the nano, and I guarantee you it's going to be more accurate than the mains frequency.

Get up in there and directly access the timer interrupt registers. AVR chips contain hardware timers, timer clock dividers, and timer interrupts, which can run at full speed while the rest of the chip does it's thing. This will allow you to make a fairly accurate clock, since the instructions to update the display won't stop it from counting time.

Something like

cli(); //disable interrupts
TCCR1A |= (1<<WGM12); //Set Timer/counter 1 to clear timer on compare match
TCCR1B |= (1<<CS00); //set clock select to clk/64
TCCR1B |= (1<<CS01); //set clock select to clk/64
TIMSK1 |= (1<<OCIE0A); //enable output compare interrupt 0(A). trigger interrupt when clk/64 counts up to 125, triggering an interrupt evert millisecond. (for 8mhz clock)
OCR1AH |= 0x00; //Timer/Counter 1 Output Compare Register A High = 0
OCR1AL |= 0x7D; //Timer/Counter 1 Output Compare Register A Low = 125
sei();


and then way down at the bottom:

ISR (TIMER1_COMPA_vect)
{
time++; //increment real time clock by one milisecond.
}

And then just stick the part that does the display in the loop and have it read your time variable whenever it decides to update.
>>
>>1098383
>I guarantee you it's going to be more accurate than the mains frequency.
Not on long run, due to the reasons mentioned already.
>>
Using AC main for your time? Why would you want to do this in the age of cheap, accurate, battery backed up RTC? Unless your the guy who doesn't have to reset all the FLIPP'N clocks when the power goes out, its just another clock to set during those pesky outages.
Thread posts: 30
Thread images: 3


[Boards: 3 / a / aco / adv / an / asp / b / bant / biz / c / can / cgl / ck / cm / co / cock / d / diy / e / fa / fap / fit / fitlit / g / gd / gif / h / hc / his / hm / hr / i / ic / int / jp / k / lgbt / lit / m / mlp / mlpol / mo / mtv / mu / n / news / o / out / outsoc / p / po / pol / qa / qst / r / r9k / s / s4s / sci / soc / sp / spa / t / tg / toy / trash / trv / tv / u / v / vg / vint / vip / vp / vr / w / wg / wsg / wsr / x / y] [Search | Top | Home]

I'm aware that Imgur.com will stop allowing adult images since 15th of May. I'm taking actions to backup as much data as possible.
Read more on this topic here - https://archived.moe/talk/thread/1694/


If you need a post removed click on it's [Report] button and follow the instruction.
DMCA Content Takedown via dmca.com
All images are hosted on imgur.com.
If you like this website please support us by donating with Bitcoins at 16mKtbZiwW52BLkibtCr8jUg2KVUMTxVQ5
All trademarks and copyrights on this page are owned by their respective parties.
Images uploaded are the responsibility of the Poster. Comments are owned by the Poster.
This is a 4chan archive - all of the content originated from that site.
This means that RandomArchive shows their content, archived.
If you need information for a Poster - contact them.