Xtal-locked DDS audio sine generator with just a PIC 18F1320

MMcLaren

Joined Feb 14, 2010
859
I'll nitpick that one because it doesn't "match the performance" it matches the freq but has 20% less vertical resolution. In signal generation that can be significant although I agree it's less ciritcal in this case and for a budget sine signal generator app you came close to matching the performance. ;)
Well, I believe it does match the performance for this particular application. Let me explain why I think so and perhaps the experts will correct me if I'm wrong;

Here's a plot (below) of duty cycle to output voltage for a pair of 256 element sine arrays, one with 80 duty cycle steps and the other with 100 duty cycle steps. It's an overlay plot and if you look very closely you can just see some blue spots from the 80 level plot peeking through from underneath the red 100 level plot. I did not make any attempt to fine tune either array or account for rounding errors. Even so, the plots are nearly identical.

I believe that 64 duty cycle levels would produce a very nice wave form in this particular application and that using 80 levels is overkill. If 80 duty cycle levels is overkill, 100 levels is merely more overkill and will not contribute to performance in a significant way. In this case you could claim that 80 levels is less overkill compared to 100 levels, but I don't think you can claim that 100 levels will have significantly better performance.

I'd love to hear what the experts think and if they would characterize the 80 level wave form pictured below to be deficient in any way.

Kind regards, Mike


 

Attachments

Last edited:

Thread Starter

THE_RB

Joined Feb 11, 2008
5,438
Although your sine images are too small and too high a freq to show it Mike, there are three problems that arise from reducing the waveform vertical resolution;

1. It increases distortion at the table. Generating the sine table adds distortion as each perfect sine value must be rounded to the nearest integer value. So a 20% reduction in vert resolution is an average 20% increase in distortion of table entries.

2. It increases the size of low frequency steps when the sine is produced at a low frequency. A sine of 1kHz will be produced from 256 table entries so the steps are occuring at 1000/256 = 3.9Hz, so this is a vertical distortion added to the sine resulting in a 3.9Hz component superimposed on the 1kHz sine. With a vertical resolution of 80 this error component is 20% larger than when a resolution of 100 vert steps is used. At very low frequencies (where the RC filter does much less filtering) the /256 component is practically a square wave, so that component is superimposing not only the /256 frequency but all its associated harmonics, causing multiple frequencies added to the sine.

3. At mid-range frequencies one of the problems of a DDS wavetable is that it gets to a point where there are no longer a full 256 steps used to make the table. With a 400kHz DDS cycle this occurs at frequencies just over 1562Hz. At these frequencies some of the 256 steps are removed, causing an increase in horizontal error (distortion) as not only is there vertical distorion from the height of the table steps, there is added horizontal distortion because the position of the table step horizontally no longer matches the perfect horizontal position on the sinewave. With increased vertical step size both the vertical and horzontal distortion are increased.

I wasn't particularly happy about having only 100 vertical steps (actually I used 95 to allow better reporduction of the sine peaks.) But to counter problem 3 above I deliberately chose filter values that were quite effective at averaging out the midrange vert and horiz errors. Fortunately the filter effectiveness also extended down to below 1kHz to about 700Hz, which did well to remove much of problem 2 as the superimposed step frequency was now well below 3Hz and for audio testing should be below the freq response of most amps etc.

But problem 2 itself always remains, which you should see (Mike) if you set the freq of your sine to 50Hz or 100Hz significant vertical stepping. That could still be a problem if testing an amp with DC freq response or sinewaves for an inverter etc. A switchable filter would be of big help, but I didn't include one as I wanted to keep the project complexity as low as possible and not scary for beginners.

Likewise it could be fixed in software by using a larger table resolution and reduced PWM freq when generating lower frequencies, which I did consider but then thought it was too much work putting in dual tables and dual DDS loops for a Christmas evening "quickie" gift project. ;)

(edit) Speaking of distortion, did you use a 2nd harmonic compensated sine table? If not I described a short cut algorithm to mimic "natural sampling" a sine in Excel here (near bottom of page); http://www.romanblack.com/onesec/Sine1kHz.htm
 

