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
    Oct 2005
    Location
    Sweden
    Posts
    3,612


    Did you find this post helpful? Yes | No

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

    Ionnis, that's a very good point!
    However, if DT-Ints are used it saves and restores those variables so I don't think there's any risk of corrupting them if an interrupt occurs during the calculation phase. (?)

    If using ON INTERRUPT then you should definitely disable interrupts (or interrupt checking rather) during that calculation operation.

    Hank, what you say is true but Ioannis has a point here. The R0/R2 variables are internal PBB variables used by a host of commands. If you're in the middle of that 32bit calculations and an interrupt comes along it's very likely that the code in the ISR uses those same variables (R0 and R2) so when you return the value previosuly there is now gone and you end up with weird results.

    But like I said, the whole DT-Ints concept builds on saving the PBP system variables on ISR entry and restoring them on exit (if the handler is defined as PBP-handler) so I don't think it's going to be a problem.

    Anyway, that calculation should only be executed when the frequency is changing so even if you SHOULD need to disable interrupts it won't make much difference.

    /Henrik.

    EDIT: Oooh, Hank, I think you're in for some trouble in the long run..... You have your handler defined as ASM yet we're doing a host of "PBP-work" in the handler. If you're not very carefull and know exactly what you're doing that is a very likely cause for trouble and data corruption due what is described above. Either write the handler in ASM or define as it type PBP and include the Re-Enter file.

    EDIT2: Currently it might not be a problem since you're not doing anything in the main loop but as soon as you start doing things there it's going to go havoc.
    Last edited by HenrikOlsson; - 27th August 2011 at 15:14.

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


    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 HenrikOlsson View Post
    Anyway, that calculation should only be executed when the frequency is changing so even if you SHOULD need to disable interrupts it won't make much difference.
    At 32Mhz no one will notice

    Ioannis

  3. #3
    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 HenrikOlsson View Post
    EDIT: Oooh, Hank, I think you're in for some trouble in the long run..... You have your handler defined as ASM yet we're doing a host of "PBP-work" in the handler. If you're not very carefull and know exactly what you're doing that is a very likely cause for trouble and data corruption due what is described above. Either write the handler in ASM or define as it type PBP and include the Re-Enter file.

    EDIT2: Currently it might not be a problem since you're not doing anything in the main loop but as soon as you start doing things there it's going to go havoc.
    Good spot (cut & paste from another program + laziness!) - now changed.

    The frequency is very easy to set though (presently I work out the tuning word value by way of a simple spreadsheet!)

    Higher frequencies look ugly as sin (I even cranked the interrupt rate up - not much better) ...maybe it's just the simple filter I used ....hmm, not sure that PWM is gonna be the solution here (as expected the signal amplitude is related to frequency eg 400hz about 4V peak to peak but 4000hz circa 3.5V peak to peak, it'll be worse with a two pole filter) ...it looks like an R2R ladder is going to be the way forward...damnit!
    Last edited by HankMcSpank; - 27th August 2011 at 15:26.

  4. #4
    Join Date
    Oct 2005
    Location
    Sweden
    Posts
    3,612


    Did you find this post helpful? Yes | No

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

    Hi Hank,
    There might be also a problem with the code I posted. This is new territory for me as well.

    I think that the PWM is one part of the problem, do try it with a R2R resistor DAC on a port and see what happens?

    However, don't forget how this works.... The lookup table is 256 entries long. At 500Hz output frequency you would need an interrupt rate of 500*256=128kHz to "hit" every entry in the table (thus producing the highest possible quality output). As the frequency goes up more and more of the table entries are skipped, you might "hit" entry 5, 75, 145, 205, 29, 9, 169, 239, 53, 123,193, 7 and so on. Plotting those values and drawing a straight line between them isn't going to produce a very pretty sine-wave.

    I suck at filter desing and analog stuff (too) so I can't help much with the filter desing.

    /Henrik.

  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?

    The scoped waveform didn't show the main problem... at higher waveform frequencies there was ripple moving through the waveform (left to right)....I'm thinking it might be a 'beat' frequency relating to the difference between the pwm rate & interrupt rate (or it may be that my filter is just too woeful). Anyway, whilst pwm might be just the ticket for very low frequencies or static (or narrow range) of frequencies...I don't think it's the solution here.

    ok, I can feel an R2R ladder coming on!

  6. #6
    Join Date
    Nov 2003
    Location
    Greece
    Posts
    4,132


    Did you find this post helpful? Yes | No

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

    How is your filter constructed?

    Ioannis

  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 Ioannis View Post
    How is your filter constructed?

    OP PIN -> 2.2K resistor------------------> scope
    .....................................|
    .................................01uf cap
    .....................................|
    ...................................Gnd


    ok, I've implemented an R2R ladder - much nicer....but not without issue.

    The waveform is rather nice up to about 1.5khz, but then it starts degrading , this is 3.33khz..



    ok, so that doesn't look too bad (but when you make it larger, it's steppy)

    If I up the interrupt rate things get better, but I can't get the interrupt rate any faster than about 80khz, before I hit a wall.

    Firstly with DTS_INT using 'pbp' ...woeful, can't get the interrupt rate above 20Khz

    Next DTS_INT using 'asm' instead ...I can get the interrupt rate past 80khz before my scope measures a different output frequency to what it should be present.

    there's almost nothing in my interrupt routine....

    Code:
    DDS:
    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
    @ INT_RETURN
    I'm now realising why everyone has assembly in their interrupts!
    Last edited by HankMcSpank; - 27th August 2011 at 17:47.

  8. #8
    Join Date
    Jul 2003
    Location
    Colorado Springs
    Posts
    4,959


    Did you find this post helpful? Yes | No

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

    80Khz?

    CD audio has a 44.1khz sample rate.
    If it doesn't sound right at that frequency, the problem probably isn't the interrupt rate, and faster won't help.
    DT

  9. #9
    hariuc's Avatar
    hariuc Guest


    Did you find this post helpful? Yes | No

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

    Hi to all,

    Hope all r doing well.

    I have recently joined this forum and quit impressed about the DDS discussion.

    I have generated sine wave using PWM of pic16f with fixed frequency. my goal is to generate a sine wave in range of frequency from 1 Hz to 500 Hz with the step of 1 Hz. while doing so i am unable to vary the frequency in step of 1 Hz by changing either PWM frequency or number of samples in sine wave.

    As i am unable to produce a sine wave with step accuracy using PWM. i am thinking to use some other on chip module like DAC to achieve my goal.

    Please give me your valuable suggestions about, what module i should use to get my job done.

    thanks

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