libpropeller
Making PropellerGCC Easier
 All Classes Files Functions Variables Enumerations Enumerator Macros Pages
Public Member Functions | List of all members
MCP3208 Class Reference

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...
 

Detailed Description

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.nosp@m.opel.nosp@m.ler@k.nosp@m.enne.nosp@m.thbed.nosp@m.olla.nosp@m..com)

Member Function Documentation

int MCP3208::Average ( const int  Channel,
const int  N 
)
inline

Sample a channel n times and average the results.

This function is useful for reducing noisy readings.

Parameters
ChannelThe channel [0..7] to read
NThe number of samples to average

Here is the call graph for this function:

int MCP3208::In ( const int  Channel)
inline

Read a channel input.

Parameters
ChannelThe channel [0..7] to read
Returns
The ADC reading in the range [0..4096]
void MCP3208::Out ( const short  aOutput,
const short  bOutput = -1 
)
inline

Output analog values (if enabled during Start)

The range is 0 (ground) to 65535 (3.3v) for the output.

Parameters
aOutputThe output value for channel a
bOutputThe output value for channel b
void MCP3208::Start ( const int  dataPin,
const int  clockPin,
const int  selectPin,
const int  mode = 0xFF,
const int  dacAPin = -1,
const int  dacBPin = -1 
)
inline

Start the ADC driver in a new cog.

Be sure to give the driver sufficient time to start up.

Parameters
dataPinThe data in and data out pins on the MCP3208
clockPinThe clock pin on the MCP3208
selectPinThe select pin on the MCP3208
modeChannel enables in bits [0..7], differential mode enable in bits [8..15]. Most applications should set this to 0xFF
dacAPinIf desired, the pin number for a DAC (see discussion above)
dacBPinIf desired, the pin number for a DAC (see discussion above)
void MCP3208::Stop ( void  )
inline

Stop the driver and free a cog.


The documentation for this class was generated from the following file: