serial DAC - sine wave
ceresin
Posts: 3
Hi all,
I am a novice. I want to make sine wave with 12bits serial D/A converter. I would like to use the sine table in ROM, but I dont know how. I read that simples in this table are 16bits and I need 12bits for my converter.
Could you help me with:
1) How read sample from sine table in ROM
2) How make 12bits from 16bits sample and how send this sample to serial converter.
Thanks a lot for all the advice.
I am a novice. I want to make sine wave with 12bits serial D/A converter. I would like to use the sine table in ROM, but I dont know how. I read that simples in this table are 16bits and I need 12bits for my converter.
Could you help me with:
1) How read sample from sine table in ROM
2) How make 12bits from 16bits sample and how send this sample to serial converter.
Thanks a lot for all the advice.
Comments
Regarding sending the 12 bits to the DAC, that depends on the chip you're using. You have to provide a link to a datasheet if you want further suggestions. You might look in the Object Exchange for an existing DAC object for the device you're using or something similar.
There was an early Prop document called "Propeller Guts". I don't know where it's kept these days, but attached is a copy from my archive. There's a section on the use of the Log / Anti-log and Trig tables.
thank you for your response. I apologize for my ignorance, I am a novice.
I found the manual code for sine:
And this is code for DAC (I use MCP4822):
And I dont know, how to combine. How to modify the variable "sin" (16bits <-> 12bits) and stored in the variable "Value".
Start with the Propeller Education Kit tutorials. Remember that objects are a little like library routines. You refer to them in your program and call them from your program. You don't cut and paste the code into your program. In the case of objects from the Object Exchange, the documentation for the object is either contained in the comments of the object source code or in a demo program provided in the object's archive or in a separate document included in the archive (like for the floating point package).
It looks like the MCP4822 is the same as the MCP4922 except that the MCP4822 has an on-chip voltage reference. You should be able to use the same object from the Object Exchange.
Welcome to the forum. I think you will enjoy the Propeller, and I do second Mike's suggestions.
The method you posted above for the DAC is written in Spin language, whereas the snippet for producing the sine is in assembly language, pasm. There is a huge difference in speed of execution.
In the Spin method, each value you send to the DAC will take about 0.5 or 0.6 millisecond. That limits the frequency of your sine wave to something like 100Hz depending on how smooth you need the waveform to be. A 1 Hz sine wave would give about 200 level shifts over the course of one second and would look pretty good.
Each elementary instruction in Spin takes about 5 microseconds. In contrast, each elementary instruction in pasm takes around 50 nanoseconds, so right there you have a factor of 100 difference. If you want to generate high frequency sine waves, both the DAC routine and the sine routine will have to be written in pasm. It is not necessarily harder than Spin, but it is a different skill set, because you have to think closer to the heart of the machine. The most important thing is to understand the logical steps that go into your project.
Here is a spin method that reads the sine table. The input is a number 0 to 8191 that represents phase around a circle. The result is a number that could feed into your DAC, 12 bits, biased at 2048 center scale. You would need a main method that cycles through phase at your desired frequency, which would call on another method like the one below to find the sine, after which it would call on the method that sends the sine value to the DAC. Repeat around the cycle.
I wrote program in PASM. Sine is nice but the frequency is only 40 Hz and I need frequency about 100kHz. I mean it is neccessary to use more cogs, isn´t it? But I dont know how. Is there some material to learn how to use more cogs? Or could you give me some advice how to do it? Thank you.
One issue is that the phase "count3" advances by one at each iteration, and 2048 counts per each cycle and about 10 or 12 microseconds to run through all the pasm code for each sample, that comes out to about 40 Hz.
The serial DAC requires a lot of instructions for each update, and by a quick estimate that comes out to about 7+ microseconds right there.
One cure is to use DDS techniques, and advance the phase by a larger increment. For example, instead of +1, do +8, and then you would have 320 Hz instead of 40 Hz, but fewer samples per cycle.
But 100 kiloHz as a target requires a different approach.
Have you considered using the Propeller's own version of a DAC? That is uses the cog counter in the so-called duty mode. That combined with DDS techniques can reach audio frequencies. Here for example is sinewave3.spin, my own reaches about 1 microsecond per sample.
Another approach would be an external DDS chip instead of a DAC. Or you could use an external ladder network and lots of Prop pins and send the data out in parallel.
I think you will have a very limited gain structure with only 12 bits.....but maybe you only need a fixed ref. level?
the sample rate for a 100khz. sine is relatively high.....and don't forget that you need overhead to eliminate distortion at the filter points....otherwise your sine at 100khz will be full of non linear artifacts....
how clean of a function do you need to generate??