DAC
Robert Humiston
Posts: 8
I have tried to dicpher how the DAC should work but cannot glean any understanding of how to use the cog counters.
I was hoping to use the propeller as a basic function genrate and Frequency counter. This serves two goals. One to learn more about frequency synthesis and how to use the propeller to do this and to create a fairly afforfdable bench tool.
I have seen dom axamples on the forum but they neither explain the use of the cog counters nor the DAC functionaliy. I small code examples would be nice, as i am trying to learn both the propeller and frequency synthesis.
Thank you in advance for support
I was hoping to use the propeller as a basic function genrate and Frequency counter. This serves two goals. One to learn more about frequency synthesis and how to use the propeller to do this and to create a fairly afforfdable bench tool.
I have seen dom axamples on the forum but they neither explain the use of the cog counters nor the DAC functionaliy. I small code examples would be nice, as i am trying to learn both the propeller and frequency synthesis.
Thank you in advance for support
Comments
The documentation for the Propeller Counters will be released shortly (it's complete, we are testing and verifying the posting system for Propeller Application Notes). It includes examples of a frequency counter, ADC, Sawtooth waveform generation (any waveform can be generated by setting the values according to the function), and other applications.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Paul Baker
Propeller Applications Engineer
Parallax, Inc.
Andre'
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Paul Baker
Propeller Applications Engineer
Parallax, Inc.
Post Edited (Paul Baker (Parallax)) : 11/17/2006 2:26:59 AM GMT
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Paul Baker
Propeller Applications Engineer
Parallax, Inc.
For Duty Cycle, the carry output of PHSA is the ouput to APIN. This is like a memoryless PHS[noparse][[/noparse]32], or what that bit would contain if it existed, and then was reset back to zero the next clock cycle. To use it, you simply set FRQA equal to the fractional amount you want or 3.3V x duty/2^32. This is a set it and forget it type operation, once you establish the duty cycle, the couter will continue to output the correct amount of pulses to generate the analog voltage without any program intervention nessesary.
Also Duty cycle provides twice as many levels of output than PWM can, and several orders of magnitude in practice, this is because to obtain the full precision possible for PWM the period must be ~54 seconds long, this is way too low of a fundamental frequency to be smoothed out by a single pole low pass filter and still have a rapid response to changes in ouput. Duty cycle takes the same total of high to low pulses as output by PWM but does a "shuffle the deck" way of outputting the pulses so high pulses are intermixed with low pulses. With PWM all the high pulses are stacked on one side of the period and all the low pulses are stacked on the other side of the period.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Paul Baker
Propeller Applications Engineer
Parallax, Inc.
Post Edited (Paul Baker (Parallax)) : 11/19/2006 12:44:32 AM GMT
1) how to get sine value and multipy to get duty realize have tow use offset 1.15V and flip values to get full 360 wave
2) In scalingduty.spin how does period in assembly work
Here is my code thus far:
{{ Demonstration of scaling Duty Cycle
10kΩ
APIN ─┳── Out
│
.1µF
Delta modulation has no fundamental freq but has quantization noise
}}
CON _clkmode = xtal1 + pll16x
_xinfreq = 5_000_000
VAR long parameter
long period
PUB SquareWave freqSynth bitDepth | x levelInc
parameter := 0
period := clkfreq / freqSynth
cognew(@entry, @parameter)
repeat
time2 := cnt
levelInc = $1_0000_0000 / bitDepth
repeat x from 0 to bitDepth -1
parameter := levelInc * x
waitcnt(time += period/bitdepth)
PUB triangleWave freqSynth bitDepth | x levelInc
parameter := 0
period := clkfreq / freqSynth
cognew(@entry, @parameter)
repeat
time2 := cnt
levelInc = $1_0000_0000 / bitDepth
repeat x from 0 to bitDepth -1
parameter := levelInc * x
waitcnt(time2 += period/2/bitdepth )
repeat x from bitDepth -1 to 0
parameter := levelInc * x
waitcnt(time2 += period/2/bitdepth )
PUB sineWave frequency | x
parameter = 0
cognew(@entry, @parameter)
repeat
time2 := cnt
repeat x from 0 to 90
parameter := $8000_0000 + $8000_000 * sine value x
waitcnt (time2 += period/360)
'' need to repeat for quadrants 2-4
DAT
org
entry mov dira, diraval
mov ctra, ctraval
mov time, cnt
add time, period
:loop rdlong value, par
waitcnt time, period
mov frqa, value
jmp #:loop
diraval long |< 1 + |< 0
ctraval long %00111 << 26 + 1<<9 + 0 'NCO/PWM APIN=0 BPIN=1
time res 1
value res 1[noparse][[/noparse]code]
once again thank you
The way you have written your code, period wont work correctly, you need to place it in your RES space in your assembly code. Also you need to set it's value before starting the cog for your SineWave.
Don't confuse period with your oscillating frequency, they are different. Period is the granularity in which the output value is updated, you can think of this as the sample rate of your generated waveform, or the time base along the X axis. It's parameter which sets the value generated, or the value along the Y-axis, this value is 3.3 x parameter/period.
The assembly code on page 423 shows how to obtain the sine of a value, you would need to scale this then add an offset to obtain the final value proivided to the parameter.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Paul Baker
Propeller Applications Engineer
Parallax, Inc.
You can get the sine value from the table in the HUB. There is no need to multiply until you need fine control of the amplitude of your sine wave. You can get a full amplitude sine wave (+/- 1.65 volts, 3.3 volts peak to peak), with a simple shift operation.
The command to get the sine from the Hub is of the form,
result := word[noparse][[/noparse]$E000 + y]
where y is a variable (11 bits) that holds the phase from 0 to 90 degrees. The sine table consists of 2k word addresses that go from $E000 to $F001, and that represents angles from 0 to 90 degrees as a sixteen bit number (result).
I'm not sure if you have seen this example, in the tutorials section, but it goes into detail about how to make a sine wave using the cog counters and the hub sine table in both spin and assembly:
http://forums.parallax.com/showthread.php?p=606978
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Tracy Allen
www.emesystems.com
Took a few miutes to make a cable and then prop was making waves.
It could make a nice little bench tool, add a LCD for frequency generation and counting.
Looking for a nice case to put it in with room for logic analyser cable connector.
Hmm graphical LCD? no just use VGA, make a nice storage cro? Fast A/D?
Every day I see more and more how useful this thing is.
Two questions. I realize that afreq = Fout / clockfreq * 2^32 but how does one realize this equation using the propeller. The Goal is to be able to input a frequency with the keyboard and generate it.
The second part of my application is to measure the frequency ouput can tsine waves be measured without some form wave-shaping.
Thanks I really appreciate your support.
The frqa value can be computed using the following routines in spin or asm. Enter with
a=Fout, your desired output frequency
b=clkfreq, your Prop clock frequency
bits=32.
The result f is the required value of frqa.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Tracy Allen
www.emesystems.com
Post Edited (Tracy Allen) : 11/30/2006 5:41:06 AM GMT
Now to return the favor.
Here is a complete and working App
This app uses Keyboard TV and jumper from pin·0 to 5
Post Edited (Robert Humiston) : 12/6/2006 4:24:30 PM GMT