PDA

View Full Version : Any DAC examples for the propeller using SPIN?



automaton
11-12-2006, 05:20 AM
I just recently acquired a propeller chip for a project that I need to do complete (I chose it for the multiple cogs so I can do something else in the chip while I have a DAC running on another cog). Anywyas, I have to create a DAC and I am trying write in the SPIN language. I see lots of assembly examples for this, but seeing as how I am just learning the ins and outs of the chip...

I was wondering if there are any SPIN code examples for this or if someone can point me in the direction of an object to use?

Thanks.

T Chap
11-12-2006, 06:10 AM
look in the propeller tool examples folder the ad8803 demo may help

M. K. Borri
11-12-2006, 06:43 AM
A cheap way to do this (I used to do that with a parallel port) is to get powers-of-two resistors (8 ohm, 16 ohm... to 2k ohm) and connect them to, say, pin 0 to pin 7, then connect them all together and amplify that a bit, mostly so the prop sees high impedance (the cheap radio shack audio amplifier will do the trick), you can drive a headphone with that. Just write bytes to outa and there you go, 8 bit audio!

automaton
11-12-2006, 07:11 AM
MK,

I am aware of the the old 8-bit DAC parallel port hack... but that port is being used for something else and I need more functionality than a parallel port can provide. I need to accept analog input on several of the pins and do some low frequency digital out on several of the pins.

So I can't use too many of the pins. I was thinking of using the a single resitor, and a capacitor in the following fashion....


PIN 0 ---/\/\/\/\--------------->Analog output between 0 and 3.3 V

Where there is a capacitor branching to the ground between the resistor and the analog terminal (tried to show it but forum code here doesn't display spaces at the front of a line)

But I was seeing if there were SPIN code examples (not the assembly version) showing this...

Post Edited (automaton) : 11/12/2006 12:18:04 AM GMT

Paul Baker
11-12-2006, 07:39 AM
The reason you see the examples for sigma-delta ADC written in assembly is because the speed and deterministic nature of assembler is required to make it work. Fortunately you dont need to understand the assembly code to use it, just how to interface with it in your Spin code.

▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Paul Baker (mailto:pbaker@parallax.com)
Propeller Applications Engineer
[/url][url=http://www.parallax.com] (http://www.parallax.com)
Parallax, Inc. (http://www.parallax.com)

M. K. Borri
11-12-2006, 11:25 AM
A little basic reminder in case someone finds this thread later: in general, but especially if you go the R+C route, make sure you connect the output you generate that way to a hi-Z buffer (such as an op amp hooked up as a follower hyperphysics.phy-astr.gsu.edu/Hbase/electronic/opampvar2.html (http://hyperphysics.phy-astr.gsu.edu/Hbase/electronic/opampvar2.html) ), specifically, to something whose impedance never changes. This way you know that the rest of your circuit is always getting the right output from it.

Paul Baker
11-12-2006, 01:13 PM
Hmmm, I just noticed I misread your request. Yes DACs can be made from Spin code, here's your request:


PUB ADC_start(pin) dira := |< pin
frqa := 0
ctra := %00111 << 26 + pin

PUB ADC(value)
frqa := value

ADC_start initializes the ADC to output on pin and sets the inital value to 0V, ADC changes the output voltage to 3.3x(value/2^32).
·
10kOhms and .1uF are suitable values for the resistor and capacitor, though other values will work.·You must be careful about what kind of load you place on the circuit, if it's·low resistance or high capacitance, it will affect the voltage output.·For these types of loads you should run the voltage through an op-amp configured as a voltage follower as MK Borri has shown in the link he provided.

▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Paul Baker (mailto:pbaker@parallax.com)
Propeller Applications Engineer
[/url][url=http://www.parallax.com] (http://www.parallax.com)
Parallax, Inc. (http://www.parallax.com)

Post Edited (Paul Baker (Parallax)) : 11/12/2006 6:32:53 AM GMT

automaton
11-13-2006, 11:11 PM
I started interpretting the assmebler code and almost had the same thing you posted above... except had the shifting different.. so I'll go back and fix it. :)

Thanks