electro-music.com   Dedicated to experimental electro-acoustic
and electronic music
 
    Front Page  |  Radio
 |  Media  |  Forum  |  Wiki  |  Links
Forum with support of Syndicator RSS
 FAQFAQ   CalendarCalendar   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   LinksLinks
 RegisterRegister   ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in  Chat RoomChat Room 
go to the radio page Live at electro-music.com radio 1 Please visit the chat
  host / artist show at your time
today> Twyndyllyngs live tonight! Chez Mosc
 Forum index » DIY Hardware and Software » Arduino
Clock Generator for Arduino Interrupts?
Post new topic   Reply to topic
Page 1 of 1 [18 Posts]
View unread posts
View new posts in the last week
Mark the topic unread :: View previous topic :: View next topic
Author Message
joshs



Joined: Dec 05, 2014
Posts: 32
Location: Home

PostPosted: Fri May 08, 2015 4:39 pm    Post subject: Clock Generator for Arduino Interrupts? Reply with quote  Mark this post and the followings unread

Howdy, I'm having a surprisingly hard time finding a circuit to act as an external timer for an Arduino project. What I'd like to do is generate pulses in the range of about 1hz to 500hz, with independent control of duty cycle and frequency... I'm using this to control an arpeggiator. The frequency controls the tempo and the duty cycle controls the note length. I'd use the internal timers, but they're already very busy Smile Any pointers on where to get started with this? I suppose I could use an attiny to do it, but that seems like a waste...
Back to top
View user's profile Send private message
elmegil



Joined: Mar 20, 2012
Posts: 2179
Location: Chicago
Audio files: 16

PostPosted: Fri May 08, 2015 9:03 pm    Post subject: Reply with quote  Mark this post and the followings unread

What kind of control?

Knobs, or CV, or both?
Back to top
View user's profile Send private message
joshs



Joined: Dec 05, 2014
Posts: 32
Location: Home

PostPosted: Fri May 08, 2015 9:13 pm    Post subject: Reply with quote  Mark this post and the followings unread

Just plain old knob controls.
Back to top
View user's profile Send private message
elmegil



Joined: Mar 20, 2012
Posts: 2179
Location: Chicago
Audio files: 16

PostPosted: Sat May 09, 2015 7:47 am    Post subject: Reply with quote  Mark this post and the followings unread

A simple tri-core oscillator, with a comparator to generate the square wave seems like the best bet then.

http://electro-music.com/wiki/pmwiki.php?n=Schematics.NicolasSuperSimpleVPerHzVCO

Omit the CV input and maybe the fine adjust pot, and then put a comparator on the output with a pot set up to provide the comparator level. You'll want to put resistors on either side of the pot to limit the range so that the extremes still provide a narrow pulse.

I suppose one possible issue here: do you have a +/- supply available? I'm not sure how you might adapt this to work with single supply parts. Definitely a TL074 won't work well with single supply.
Back to top
View user's profile Send private message
joshs



Joined: Dec 05, 2014
Posts: 32
Location: Home

PostPosted: Sat May 09, 2015 3:53 pm    Post subject: Reply with quote  Mark this post and the followings unread

I actually have +/-15V in the system. I ended up putting together a sketch on an attiny85 that seems like it will work alright. I think I'd rather do it with ICs so I might go and investigate this circuit more. But it's a little on the complicated side for me, which may make it tough to figure out how to tune/modify it to do exactly what I need.
Back to top
View user's profile Send private message
elmegil



Joined: Mar 20, 2012
Posts: 2179
Location: Chicago
Audio files: 16

PostPosted: Sat May 09, 2015 7:42 pm    Post subject: Reply with quote  Mark this post and the followings unread

I can vouch for the fact that if you build it as it shows, it "just works" Smile +/-15V should work just as well.

Like I said, omit the CV in and the Fine pot, it simplifies the input. You're then just generating a control voltage between +V and -V, as the pot is a voltage divider, and then the op amp buffers and scales it.

The bit with the zener diode and the trim pot let you set a minimum low voltage so that you don't stall out the VCO. If you wanted to limit the high end, you could put a resistor or trim pot between +V and the Coarse pot, BTW, to shift the voltage divider.

