PDM library (Pulse Density Modulation)

Dependents:   mbed-shiny

Embed: (wiki syntax)

« Back to documentation index

SoftPdmOut Class Reference

SoftPdmOut Class Reference

Class to use software defined Pulse Density Modulation (PDM). More...

#include <SoftPdmOut.h>

Public Member Functions

 SoftPdmOut (PinName pdm, uint32_t PulseWidth=500, uint32_t Dmax=64, float StartLevel=0)
 Create a PDM object connected to a digital pin.
void start (void)
 Start the PDM.
void stop (bool idleState=0)
 Stop the PDM.
void PulseWidth (uint32_t level)
 Change the pulse width.
uint32_t getPulseWidth (void)
 Read the pulse width.
void Dmax (uint32_t level)
 Change the total number of states in the DAC output (DMAX).
uint32_t getDmax (void)
 Read the total number of states in the DAC output (DMAX).
void write (float level)
 Set the PDM level, specified as a percentage (float).
float read (void)
 Return the current PDM level as a percentage (float).
 operator float ()
 An operator shorthand for read()
SoftPdmOutoperator= (float value)
 An operator shorthand for write()

Detailed Description

Class to use software defined Pulse Density Modulation (PDM).

'pdm' pin can be any digital pin.

//Example
//-------
#include "mbed.h"
#include "SoftPdmOut.h"

SoftPdmOut pdm(LED1);

int main()
{
    float pdmSet = 0.0f;
    float pdmAdd = 0.01f;

    // Continuously cycle the output
    while(1)
    {
        pdm = pdmSet;
        wait_ms(10);
        if(pdmSet >= 1.0f)
            pdmAdd = -0.01f;
        if(pdmSet <= 0.0f)
            pdmAdd = 0.01f;
        pdmSet += pdmAdd;
    }
}

Definition at line 47 of file SoftPdmOut.h.


Constructor & Destructor Documentation

SoftPdmOut ( PinName  pdm,
uint32_t  PulseWidth = 500,
uint32_t  Dmax = 64,
float  StartLevel = 0 
)

Create a PDM object connected to a digital pin.

Parameters:
pdm: Digital pin.
PulseWidth: Optional - The desired pulse width in microseconds (default = 500us).
Dmax: Optional - This is the total number of states in the DAC output (default = 64).
StartLevel: Optional - The DAC percentage (0.0 to 1.0) to be preprogrammed upon initialization (default = 0).
Returns:
none

Definition at line 12 of file SoftPdmOut.cpp.


Member Function Documentation

void Dmax ( uint32_t  level )

Change the total number of states in the DAC output (DMAX).

Parameters:
level: The desired max. level.
Returns:
none.

Definition at line 59 of file SoftPdmOut.cpp.

uint32_t getDmax ( void   )

Read the total number of states in the DAC output (DMAX).

Parameters:
none.
Returns:
current DMAX value.

Definition at line 66 of file SoftPdmOut.cpp.

uint32_t getPulseWidth ( void   )

Read the pulse width.

Parameters:
none.
Returns:
current PulseWidth value

Definition at line 54 of file SoftPdmOut.cpp.

operator float (  )

An operator shorthand for read()

Definition at line 84 of file SoftPdmOut.cpp.

SoftPdmOut & operator= ( float  value )

An operator shorthand for write()

Definition at line 89 of file SoftPdmOut.cpp.

void PulseWidth ( uint32_t  level )

Change the pulse width.

Parameters:
level: The desired pulse width in microseconds.
Returns:
none

Definition at line 42 of file SoftPdmOut.cpp.

float read ( void   )

Return the current PDM level as a percentage (float).

Parameters:
none
Returns:
level

Definition at line 79 of file SoftPdmOut.cpp.

void start ( void   )

Start the PDM.

Parameters:
none
Returns:
none

Definition at line 21 of file SoftPdmOut.cpp.

void stop ( bool  idleState = 0 )

Stop the PDM.

Parameters:
idleState(optional, allows the user to define the idle state - default = 0)
Returns:
none

Definition at line 32 of file SoftPdmOut.cpp.

void write ( float  level )

Set the PDM level, specified as a percentage (float).

Parameters:
level
Returns:
none

Definition at line 71 of file SoftPdmOut.cpp.