DDS (generating sine waves) with onboard DAC using latest PIC 16F chips?


Closed Thread
Results 1 to 40 of 77

Hybrid View

  1. #1
    Join Date
    Aug 2010
    Location
    Maryland, USA
    Posts
    869


    Did you find this post helpful? Yes | No

    Default Re: DDS (generating sine waves) with onboard DAC using latest PIC 16F chips?

    even if you had to dedicate the PIC to nothing else, due to the burden placed on it
    Hank, this is a great idea. Seems like you should be able to do it with any basic device if this is all you want it to do. The comm's to it will be the only thing to worry with. So lets be clear what you want here -
    1Hz-5KHz sine wave
    fixed amplitude
    A way to get its attention to change the freq.

    Do I have this correct?

    just remembered one thing, did you say NO passive devices?
    Last edited by cncmachineguy; - 26th August 2011 at 18:56.
    -Bert

    The glass is not half full or half empty, Its twice as big as needed for the job!

    http://foamcasualty.com/ - Warbird R/C scratch building with foam!

  2. #2
    Join Date
    Mar 2009
    Posts
    653


    Did you find this post helpful? Yes | No

    Default Re: DDS (generating sine waves) with onboard DAC using latest PIC 16F chips?

    Hi Bert,

    Quote Originally Posted by cncmachineguy View Post
    Seems like you should be able to do it with any basic device
    Agreed...even though I'm using a 16f1828 to practise with, my favourite low chip end of the moment is an 8 pin 12f1822. So a simple DDS program + servicing an odd interrupt (for frequency change)...should be a walk in the park. I also think even a low end 12f chip is going to be much more capable of outputting more than 5Khz...but I mentioned that frequency, only because it's all I need.

    Quote Originally Posted by cncmachineguy View Post
    1Hz-5KHz sine wave
    fixed amplitude
    A way to get its attention to change the freq.

    Do I have this correct?
    Correct, I would add, granularity to 0.01Hz or better (this is perhaps the most important requirement for me). That's where the larger accumulator is needed
    (see my other post - http://www.picbasic.co.uk/forum/show...887#post106887 )

    Without want to teach granny to suck eggs, the output frequency granularity is established from this formula...

    interrupt frequency/ accumulator

    So for an interrupt rate of say 20khz & a 16 bit accumulator, it'd be

    20,000/65536 = 0.30Hz granularity which is insufficient for my needs, which means either making the accumulator larger, or the sample rate smaller....I don't want to do the latter, hence wanting to make the accumulator larger, but I then start hitting my knowledge boundary dealing in 17 bit+ numbers witin the confines of picbasic.

    Also, there's likely to be a fair degree of floating point...which I'll have to work around. For example to set the required freqency, it's

    (required frequency/sinterrupt rate)*accumulator , so for 1500Hz

    (1500Hz/20,000) * 65536 ........clearly the first part of that equation is going to result in a decimal, so quite a few things impeding me at the moment!

    re no passive devices ...well, ideally no reactive passive devices (on account they alter the amplitude as the frequency changes)....using an R2R ladder would be cool, except the take up a lot of space & that's something I always try to avoid (I can't seem to locate anyone that sells prefabbed R2R ladders here in the UK)
    Last edited by HankMcSpank; - 26th August 2011 at 19:55.

  3. #3
    Join Date
    Aug 2010
    Location
    Maryland, USA
    Posts
    869


    Did you find this post helpful? Yes | No

    Default Re: DDS (generating sine waves) with onboard DAC using latest PIC 16F chips?

    On the passives, I was thinking about the fact we can only output 2 levels, Vcc and Vdd, so the "sine" wave won't be. I have found R2R sips before, but that would also require enough I/O to service it in parallel.

    What do we do about the not analog output?
    -Bert

    The glass is not half full or half empty, Its twice as big as needed for the job!

    http://foamcasualty.com/ - Warbird R/C scratch building with foam!

  4. #4
    Join Date
    Mar 2009
    Posts
    653


    Did you find this post helpful? Yes | No

    Default Re: DDS (generating sine waves) with onboard DAC using latest PIC 16F chips?

    I think we're at crossed wires a little.

    My first (present) plan of attack is to use the 5 bit internal DAC to get an anlogue output... (that's what my screenscrape was earlier - using the PIC's internal DAC to get a rough analogue output) clearly 32 steps is insufficent for sine waves, so I was trying to add an extra 2 bits by creatively using the PIC Fixed voltage reference (the PIC FVR output canfeed the DAC and the voltagae output can be set to 1.024V, 2.048V or 4.096V) - I might not be grasping a fundamental issue here, so I need to ponder this one until I have an "Oops, that was an embarrassing idea" moment!

    If the above comes to nothing then I'll relent & use HPWM and a filter (I only had a brief go at this a year or so ago & didn't actually test how much the reactance of the cap in such an arrangement impacts the amplitude...over the range I'm interested (0-5khz) it mght not be that much. I'm of the opinion that I'll end up having to go this way...then all I have to crack is the accumulator problem (need more than 16 bits) & the little bit of floating point (to get the accumulator value needed for the required frequency)

    Clearly if I end up going the R2R route, then I'll need to bring a 14 pin PIC into service (likely to be a 16f1824)

  5. #5
    Join Date
    Mar 2009
    Posts
    653


    Did you find this post helpful? Yes | No

    Default Re: DDS (generating sine waves) with onboard DAC using latest PIC 16F chips?

    Quote Originally Posted by HankMcSpank View Post
    My first (present) plan of attack is to use the 5 bit internal DAC to get an anlogue output... (that's what my screenscrape was earlier - using the PIC's internal DAC to get a rough analogue output) clearly 32 steps is insufficent for sine waves, so I was trying to add an extra 2 bits by creatively using the PIC Fixed voltage reference (the PIC FVR output canfeed the DAC and the voltagae output can be set to 1.024V, 2.048V or 4.096V) - I might not be grasping a fundamental issue here, so I need to ponder this one until I have an "Oops, that was an embarrassing idea" moment!
    Well, I reckon this one is doomed ...I've only just realised for my plan to work, I would need to be able to shift the 'negative ref' of the DAC to the FVR module output (I'd then get 32 steps between gnd & FVR ref, then another 32 steps between FVR & Vref) - the 16f1828 DAC control register doesn't allow this...hey ho.

    Ok, so HPWM and a filter it is then...at least I'll see what impact there is on amplitude as the frequency rises!

  6. #6
    Join Date
    Aug 2010
    Location
    Maryland, USA
    Posts
    869


    Did you find this post helpful? Yes | No

    Default Re: DDS (generating sine waves) with onboard DAC using latest PIC 16F chips?

    Ok, so I am now up to speed with you who is up to speed with me. We can now plod along blindly together - LOL. I was thinking of doing this all with software so as not to be dependent on HPWM. Chasing the single low cost PIC for 1 purpose, I was assuming HPWM may not be available.

    Quick question, what is the fastest time needed? ie, 5,000hz has a time of .2mS, but 5,000.01 has a time of .199999mS. so you want .1uS, .01uS,1uS,bla bla bla. on the other hand 100hz is 10mS while 100.01Hz is 9.9999mS.

    As you can see, I am having conceptual trouble here with the .01Hz spec.
    -Bert

    The glass is not half full or half empty, Its twice as big as needed for the job!

    http://foamcasualty.com/ - Warbird R/C scratch building with foam!

  7. #7
    Join Date
    Mar 2009
    Posts
    653


    Did you find this post helpful? Yes | No

    Default Re: DDS (generating sine waves) with onboard DAC using latest PIC 16F chips?

    Quote Originally Posted by cncmachineguy View Post
    Ok, so I am now up to speed with you who is up to speed with me. We can now plod along blindly together - LOL. I was thinking of doing this all with software so as not to be dependent on HPWM. Chasing the single low cost PIC for 1 purpose, I was assuming HPWM may not be available.

    Quick question, what is the fastest time needed? ie, 5,000hz has a time of .2mS, but 5,000.01 has a time of .199999mS. so you want .1uS, .01uS,1uS,bla bla bla. on the other hand 100hz is 10mS while 100.01Hz is 9.9999mS.

    As you can see, I am having conceptual trouble here with the .01Hz spec.
    Maybe I'm too ambitious with the .01Hz accuracy, maybe .1hz is more achievable (initially)....as it goes, I actually only need that accuracy at the lower end of the 60hz-5,000Hz frequency range (where obviously 0.1Hz error of say 60hz is a whole lot more in percentage terms than .1Hz for 5khz) but with DDS you have to decide on the acceptable resolution then be stuck with it across the frequency band. so yes, say 50.01Hz, 50.02Hz, 50.3Hz thru 5,000Hz is what I hope to achieve here.

    I've read that DDS 'interrupt rate' should be at least twice the targetted/required highest freqency, which since I want 5Khz, should mean a minimum interrupt of 10khz...but I thought 20Khz might be better. So with a 16 bit accumulator, we get....

    audio ouput frequency granularity = 20,000/65536 or 0.31hz (which is not enough) ...even dropping the interrupt rate to 10khz means granularity of 0.15Hz)

    That said, for proof of concept, maybe I just go with that initially ....ie 10,000 interrupts per second and a simple 16 bit accumulator - once that's been proven, then we can stride out a bit!
    Last edited by HankMcSpank; - 27th August 2011 at 00:30.

Members who have read this thread : 1

You do not have permission to view the list of names.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts