libpropeller
Making PropellerGCC Easier
|
MCP3208 8 channel ADC Class. More...
#include <mcp3208.h>
Public Member Functions | |
void | Start (const int dataPin, const int clockPin, const int selectPin, const int mode=0xFF, const int dacAPin=-1, const int dacBPin=-1) |
Start the ADC driver in a new cog. More... | |
void | Stop (void) |
Stop the driver and free a cog. More... | |
int | In (const int Channel) |
Read a channel input. More... | |
int | Average (const int Channel, const int N) |
Sample a channel n times and average the results. More... | |
void | Out (const short aOutput, const short bOutput=-1) |
Output analog values (if enabled during Start) More... | |
MCP3208 8 channel ADC Class.
When the MCP3208 is configured for 3.3v operation each bit represents 0.00080566406v.
The MCP3208 requires three connections to the Propeller: clock, chip select, and data (tie together Dout and Din).
This object optionally provides two DACs as well. To enable these you need to have one or two Propeller I/O pins available. Each DAC I/O pin needs to have a low pass RC filter. I reccommend R = 1k and C = 0.1uF. With this configuration you should avoid changing the DAC more than once a millisecond (the cut off frequency is 1591Hz).
This driver does continuous sampling in the background.
This object is based on MCP3208.spin v1.0 written by Chip Gracey. Thanks!
Copyright (c) 2013 Kenneth Bedolla (libpr) opel ler@k enne thbed olla .com
|
inline |
Sample a channel n times and average the results.
This function is useful for reducing noisy readings.
Channel | The channel [0..7] to read |
N | The number of samples to average |
|
inline |
Read a channel input.
Channel | The channel [0..7] to read |
|
inline |
Output analog values (if enabled during Start)
The range is 0 (ground) to 65535 (3.3v) for the output.
aOutput | The output value for channel a |
bOutput | The output value for channel b |
|
inline |
Start the ADC driver in a new cog.
Be sure to give the driver sufficient time to start up.
dataPin | The data in and data out pins on the MCP3208 |
clockPin | The clock pin on the MCP3208 |
selectPin | The select pin on the MCP3208 |
mode | Channel enables in bits [0..7], differential mode enable in bits [8..15]. Most applications should set this to 0xFF |
dacAPin | If desired, the pin number for a DAC (see discussion above) |
dacBPin | If desired, the pin number for a DAC (see discussion above) |
|
inline |
Stop the driver and free a cog.