Author Topic: Programmable Oscillator  (Read 6381 times)

0 Members and 1 Guest are viewing this topic.

Offline David_AVDTopic starter

  • Super Contributor
  • ***
  • Posts: 2863
  • Country: au
Programmable Oscillator
« on: July 01, 2012, 06:24:46 am »
I'd like to make a programmable oscillator (serial control to enable me to automate some testing) as part of a test rig.  (see my other 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?
 

Offline Psi

  • Super Contributor
  • ***
  • Posts: 10229
  • Country: nz
Re: Programmable Oscillator
« Reply #1 on: July 01, 2012, 06:39:08 am »
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?

Greek letter 'Psi' (not Pounds per Square Inch)
 

Offline Bored@Work

  • Super Contributor
  • ***
  • Posts: 3932
  • Country: 00
Re: Programmable Oscillator
« Reply #2 on: July 01, 2012, 06:56:03 am »
If PWM is to fast you could add a simple divider/counter IC. The standard logic IC series have several.
I delete PMs unread. If you have something to say, say it in public.
For all else: Profile->[Modify Profile]Buddies/Ignore List->Edit Ignore List
 

Offline Psi

  • Super Contributor
  • ***
  • Posts: 10229
  • Country: nz
Re: Programmable Oscillator
« Reply #3 on: July 01, 2012, 07:07:31 am »
That's a better option, A divider on the output will be easier/cheaper/quicker.
Greek letter 'Psi' (not Pounds per Square Inch)
 

Offline David_AVDTopic starter

  • Super Contributor
  • ***
  • Posts: 2863
  • Country: au
Re: Programmable Oscillator
« Reply #4 on: July 01, 2012, 08:07:39 am »
I'm pretty sure using any sort of post-scaler will remove the PWM timing (symmetry / duty cycle) that I'd like to incorporate.
 

Offline 0xdeadbeef

  • Super Contributor
  • ***
  • Posts: 1580
  • Country: de
Re: Programmable Oscillator
« Reply #5 on: July 01, 2012, 10:00:50 am »
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 cheap eva boards and programmers available and the LPC17xx family is supported by the free IDE CooCox(GCC+GDB+Eclipse).
Trying is the first step towards failure - Homer J. Simpson
 

Offline David_AVDTopic starter

  • Super Contributor
  • ***
  • Posts: 2863
  • Country: au
Re: Programmable Oscillator
« Reply #6 on: July 01, 2012, 10:33:01 am »
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.
 

Offline 0xdeadbeef

  • Super Contributor
  • ***
  • Posts: 1580
  • Country: de
Re: Programmable Oscillator
« Reply #7 on: July 01, 2012, 11:03:40 am »
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.
Trying is the first step towards failure - Homer J. Simpson
 

Offline digsys

  • Supporter
  • ****
  • Posts: 2209
  • Country: au
    • DIGSYS
Re: Programmable Oscillator
« Reply #8 on: July 01, 2012, 11:17:53 am »
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 (now
almost 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.
Hello <tap> <tap> .. is this thing on?
 

Offline David_AVDTopic starter

  • Super Contributor
  • ***
  • Posts: 2863
  • Country: au
Re: Programmable Oscillator
« Reply #9 on: July 01, 2012, 12:02:42 pm »
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.
 

Offline digsys

  • Supporter
  • ****
  • Posts: 2209
  • Country: au
    • DIGSYS
Re: Programmable Oscillator
« Reply #10 on: July 01, 2012, 12:23:47 pm »
Quote
A 1ms interrupt is only going to give 500Hz max square wave though
The 1mS / 10mS routine is ONLY for say 0.1 sec-1000+ sec timing. For high freq, your code would
be setting the Timer registers directly and ONLY need to switch to this extra routine for
the long timer periods. Best of both worlds and pretty easy to set up.
Hello <tap> <tap> .. is this thing on?
 

Offline David_AVDTopic starter

  • Super Contributor
  • ***
  • Posts: 2863
  • Country: au
Re: Programmable Oscillator
« Reply #11 on: July 01, 2012, 12:37:06 pm »
Quote
A 1ms interrupt is only going to give 500Hz max square wave though

The 1mS / 10mS routine is ONLY for say 0.1 sec-1000+ sec timing.

Ah, I see what you mean now.  I had thought of switching modes, but was looking for an easy solution.  ;D

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.
 

Offline digsys

  • Supporter
  • ****
  • Posts: 2209
  • Country: au
    • DIGSYS
Re: Programmable Oscillator
« Reply #12 on: July 01, 2012, 12:58:11 pm »
Quote
... Ah, I see what you mean now.  I had thought of switching modes, but was looking for an easy solution.  ;D
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.
You learn fast grasshopper :-)
Hello <tap> <tap> .. is this thing on?
 

Offline hlavac

  • Frequent Contributor
  • **
  • Posts: 536
  • Country: cz
Re: Programmable Oscillator
« Reply #13 on: July 01, 2012, 01:57:52 pm »
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.
Good enough is the enemy of the best.
 

Offline David_AVDTopic starter

  • Super Contributor
  • ***
  • Posts: 2863
  • Country: au
Re: Programmable Oscillator
« Reply #14 on: July 02, 2012, 02:15:32 am »
Rigol DG1022 ordered.   ;D

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.
 

Offline David_AVDTopic starter

  • Super Contributor
  • ***
  • Posts: 2863
  • Country: au
Re: Programmable Oscillator
« Reply #15 on: July 04, 2012, 12:15:35 am »
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.
 

Offline digsys

  • Supporter
  • ****
  • Posts: 2209
  • Country: au
    • DIGSYS
Re: Programmable Oscillator
« Reply #16 on: July 04, 2012, 02:35:27 am »
Quote
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.
That wast fast ! Ya never get tired of playing with new toys !! Have fun
Hello <tap> <tap> .. is this thing on?
 

Offline David_AVDTopic starter

  • Super Contributor
  • ***
  • Posts: 2863
  • Country: au
Re: Programmable Oscillator
« Reply #17 on: July 04, 2012, 03:02:48 am »
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.
 


Share me

Digg  Facebook  SlashDot  Delicious  Technorati  Twitter  Google  Yahoo
Smf