| 
    Propeller Activity Board Voltage Library
    v0.50
    
   Set and measure voltages with Propeller Activity Board D/A and A/D sockets 
   | 
 
Functions for setting voltages with D/A0, D/A1 outputs and measuring voltages with A/D0...A/D3 inputs. More...
#include "simpletools.h"Go to the source code of this file.
Macros | |
| #define | _abvolts_EE_start_ 63400 | 
| abvolts EEPROM calibration data start address.  | |
| #define | _abvolts_EE_end_ 63400 + 16 | 
| abvolts EEPROM calibration data end address.  | |
Functions | |
| void | da_init (int pinDA0, int pinDA1) | 
| Set output pins for D/A0 and D/A1.   | |
| void | ad_init (int csPin, int sclPin, int doPin, int diPin) | 
| Initialize Activity Board A/D converter.   | |
| void | da_volts (int channel, float daVal) | 
| Set D/A voltage (0 to ~3.3 V) on a given channel (0 or 1 for D/A0 or D/A1). Actual voltage will be the closest match of 256ths of 3.3 V.   | |
| float | ad_volts (int channel) | 
| Get a voltmeter style floating point voltage measurement from one of the A/D converter's input channels.   | |
| void | da_out (int channel, int daVal) | 
| Set D/A output.   | |
| int | ad_in (int channel) | 
| Get input value that corresponds to voltage measurement on one of the A/D converter's input channels. This number indicates voltage in terms of 4096ths of 5 V.   | |
| void | da_res (int bits) | 
| Set D/A voltage resolution.   | |
| void | da_setupScale (void) | 
| Set up scale to adjust D/A0 and D/A1. Connect DA/0 to AD/0 and DA/1 to AD/1 before running. Writes scalars to EEPROM memory. These scalars can be retrieved with da_getScale();.   | |
| void | da_useScale (void) | 
| Load scale that adjusts D/A0 and D/A1. If you have not called da_setScale some time in the past, this will not have any affect.   | |
| void | da_stop (void) | 
| Stop the cog that's transmitting the D/A signal(s).   | |
Functions for setting voltages with D/A0, D/A1 outputs and measuring voltages with A/D0...A/D3 inputs.
| int ad_in | ( | int | channel | ) | 
Get input value that corresponds to voltage measurement on one of the A/D converter's input channels. This number indicates voltage in terms of 4096ths of 5 V.
| channel | The A/D converter's input channel, either channel 0, 1, 2, or 3. Marked A/D 0, 1, 2 or 3 on the Propeller Activity Board. | 
| void ad_init | ( | int | csPin, | 
| int | sclPin, | ||
| int | doPin, | ||
| int | diPin | ||
| ) | 
Initialize Activity Board A/D converter.
Call this function once before calling ad_in or ad_volts.
Propeller Activity Board Example:
 
| csPin | Propeller I/O pin connected to the A/D converter's chip select pin.  The Propeller chip uses that pin to enable communication with the A/D converter chip. This connection is labeled /CS-P21 on the Propeller Activity Board. In that case Propeller I/O pin P21 is connected to the A/D converter's chip select pin, so you would use 21 for this parameter.  | 
| sclPin | Propeller I/O pin connected to the A/D converter's serial clock pin.  The Propeller chip sends a series of pulses to the A/D converter's SCL pin to drive the conversion and signal to send/receive binary conversion values. This connection is labeled SCL-P20 on the Propeller Activity Board. In that case Propeller I/O pin P20 is connected to the A/D converter's serial clock pin, so you would use 20 for this parameter.  | 
| doPin | Propeller I/O pin connected to the A/D converter's data out pin.  The A/D converter sends binary values to the controller with this pin. This connection is labeled DO-P19 on the Propeller Activity Board. In that case Propeller I/O pin P19 is connected to the A/D converter's data out pin, so you would use 19 for this parameter.  | 
| diPin | Propeller I/O pin connected to the A/D converter's data in pin.  The Propeller chip sends a channel selection to the A/D converter, which receives it with this pin. This connection is labeled DI-P18 on the Propeller Activity Board. In that case Propeller I/O pin P18 is connected to the A/D converter's chip data in, so you would use 18 for this parameter.  | 
| float ad_volts | ( | int | channel | ) | 
Get a voltmeter style floating point voltage measurement from one of the A/D converter's input channels.
| channel | The A/D converter's input channel, either channel 0, 1, 2, or 3. Marked A/D 0, 1, 2 or 3 on the Propeller Activity Board. | 
| void da_init | ( | int | pinDA0, | 
| int | pinDA1 | ||
| ) | 
Set output pins for D/A0 and D/A1.
If this function is not called, the default is D/A0 = 26 and D/A1 = 27, which go the D/A0 and D/A1 sockets on the Activity Board. These sockets can supply current loads while maintaining the output voltage. Other I/O pins can be used, for LED brightness and other circuits that do not draw current loads.
| pinDA0 | D/A0 pin. | 
| pinDA1 | D/A1 pin. | 
| void da_out | ( | int | channel, | 
| int | daVal | ||
| ) | 
Set D/A output.
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. The D/A0 and D/A1 circuits use this type of circuit.
Default resolution is 8 bits for output voltages ranging from 0 V to (255/256) of 3.3 V.
General equation is daVal * (3.3 V/2^bits)
Default is 8 bits, which results in daVal * (3.3 V/ 256), so daVal specifies the number of 256ths of 3.3 V. You can change the resolution with the da_res function.
| channel | Use 0 or 1 to select the cog's CTRA or CTRB counter modules, which are used for D/A conversion. | 
| daVal | Number of 256ths of 3.3 V by default. Use a value from 0 (0 V) to 255 . | 
| void da_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 daVal * (3.3 V/2^bits)
Default is 8 bits, which results in daVal * (3.3 V/ 256), so daVal specifies the number of 256ths of 3.3 V.
| bits | The D/A converter's resolution in bits. | 
| void da_setupScale | ( | void | ) | 
Set up scale to adjust D/A0 and D/A1. Connect DA/0 to AD/0 and DA/1 to AD/1 before running. Writes scalars to EEPROM memory. These scalars can be retrieved with da_getScale();.
Measures high signal to D/A0 and D/A1 and use any difference in 3.3 V signal to set output scalars that are stored in EEPROM.
| void da_stop | ( | void | ) | 
Stop the cog that's transmitting the D/A signal(s).
Stops any signals, lets go of any I/O pins, and reclaims the cog for other uses.
| void da_useScale | ( | void | ) | 
Load scale that adjusts D/A0 and D/A1. If you have not called da_setScale some time in the past, this will not have any affect.
Retrievels scalars for adjusting D/A outputs from EEPROM and uses them for subsiquent D/A conversions.
| void da_volts | ( | int | channel, | 
| float | daVal | ||
| ) | 
Set D/A voltage (0 to ~3.3 V) on a given channel (0 or 1 for D/A0 or D/A1). Actual voltage will be the closest match of 256ths of 3.3 V.
| channel | Use for D/A0 or 1 for D/A1. .* | 
| daVal | floating point number of volts. | 
 1.8.1.2