Thread Starter

THE_RB

Joined Feb 11, 2008
5,438
...
For the benefit of AAC members who don't know the inside joke. In the past over on the Electro-Tech forum I've accused Roman of elevating self-promotion to an art form. If you read through his web page he's always patting himself on the back and telling us how clever he is, and I admit, deservedly so. But, I still think it's a slightly annoying personality trait and so I tease him about it every once in awhile.
...
I guess you'll have to try to tolerate my annoying personality flaw of saying that I had put together something clever and I'll have to try to tolerate your annoying personalty flaw of being very quick to show ridicule for someone else's Christmas gift...
 

Thread Starter

THE_RB

Joined Feb 11, 2008
5,438
Firmware v2 - now has 4 waveforms

I got a spare hour tonight and added some more wavetables. With nothing connected to pins RB7 and RB6 the PIC will default to sinewave and give the same functionality as v1.

But if you connect two switches, between RB7 and GND and RB6 and GND, these select between 4 waveforms; Sine, Square, Sawtooth, Triangle.

Details are on the project web page;
http://www.romanblack.com/onesec/SineDDS.htm
 

MMcLaren

Joined Feb 14, 2010
859
I guess you'll have to try to tolerate my annoying personality flaw of saying that I had put together something clever and I'll have to try to tolerate your annoying personalty flaw of being very quick to show ridicule for someone else's Christmas gift...
Roman, I think you came up with a wonderful project and I think it's great that you have given it away as a gift. I was delighted when you gave me permission to borrow your filter design in an attempt to create a spin-off project on the 32 MHz enhanced mid-range devices and when you invited me to share ideas here on the forum. I wonder now if that may have been a mistake. If you can show me somewhere in this thread where I ridicule your design, I'm sure I would be just as shocked as you seem to be. I just don't recall doing that, except perhaps when I characterized "blind tuning" as a "problem", which I hope you feel was corrected quickly in a subsequent post. I hope you don't think that our disagreement over whether or not my 20 cycle DDS routine matches the performance of your 25 cycle routine was meant to be ridicule.

I'd love to share the "cycle banking" method I came up with late last night which would allow code for switches, LED or LCD displays, Sony SIRC remote control input, the DDS math, or whatever, to run without the DDS loop ever missing a single cycle, but I can't say you've been very receptive to my ideas or very encouraging thus far. The ideas and code I came up with were meant to facilitate moving the design over to the 32 MHz enhanced mid-range devices and should not be interpreted as criticism of your design or your code. So perhaps it's best if I stop trying to engage or collaborate with you at this point and I'd like to apologize to you and fellow forum members for butting in on your thread.

Kind regards, Mike
 

thatoneguy

Joined Feb 19, 2009
6,359
MMcLaren, don't worry about it too much, from the timestamp he probably had finished off the left over egg nog.

You both have great ideas, and I love the trick you've added to it, which allows for inputs and extra processing instead of 100% uC usage.
 

Thread Starter

THE_RB

Joined Feb 11, 2008
5,438
Haha no I barely drink at all, and not much lately. :)

Mike the "ridicule" comment was directed at what you said here; "Only impressive? You won't share some of that "clever" adjective you lavish upon yourself on your project web page (lol)?" which to me appears to firmly qualify as ridicule. It's obvious we have different personality types and different ways of communicating, so what you judge in my behaviour to be "always patting himself on the back and telling us how clever he is," to me was simply stating a fact that I had used a couple of clever tricks in the DDS loop. You may not like the way I express myself, and to be blunt I'm not entirely happy with the way you express yourself. But up to this point you were the only one doing the criticising as I prefer not to criticise someones personality until they cross the line.