The 47nF cap alternately charges and discharges, with U1b as a comparator and the BC557 as a switch determining which, at a rate determined by that control voltage. The diodes set the comparator value, but honestly that bit of the circuit is a little beyond my grasp at the moment too Smile. I suspect, but can't swear, that it's intended to keep the signal within 2 diode drops up or down relative to ground. For standard diodes with .7V drop, that's 1.4V each way, or a swing of 2.8Vpp.

The output op amp buffers that signal as well as multiplying it times about 4 (100/24) which is just shy of 12Vpp, or +/- 6V. With typical component tolerances, I'd expect this to likely be closer to 10Vpp, but your best bet would be to build this part and look at it with a scope to see.

Since you're not giving this guy a CV, you don't need to really worry about the fact that the control is V/Hz (linear) rather than V/Oct (exponential).

Does that help make sense of it?

Do you understand what I meant about the comparator? I can link to a circuit and explain that more as well.
Back to top
View user's profile Send private message
joshs



Joined: Dec 05, 2014
Posts: 32
Location: Home

PostPosted: Sat May 09, 2015 11:01 pm    Post subject: Reply with quote  Mark this post and the followings unread

Thanks for all this info! Actually, the part about the comparator was one of the big parts I didn't understand. I know that an op amp can be set up as a comparator, but I don't know how to design a comparator properly to work in a situation like this.
Back to top
View user's profile Send private message
elmegil



Joined: Mar 20, 2012
Posts: 2179
Location: Chicago
Audio files: 16

PostPosted: Sun May 10, 2015 12:13 am    Post subject: Reply with quote  Mark this post and the followings unread

The idea of the comparator is to convert a triangle to a rectangular waveform with pulse width adjustment.

