Accurate Arduino clock

67 views
Skip to first unread message

Overkill

unread,
Oct 26, 2015, 8:26:24 AM10/26/15
to ardui...@googlegroups.com

I need to create a variable 200-400khz 25% duty cycle square wave using an Arduino, or PIC, very accurately! as in Low Jitter, low drift. It needs to be as good or better than a Quarts crystal derived clock.

 

The current circuit uses a crystal that gets divided down to 300khz, then another circuit varies that 300khz master clock up or down 100khz.

 

I need to be able to replace all of that. Suggestions on how best to do this accurately.

 

 

Dave

Minh Anderson

unread,
Nov 2, 2015, 10:31:34 PM11/2/15
to Arduino MN
Dave,

Do you still need help with this? I spent some time playing with PWM on Arduino over the weekend, and I was able to generate variable 25% duty cycle square wave from 250 Hz - 400 kHz with about 1% error. The compare register overflows for value below 250 so it doesn't work for frequency less than 250 Hz. But that's probably not too hard to fix. If I have some free time next weekend, I'll try to get it down to 200 Hz. I've attached the plots and my code. I hope this helps.

Minh
500 Hz.bmp
500 Hz duty cycle.bmp
400 kHz duty cycle.bmp
variable square wave.ino
400 kHz.bmp

Eric Tsai

unread,
Nov 3, 2015, 12:02:44 AM11/3/15
to Arduino MN
Pretty cool Minh, thanks for sharing.  The different timer and interrupt modes are stuff I've never had a need to use before, so it's interesting to see how they're used for something like this.

Eric

Overkill

unread,
Nov 3, 2015, 8:20:06 AM11/3/15
to ardui...@googlegroups.com

Thank you. I have someone that has been working on this. The problem we are finding is that while we can create 200khz-400khz PWM 25% duty cycle square waves easy enough, the second part of this is we need to be able to adjust in .1% steps up or down from the base 300khz frequency. and with a 16bit controller, we don’t have enough resolution. So I’m told. We are looking at 32bit pics and maybe another way to do it.

 

 

Thank you for the input! It is an interesting puzzle. Trying to recreate something that was done in the 70’s with TTL chips and a VCO!!

 

 

 

Dave

--
You received this message because you are subscribed to the Google Groups "Arduino MN" group.
To unsubscribe from this group and stop receiving emails from it, send an email to arduino-mn+...@googlegroups.com.
To post to this group, send email to ardui...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/arduino-mn/cbff25a5-65c9-416d-9772-93b60b8eae54%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Minh Anderson

unread,
Nov 3, 2015, 1:53:51 PM11/3/15
to Arduino MN
Eric: No problem. It was interesting. I haven't done much with interrupt and timer either.

Dave: So you want to be able to generate 25% duty-cycle square wave from 200 kHz to 400 kHz with step .1% of 300 kHz, or step of 300 Hz?

Overkill

unread,
Nov 3, 2015, 10:18:34 PM11/3/15
to ardui...@googlegroups.com

300Khz is the “center” frequency, I then need to be able to “tune” in 0.1% steps up or down from 300khz.

 

 

Dave

 

 

 

From: ardui...@googlegroups.com [mailto:ardui...@googlegroups.com] On Behalf Of Minh Anderson
Sent: Tuesday, November 03, 2015 12:54 PM
To: Arduino MN
Subject: Re: Accurate Arduino clock

 

Eric: No problem. It was interesting. I haven't done much with interrupt and timer either.

 

Dave: So you want to be able to generate 25% duty-cycle square wave from 200 kHz to 400 kHz with step .1% of 300 kHz, or step of 300 Hz?

 

--

You received this message because you are subscribed to the Google Groups "Arduino MN" group.
To unsubscribe from this group and stop receiving emails from it, send an email to arduino-mn+...@googlegroups.com.
To post to this group, send email to ardui...@googlegroups.com.

Reply all
Reply to author
Forward
0 new messages