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
    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 scalerobotics View Post
    On a side note I see there is a future product with an 8 bit DAC. Im on my phone, so I can't tell if there is even a dataxheet out for it. Pic16f1786 is one of them.
    That's excellent input - I wasn't aware...this is the type of PIC I've been waiting for all this time (integral opamps too), seems to be a few variants, found this product brief for the 16f17822/23 ...

    http://ww1.microchip.com/downloads/e...Doc/41410B.pdf (28 pins - wish it was available in a smaller package though)

    I don't suppose you have any idea how far away these products are from being able to purchase?

    Quote Originally Posted by cncmachineguy View Post
    Hank, before you go to far let me just get some clarity for those who are a little slow at time (me). If we break this down just a little and start slow is this correct: (back to pwm)
    Across 1 cycle you need to generate different duty cycle waves for each angle of the wave?
    So if you chop the wave into 255 steps(prolly too many at higher freq), each step will have a unique duty cycle. (in practice they may not all be unique at high freq)
    The amount of time that duty is output depends on the duration of the step, which is determined by the desired freq.

    Is this correct so far?
    Yes Bert, you are correct.

    Quote Originally Posted by cncmachineguy View Post
    Assuming so, seems to me you just have nested for loop structure here. If the only job of the pic isto spit out this wave, maybe doing it as a loonnnggg program with each step coded separately will work better then the interrupt. So in essence expand the lookup table to be the next for loop in the program.

    To test all of this I would just deal with the 5k freq as the slow end seems pretty easy.

    I really hope that all made sense
    yes it made sense, & I'd considered doing such a thing, but then binned that approach because clearly every line of the code would impact the time taken to 'loop' and therefore the output frequency ...fine once you've got it squared away so to speak, but a nightmare while still trying to grasp the basics and changing the program every minute or two! (which you'll no doubt gather, that's the stage I'm at!). It's a valid approach though...and may well be the end solution (it would save the overhead of getting in/out of an interrupt).
    Last edited by HankMcSpank; - 27th August 2011 at 20:40.

  2. #2
    Join Date
    Nov 2003
    Location
    Greece
    Posts
    4,170


    Did you find this post helpful? Yes | No

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

    A higher order filter as Darrel stated could help a little bit more, but I doubt it could make it a nice sin wave.

    Better resolution DAC is the way to go.

    Ioannis

  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?

    Walter, do you have the direct line to the engineers or something? You always have these cutting edge finds!!!

    Hank, it may save a lot more then the overhead of the isr, you may be able to save a bunch of computations too! That's what I am going for in my brain. Here's my first snag- at 5k, 1 cycle is 200 uS. So how many steps do we need in there? Clearly 250 steps would be a bunch, each step would be 10uS long. In my head, I see each step made up of 255 sections, each section lasting some pre defined amount of time to make up the duty for that step.
    So using the above 10uS big step number, we have to do 255 somethings in 10uS. That will be a bit troublesome.
    Got any ideas how long we can make a big step and keep the resolution at 5k?
    -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
    Feb 2006
    Location
    Gilroy, CA
    Posts
    1,530


    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
    Walter, do you have the direct line to the engineers or something?
    Hah, I wish! I infrequent the Microchip MAPS search utility just enough that sometimes I get pleasantly surprised. I can't find anything that tells me the release date. Here's the data sheet for the 16f1782/3, but you probably already found it. http://ww1.microchip.com/downloads/e...Doc/41579B.pdf . And as an added bonus, PBP3.0 already supports the 16F1782/3 devices!

  5. #5
    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?

    Hank you could get the QFP package, 28 pins in a 4mmX4mm space
    -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!

  6. #6
    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
    Hank you could get the QFP package, 28 pins in a 4mmX4mm space
    QFP at 0.5mm pitch is a bit too challenging for my soldering iron..



    Just noticed a discrepancy, on the Microchip site ....the 'highlights' of the PIC16Ff1782/3 has 4 x 8 bit timers & 1 x 16 bit timer shown...

    http://www.microchip.com/wwwproducts...cName=en552738

    but in the datasheet it's only talking of 2 x 8 bit timers & 1 x 16 bit timer...

    http://ww1.microchip.com/downloads/e...Doc/41579B.pdf

    Bert...re your former post/points, it's late here in the UK, I've now had a couple of beers too....this is challenging for McSpank's grey matter even when sober, so I'll defer until later!
    Last edited by HankMcSpank; - 28th August 2011 at 01:26.

  7. #7
    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?

    OMG!!! Hank I would be way challanged using those on 1/4" spade terminals with 14GA wire. LMAO!!!!!
    -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!

  8. #8
    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?

    ok, not running interrupts here, just the bare minimum main loop (as per Bert's proposal)...

    Code:
    tuning_word         VAR word
    accumulator         VAR WORD
    '
    ACCUMULATOR = 0          ' clear down the accumulator before starting.
    TUNING_WORD = 1     ' 
    '
    Main:
    ACCUMULATOR = ACCUMULATOR + tuning_word
    '
    Lookup Accumulator.HighBYTE, [$80,$83,$86,$89,$8C,$8F,$92,$95,$98,$9C,$9F,$A2,$A5,$A8,$AB,$AE,$B0,$B3,$B6,$B9,$BC,$BF,$C1,$C4,_
    $C7,$C9,$CC,$CE,$D1,$D3,$D5,$D8,$DA,$DC,$DE,$E0,$E2,$E4,$E6,$E8,$EA,$EC,$ED,$EF,$F0,$F2,$F3,$F5,$F6,$F7,$F8,$F9,$FA,$FB,$FC,$FC, _
    $FD,$FE,$FE,$FF,$FF,$FF,$FF,$FF,$FF,$FF,$FF,$FF,$FF,$FF,$FE,$FE,$FD,$FC,$FC,$FB,$FA,$F9,$F8,$F7,$F6,$F5,$F3,$F2,$F0,$EF,$ED,$EC, _
    $EA,$E8,$E6,$E4,$E2,$E0,$DE,$DC,$DA,$D8,$D5,$D3,$D1,$CE,$CC,$C9,$C7,$C4,$C1,$BF,$BC,$B9,$B6,$B3,$B0,$AE,$AB,$A8,$A5,$A2,$9F,$9C, _
    $98,$95,$92,$8F,$8C,$89,$86,$83,$7F,$7C,$79,$76,$73,$70,$6D,$6A,$67,$63,$60,$5D,$5A,$57,$54,$51,$4F,$4C,$49,$46,$43,$40,$3E,$3B, _
    $38,$36,$33,$31,$2E,$2C,$2A,$27,$25,$23,$21,$1F,$1D,$1B,$19,$17,$15,$13,$12,$10,$0F,$0D,$0C,$0A,$09,$08,$07,$06,$05,$04,$03,$03, _
    $02,$01,$01,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$01,$01,$02,$03,$03,$04,$05,$06,$07,$08,$09,$0A,$0C,$0D,$0F,$10,$12,$13, _
    $15,$17,$19,$1B,$1D,$1F,$21,$23,$25,$27,$2A,$2C,$2E,$31,$33,$36,$38,$3B,$3E,$40,$43,$46,$49,$4C,$4F,$51,$54,$57,$5A,$5D,$60,$63, _
    $67,$6A,$6D,$70,$73,$76,$79,$7C],PORTC
    '
    goto main
    '
    END
    not sure if my maths is correct here, but

    total number of sine 'slices' = 256 (1 period...ie all the values in the array)

    accumulator is 16 bits long therefore counts to 65536 & rolls over

    With the tuning word set to 1 (this is the number added to the accumulator on each loop)

    My scope measures a waveform frequency of 5.09Hz, therefore...

    sampling rate = Frequency/tuning word * accumulator or 5.09/1 * 65536 = 333,578hz ..........or a sampling rate of 333.578khz (ie how often the main loop is erhm looping)

    ...this actually kinda sucks for a DDS sampling rate (most of the DDS solutions talk of a mega high sampling rate) ....I'm running my PIC at 32Mhz Osc (8mhz * 4 PLL), therefore instruction clock of 8Mhz.



    The highest frequency with all the bits in the array being read properly (vs being skipped) is now about 1.3Khz....



    Any top tips for getting the effective sampling rate even higher? (ie getting the main loop to run faster)
    Last edited by HankMcSpank; - 28th August 2011 at 19:40.

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