PropWare  3.0.0.229
C++ objects and CMake build system for Parallax Propeller
Macros | Functions | Variables
dac.c File Reference

dac function source, see simpletools.h for documentation. More...

#include "simpletools.h"
+ Include dependency graph for dac.c:

Go to the source code of this file.

Macros

#define DUTY_SE   (0b110 << 26)
 

Functions

void dac_ctr_cog (void *par)
 
void dac_ctr_res (int bits)
 Set D/A voltage resolution. More...
 
void dac_ctr (int pin, int channel, int dacVal)
 Set D/A voltage. More...
 
void dac_ctr_stop (void)
 Stop the cog that's transmitting the DAC signal(s).
More...
 

Variables

static unsigned int stack [44+16]
 
static int dacCtrBits
 
static unsigned int cog
 
static volatile int ctra
 
static volatile int ctrb
 
static volatile int frqa
 
static volatile int frqb
 

Detailed Description

dac function source, see simpletools.h for documentation.

Author
Andy Lindsay
Version
0.86

@detail Please submit bug reports, suggestions, and improvements to this code to edito.nosp@m.r@pa.nosp@m.ralla.nosp@m.x.co.nosp@m.m.

Definition in file dac.c.

Function Documentation

◆ dac_ctr()

void dac_ctr ( int  pin,
int  channel,
int  dacVal 
)

Set D/A voltage.

Launches process into another cog for up to two channels of D/A conversion on any I/O pin. Other libraries may be available that provide D/A for more channels. Check SimpleIDE/Learn/Simple Libraries/Convert for options. For more options, check obex.parallax.com.

This library uses another cog's counter modules (2 per cog) to perform duty modulation, which is useful for D/A conversion. The digital signal it generates will affect LED brightness. The signal can be passed through a low pass RC filter for digital to analog voltage conversion. Add an op amp buffer if it needs to drive a load.

Default resolution is 8 bits for output voltages ranging from 0 V to (255/256) of 3.3 V.

General equation is dacVal * (3.3 V/2^bits)

Default is 8 bits, which results in dacVal * (3.3 V/ 256), so dacVal specifies the number of 256ths of 3.3 V. You can change the resolution with the dac_ctr_res function.

Parameters
pinI/O pin number.
channelUse 0 or 1 to select the cog's CTRA or CTRB counter modules, which are used for D/A conversion.
dacValNumber of 256ths of 3.3 V by default. Use a value from 0 (0 V) to 255 .

Definition at line 36 of file dac.c.

◆ dac_ctr_res()

void dac_ctr_res ( int  bits)

Set D/A voltage resolution.

Default resolution is 8-bits for output voltages ranging from 0 V to (255/256) of 3.3 V.

General equation is dacVal * (3.3 V/2^bits)

Default is 8 bits, which results in dacVal * (3.3 V/ 256), so dacVal specifies the number of 256ths of 3.3 V.

Parameters
bitsThe D/A converter's resolution in bits.

Definition at line 31 of file dac.c.

◆ dac_ctr_stop()

void dac_ctr_stop ( void  )

Stop the cog that's transmitting the DAC signal(s).

Stops any signals, lets go of any I/O pins, and reclaims the cog for other uses.

Definition at line 96 of file dac.c.