MMcLaren said:
...
I'd love to share the "cycle banking" method I came up with late last night which would allow code for switches, LED or LCD displays, Sony SIRC remote control input, the DDS math, or whatever, to run without the DDS loop ever missing a single cycle,
A version of that was already implemented in my code from the start. One of the "clever tricks" I had achieved with the 25cycle DDS loop (but I had not really discussed the specifics of as nobody asked until now) was that it continues to make the correct frequency even when the buttons are pressed and it is being adjusted, as my system keeps the DDS loop intact at 25 cycles for the vast majority 99.99% of the time even during adjustment. The very first version would drop the frequency badly during adjustment as the added cycles reduced the total DDS frequency (which I'm sure you found out with your version). But that was fixed before I wrote the web page so that when someone is listening to the frequency as it is being adjusted they can hear the correct frequency. I'm not even sure you were aware I had achieved that in my original version when you were throwing around the "clever" comments about the code I had done.

Feel free to create whatever changes and improvements you like Mike, and I will be genuinely interested to see what you come up with. But for me this project was a "spend an evening, and release a tested fully working reasonable functioning finished project with a beginner PIC" kind of deal, and there are lots of things that could have been made faster or better or more features etc but there was a finite limit to the amount of time I wanted (and want) to spend on it. :)
 

Thread Starter

THE_RB

Joined Feb 11, 2008
5,438
MMcLaren said:
... I wonder now if that may have been a mistake. If you can show me somewhere in this thread where I ridicule ...
Look Mike, I think I owe you a full explanation as you have a right to know how I view it. I thought it was great that you took an interest in my Christmas gift project. I thought it was great you wanted to help improve the project by making code for another chip to make it more accessible to more people. It was a compliment that you thought the project was cool enough to want to copy it. I didn't even expect that, I thought people would just use the thing as it was already finished and tested.

I didn't mind too much when your posts started to look to me a bit more like "one-upmanship" than genuine help, as if maybe your goal was to prove you could do it better (or maybe subconsciously prove I'm not so "clever" since you seem to have an issue with that?). A bit of friendly competition can be fun I guess, we have got along in the past even with our personality differences and normally I enjoy challenges.

But then when I didn't compliment you grandly enough, you threw in a snide (and uncalled for) personal comment;

MMcLaren said:
...
Only impressive? You won't share some of that "clever" adjective you lavish upon yourself on your project web page (lol)?
which I was quite prepared to gloss over in the interest of friendly teamwork and to keep this thread civil and get back to technical discussion.

What crossed the line for me was this second remark;

MMcLaren said:
...For the benefit of AAC members who don't know the inside joke. In the past over on the Electro-Tech forum I've accused Roman of elevating self-promotion to an art form. If you read through his web page he's always patting himself on the back and telling us how clever he is, and I admit, deservedly so. But, I still think it's a slightly annoying personality trait and so I tease him about it every once in awhile.
where you sound like you are educating everybody to the "fact" that I have a history of being some sort of clown who spends all his time "self promoting" how clever he thinks he is. I found that very insulting, even with your disclaimer.

My hobby web page exits for ONE reason Mike; for the benefit of others. I make no money from it, in fact it costs me hundreds of dollars in server fees. I have chosen not to put advertising on my site, at my own expense. I gain nothing from it! My professional clients don't know or care about my hobby PIC site, nor have I ever solicited for professional consulting on my site. My professional money is made elsewhere, and the real clever stuff I do is not given away on a hobby site that's for sure! My activity here on the forums is probably 90% me trying to help others where I can. If there is a "self promotion" I am guilty of then it's promoting my web site, as a service where people can get something for free.

I don't think you truly understand why I spend a good chunk of my time creating projects to give away to others, and this is not the first time you have been quick to make comments judging my personality as if I have done something wrong.

A joke at the expense of someone's feelings and reputation is not such a friendly joke at all, and there is a limit with personal remarks that if crossed requires me to speak up for myself. I'm not going to change my online personality because you don't like it, and I will keep creating hobby stuff for my web page and even poking a little fun at my own ego on my web page which I'm sure some people with a sense of humour (or people who really know me) must get. Having said all that, really none of this is that big a deal and it's not relevant to this technical project either so this personal discussion stuff is all done and over as far as I'm concerned.

You really are welcome in the thread Mike, as is any technical contribution that might be helpful to others. Your enthusiasm is great and this IS a fun project! Please let's keep it that way. So bring on any super-sine maker you can come up with! :)
 
Top