So a comparator (and I'd use a chip meant to be one--like an LM311--rather than an op amp, though an op amp is certainly feasible) is what it sounds like. It compares its two inputs, and if the positive input is higher than the negative one, then its output is high, and if it's lower, then it's low.

So you set a threshold at the negative input (a pot, as a voltage divider) and run the triangle into the positive input. If the threshold is right at ground, and your triangle is nicely symmetrical, you'll get a square wave of the same frequency at the output of the comparator. As you increase the threshold, the positive side of the rectangle wave gets narrower, and as you decrease it below ground the negative side of the rectangle wave gets narrower. You're basically "slicing" the triangle wave with the threshold. You don't want to allow the threshold to go so high or so low that it no longer intersects with the triangle, so you would have resistors at the positive and negative sides to limit the voltage range to be within that 10 or 12Vpp.

A picture that might help (ignore that it's 0 to +V, same goes if it were -V to +v):

Posted Image, might have been reduced in size. Click Image to view fullscreen.
Back to top
View user's profile Send private message
joshs



Joined: Dec 05, 2014
Posts: 32
Location: Home

PostPosted: Sun May 10, 2015 6:50 am    Post subject: Reply with quote  Mark this post and the followings unread

Oh, cool that actually makes a lot of sense! I think this very well may be how I end up going about this. I've seen a couple of circuits out there that used a setup sort of like this, but didn't really get what was going on. I have some LM393 chips coming my way hopefully next week. The attiny85 thing is working OK but as a I mentioned, it seems weird to use a microcontroller to do something like this Smile Thanks for the detailed explanation!
Back to top
View user's profile Send private message
elmegil



Joined: Mar 20, 2012
Posts: 2179
Location: Chicago
Audio files: 16

PostPosted: Sun May 10, 2015 8:02 am    Post subject: Reply with quote  Mark this post and the followings unread

You're quite welcome Smile
Back to top
View user's profile Send private message
joshs



Joined: Dec 05, 2014
Posts: 32
Location: Home

PostPosted: Fri May 15, 2015 4:36 pm    Post subject: Reply with quote  Mark this post and the followings unread

Well, I made some progress on this, but still don't quite have it settled... I built a circuit a little different then what you posted, but same concept. I used a very simple triangle wave generator circuit I found based on a hex inverter (CD40106 specifically) and then used an LM393 for the comparator. Now it blinks an LED exactly the way I want... which is great... but for some reason it's not working properly as a clock for the Arduino. I can say for sure that it's possible for the Arduino to respond to an external clock, because I have a version that works using an attiny85. That clock has a bug in it though that I can't seem to fix and I'd rather use this circuit anyway. I wonder if I need to clean up the signal somehow. I don't have an oscilloscope unfortunately. I tried adding a buffer and a couple of different capacitor/resistor combos. No change. It does trigger the Arduino, but it's erratic. Any ideas how I might get a cleaner pulse out of this?
Back to top
View user's profile Send private message
elmegil



Joined: Mar 20, 2012
Posts: 2179
Location: Chicago
Audio files: 16

PostPosted: Fri May 15, 2015 9:24 pm    Post subject: Reply with quote  Mark this post and the followings unread

what voltages?

Arduino isn't necessarily going to like the full +/-12V, in fact you could be frying it if you're feeding it that high a signal.
Back to top
View user's profile Send private message
joshs



Joined: Dec 05, 2014
Posts: 32
Location: Home

PostPosted: Fri May 15, 2015 9:36 pm    Post subject: Reply with quote  Mark this post and the followings unread

I'm using 5V for this circuit. I did feed +/-15V into the op amp for the buffer, but that was set up for unity gain and I checked that the output was around 5V. I have a power supply that does +/-15V and +5V.
Back to top
View user's profile Send private message
elmegil



Joined: Mar 20, 2012
Posts: 2179
Location: Chicago
Audio files: 16

PostPosted: Fri May 15, 2015 10:33 pm    Post subject: Reply with quote  Mark this post and the followings unread

If you're only doing 5V, you might consider putting in a schmitt trigger buffer to square up the waveform. I can't think why the op amp wouldn't be square enough, but using, for example a CD40106 and using two stages (it's a hex inverter). There's also a non-inverting buffer in the CD4000 series.

Of course you can also use a 40106 as an oscillator itself and possibly simplify things a lot, I'm just not sure off the top of my head if you can do pulse width stuff with it.
Back to top
View user's profile Send private message
joshs



Joined: Dec 05, 2014
Posts: 32
Location: Home

PostPosted: Fri May 15, 2015 10:59 pm    Post subject: Reply with quote  Mark this post and the followings unread

Yeah, I don't know for sure if it's an issue of clean edges. Could be anything I guess. Without an oscilloscope, it's hard to say. I just ordered one though, so hopefully I'll eventually figure it out. I also did try taking the pulse wave and feeding it through two stages of inversion. That didn't fix it either. I made more progress with the attiny85 version in the meantime. Although it doesn't work right at slower settings. It also has the nice feature of being easy to reset, which is something I think will be hard with the IC based circuit...
Back to top
View user's profile Send private message
joshs



Joined: Dec 05, 2014
Posts: 32
Location: Home

PostPosted: Fri May 15, 2015 11:49 pm    Post subject: Reply with quote  Mark this post and the followings unread

Some google searching ran me into hysterisis which wound up being the solution to the problem. I added a 130K resistor from output to + and now it works. I still don't know how to reset the oscillator...
Back to top
View user's profile Send private message
elmegil



Joined: Mar 20, 2012
Posts: 2179
Location: Chicago
Audio files: 16

PostPosted: Sat May 16, 2015 9:14 am    Post subject: Reply with quote  Mark this post and the followings unread

Can you post the circuit you actually used? I was forgetting that earlier.

Also remind me what you mean by sync.

If we're talking sync like common oscillator sync, a common approach is to put a FET across the timing cap, and have the sync signal turn on the fet, which discharges the cap. But there are other particulars that would depend on the circuit.

Good find with the 130K resistor, i wasn't thinking about that, but yeah, that makes sense.
Back to top
View user's profile Send private message
arpeggio



Joined: Jan 05, 2010
Posts: 24
Location: the Netherlands

PostPosted: Wed May 27, 2015 11:58 am    Post subject: sync to mid clock Reply with quote  Mark this post and the followings unread

Hello, read your messages, i am using midiclock signals from a synth to sync other timing tings to the other, via an Arduino running the MIDI library
I don't know i you are interested in this way of syncing, you use electronical signals, and this are midi signals, anyway works like a charm,
Let me know if you are interested,
Dian from the Netherlands
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic
Page 1 of 1 [18 Posts]
View unread posts
View new posts in the last week
Mark the topic unread :: View previous topic :: View next topic
 Forum index » DIY Hardware and Software » Arduino
Jump to:  

You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Forum with support of Syndicator RSS
Powered by phpBB © 2001, 2005 phpBB Group
Copyright © 2003 through 2009 by electro-music.com - Conditions Of Use