dacctr library
v0.85
Performs D/A conversion (sets voltages) with a cog's counter modules
|
This file provides convenience functions for digital to analog conversion using using counter modules (each cog has two).
Currently supports LMM and CMM memory models.
More...
#include "simpletools.h"
Go to the source code of this file.
Data Structures | |
struct | DacControl |
struct | DacAddr |
struct | DacCogMemory |
Macros | |
#define | DUTY_SE (6 << 26) |
#define | NEW_COG 2 |
Typedefs | |
typedef struct DacControl | dac |
typedef struct DacAddr | daca |
typedef struct DacCogMemory | dacmem |
Functions | |
dac | dac_setup (int pin, int channel, int bits) |
Configure an I/O pin to set a voltage with digital to analog (D/A) conversion. | |
void | dac_set (dac *da, int value) |
Set the D/A converter's output. | |
void | dac_close (dac *da) |
Clear a D/A converter that's running in the same cog and reclaim the I/O pin and counter module for other uses. | |
int | dac_start (dacmem mem, int sampleRate, dac *da0, dac *da1) |
Start D/A converter in new cog that sets voltages on either one or two pins. | |
int | dac_stop (int cogid) |
Stops a dac cog and frees up a cog and all its resources for other uses. |
This file provides convenience functions for digital to analog conversion using using counter modules (each cog has two).
Currently supports LMM and CMM memory models.
The current cog's counters can be used for D/A conversion, or one or more new cogs can be launched, each with two D/A channels. The output of this type of D/A converter can go straight to an LED circuit for variable brightness, or to a filter and into an op amp to drive other circuits at certain voltages. See Propeller Activity Board schematic for an example. P26 and P27 are connected to a filter, op amp, and also to LEDs.
Example in same cog:
Example in another cog:
void dac_close | ( | dac * | da | ) |
Clear a D/A converter that's running in the same cog and reclaim the I/O pin and counter module for other uses.
dac | Structure corresponding to the I/O pin that's sending the dac signal you want to close. |
void dac_set | ( | dac * | da, |
int | value | ||
) |
Set the D/A converter's output.
After a call to dac_setup, you can use the dac structure it returns to set the D/A converter's voltage. Again, see examples at the top of this file.
da | The pointer to the dac structure that dac_setup function returned. |
value | The output value for the D/A converter. (Like the number of 256ths of 3.3 V if you set up an 8-bit D/A converter with dac_setup. |
dac dac_setup | ( | int | pin, |
int | channel, | ||
int | bits | ||
) |
Configure an I/O pin to set a voltage with digital to analog (D/A) conversion.
Sets up a dac structure for you. You can then pass the address of this dac structure to other functions (like dac_set and/or dac_start) do things like set voltages or launch other cogs to perform D/A conversion. The technique this library uses is called duty modulation, and each D/A channel uses one of a cog's two counter modules. If you need to launch more than one D/A channel, you can use the dac structure this function returns in a call to dac_start to launch the D/A process into another cog.
pin | Number of the I/O pin to perform D/A conversion. |
channel | Use 0 for the cog's CTRA or 1 for the cog's CTRB counter module. You can also use NEW_COG if you are going to use dac_start. |
bits | The resolution of your D/A converter in bits. If you set it to 8, you will be able to set voltages in terms of 256ths of 3.3 V, from 0 to 255. If you set it to 10, you will be able to set voltages in terms of the number of 1024ths of 3.3 V. More generally, the fraction of 3.3 V is 2^bits. |
Start D/A converter in new cog that sets voltages on either one or two pins.
Launches up to two D/A converters in a new cog. Example included near the top of this file.
mem | A dacmem structure that you initialize with dacmem myStructureName; |
sampleRate | The sample rate you want the dac to update values at. Top speed is 46 kHz, 44.1 kHz is recommended. |
da0 | Address of the dac structure the cog's channel 0 will run. If you do not want to use this channel, pass NULL. |
da1 | Address of the dac structure the cog's channel 1 will run. If you do not want to use this channel, pass NULL. |
int dac_stop | ( | int | cogid | ) |
Stops a dac cog and frees up a cog and all its resources for other uses.
cogid | The dac cog's ID that dac_start returned. |