Programmable Oscillator - Page 1
Forum section: electronics / projects

author: David_AVD
author_rank: Super Contributor
timestamp: July 01, 2012, 06:24:46 am
content: I'd like to make a programmable oscillator (serial control to enable me to automate some testing) as part of a test rig. (see myother thread). I'm using a $100 function generator for now, but the display resolution of 1Hz is somewhat limiting.The area of interest right right now is approx 0Hz to 200Hz for simulating anemometer pulses going into a weather station. Adjustable symmetry would allow me to better simulate the short pulses from the reed switch.So, this sounds somewhat like a very low frequency PWM signal for my current application, but I'd rather build something a bit more universal and with a frequency range of 0.1Hz to 50Khz or so.Software PWM on a PIC will only do very low frequencies and hardware PWM on a PIC won't go down low enough. I've looked at the Analog Devices DDS chips, but have no experience with them yet.I looked at the Rigol AWG for about $400 as a ready made solution, but has anyone done this as a DIY project?

author: Psi
author_rank: Super Contributor
timestamp: July 01, 2012, 06:39:08 am
content: Are you sure hardware PWM wont go slow enough on a PIC?I know with AVR's that some chips have more (slower) divider options than others. I'd imagine its the same with PICs.Can you set the mcu timer clocking to an external input pin? That way you can supply it with a frequency that can be converted to all timing values in the range you need?

author: Bored@Work
author_rank: Super Contributor
timestamp: July 01, 2012, 06:56:03 am
content: If PWM is to fast you could add a simple divider/counter IC. The standard logic IC series have several.

author: Psi
author_rank: Super Contributor
timestamp: July 01, 2012, 07:07:31 am
content: That's a better option, A divider on the output will be easier/cheaper/quicker.

author: David_AVD
author_rank: Super Contributor
timestamp: July 01, 2012, 08:07:39 am
content: I'm pretty sure using any sort of post-scaler will remove the PWM timing (symmetry / duty cycle) that I'd like to incorporate.

author: 0xdeadbeef
author_rank: Super Contributor
timestamp: July 01, 2012, 10:00:50 am
content: It might be a bit of overkill, but just as a suggestion: I recently did some semi-private projects with an LPC1768. That's a 100MHz Cortex-M3 ARM CPU with pretty good timer peripherals. The nice thing about it that all the timers and PWMs are true 32bit. So you have e.g. three (or six single edged) 32bit PWM channels where each channel has a 32bit prescaler (in addition to a rough main prescaler) and the maximum timer frequency is the core frequency (100MHz). Note that this means a resolution of 10ns with a timer overflow only after ~42.9s - and at 50kHz you'd still have 2000 timer ticks per period.There are also 4 more general purpose 32bit timers with DMA transfer capability. With them you can create nonperiodic pulses with very accurate timings. E.g. just for fun, I implemented a (lores 8-color) VGA output this way.On top of it, you can connect the PWMs and timer channels to an external clock input. This way you can e.g. create your clock with one timer channel and thus increase the frequency of the other channels in very fine steps (while the 32bit prescaler is much too course for low values). I used this for a four channel engine speed simulator which can be adjusted from 1-10000rpm in 1rpm steps.There are cheapeva boardsandprogrammersavailable and the LPC17xx family is supported by the free IDECooCox(GCC+GDB+Eclipse).

author: David_AVD
author_rank: Super Contributor
timestamp: July 01, 2012, 10:33:01 am
content: That CPU sounds pretty cool, although I'm not keen on learning about a new processor family. I currently program PIC micros mostly in assembler.

author: 0xdeadbeef
author_rank: Super Contributor
timestamp: July 01, 2012, 11:03:40 am
content: Well, might be only my point of view, but if you really know one microcontroller and its peripherals, you can usually easily get into another - even it it has some different concepts.Of course moving from one µC to another is easier if you program in C and if there is already a stable core/driver base. E.g. in CooCox, there is a more or less complete library for all the peripherals. Indeed I rewrote everything but the very core stuff (and the USB driver) for my own projects, but it's always good to have a working base to start from.

author: digsys
author_rank: Unknown
timestamp: July 01, 2012, 11:17:53 am
content: Unless you need nS precision, set up a timer for E.G. 1mS - 10mS Interrupts. If you don't have a spare timer PRESET,just use the O/Flow interrupt. In the Interrupt rountine, simply - INCR an 8 or 16+ bit register - compare to your (nowalmost unlimited time value) and SET/RST the OP pin. The M/S width accuracy is whatever IRQ value you set.Even with a cheap 1mip CPU, you should be able to achieve 1-5% jitter.

author: David_AVD
author_rank: Super Contributor
timestamp: July 01, 2012, 12:02:42 pm
content: A 1ms interrupt is only going to give 500Hz max square wave though. That would do for my immediate means but I'm thinking beyond that.An AWG is sounding better by the minute. The Rigol 1022 (I think?) can be had for $399 + GST so that may be the most appropriate route.

author: digsys
author_rank: Unknown
timestamp: July 01, 2012, 12:23:47 pm
content: QuoteThe 1mS / 10mS routine is ONLY for say 0.1 sec-1000+ sec timing. For high freq, your code wouldbe setting the Timer registers directly and ONLY need to switch to this extra routine forthe long timer periods. Best of both worlds and pretty easy to set up.

author: David_AVD
author_rank: Super Contributor
timestamp: July 01, 2012, 12:37:06 pm
content: QuoteQuote from: digsys on July 01, 2012, 12:23:47 pmAh, I see what you mean now. I had thought of switching modes, but was looking for an easy solution.I'm now thinking that any development time spent on this item would be better used charging clients for R&D. That will pay for a low cost AWG in a few hours.

author: digsys
author_rank: Unknown
timestamp: July 01, 2012, 12:58:11 pm
content: QuoteYou learn fast grasshopper :-)

author: hlavac
author_rank: Frequent Contributor
timestamp: July 01, 2012, 01:57:52 pm
content: I'm pretty sure you can make this with just the bare PIC.Combine software with hardware timers and PWM.Use just hardware for high frequencies, extend with software for lower frequencies.

author: David_AVD
author_rank: Super Contributor
timestamp: July 02, 2012, 02:15:32 am
content: Rigol DG1022 ordered.Now I just need to make a boxed version of my isolated volts to closure adapter.I use a bit of proto board with a VO1400AEFTR SSR as the output is good to 60V and it has back to back output FETs.

author: David_AVD
author_rank: Super Contributor
timestamp: July 04, 2012, 12:15:35 am
content: Rigol DG1022 received this morning. Already unpacked, hooked up and doing something useful.Much nicer being able to dial in the exact frequency I want.I'll have a play with the USB interface side of it later this week.

author: digsys
author_rank: Unknown
timestamp: July 04, 2012, 02:35:27 am
content: QuoteThat wast fast ! Ya never get tired of playing with new toys !! Have fun

author: David_AVD
author_rank: Super Contributor
timestamp: July 04, 2012, 03:02:48 am
content: I bought it from Emona for approx $455 including delivery and GST. That seemed to be the best deal for an Australian delivered unit with local warranty.