The analog functionality currently supported by the PiSoC API
Class: | Provides functionality for use of the general purpose analog input pins exposed on the PiSoC |
---|---|
Example: | Define an AnalogPin object in the following way: >>> My_analog_pin = AnalogPin(pin)
|
Method: | __init__ |
---|---|
Description: | Constructs and initializes an AnalogPin object for general purpose analog input |
Parameters: | pin (int) – The analog pin number - This directly corresponds to the pins connected to your sequenced SAR ADC, where 0 is the top pin
|
Returns: | None |
Method: | Read |
---|---|
Description: | Reads the calculated digital value after analog to digital conversion |
Returns: | Digital value after an A/D conversion
|
Return type: | int |
Method: | ReadVolts |
---|---|
Description: | Reads the specified analog pin and converts that digital reading to a voltage in Volts, or converts a given count value to Volts if one is provided |
Parameters: |
|
Returns: | A floating point number representative of an analog voltage taken with respect to PiSoC ground. |
Method: | SetOffset |
---|---|
Description: | Sets an offset on the ADC which is used for the voltage conversion. It will subtract the given offset before making the conversion |
Parameters: | counts (int) – Digital value which will be subtracted from any digital result before its conversion to a voltage takes place |
Returns: | None |
Method: | SetResolution |
---|---|
Description: | This function sets the resolution of ALL AnalogPin objects. The resolution is defaulted to 12, so this method is only needed if this needs to be changed |
Parameters: | resolution (int) – An integer value, in bits, that represents the new resolution of the SAR ADC. Valid arguments are 8, 10, and 12 |
Returns: | None |
Class: | Provides functionality for use of CapSense buttons on the PiSoC |
---|---|
Example: | Define a CapSense object in the following way: >>> button = CapSense(0)
|
Method: | __init__ |
---|---|
Description: | Initializes a Capsense object for use as a touch sensor |
Parameters: |
|
Returns: | None |
Note
threshold is only needed for is_touched() (the suggested reading method). Read() is only valid when SmartSense is enabled in firmware, which by default it is not.
Method: | Read |
---|---|
Description: | Determines the state of the capsense button, as determined by PSoC SmartSensing. This will need to be calibrated in PSoC Creator for optimal results. Use is_touched() for more general application |
Returns: | A boolean (True or False) value when the output is determined to be touched or not touched, respectively. |
Warning
This functionality has been deprecated since version 1.2 because the implementation was slow. It will only work if the firmware will support it. It has since been replaced by is_touched() but it is maintained as a seperate function for legacy purposes.
Method: | ReadRaw |
---|---|
Description: | Gives an 8-bit raw value from the capsense raw data array, which represents capacitance detection and is thus correlated with touch data. Use this to calibrate touch buttons by deciding an approriate threshold as described in __init__() |
Returns: | The raw value on the capsense button, which can be used to characterize the nature of a touch event |
Method: | Sleep |
---|---|
Description: | Prepares the component for the device entering a low-power mode. Disables Active mode power template bits of the sub components used within CapSense, saves nonretention registers, and resets all sensors to an inactive state. |
Returns: | None |
Warning
This will affect functionality of all CapSense sensors, use it only if this is intended.
Method: | Start |
---|---|
Description: | Initializes registers and enables active mode power template bits of the subcomponents used within CapSense. Also establishes a CapSense baseline, which is used as a comparison value in is_touched() |
Returns: | None |
Note
If the sensor is touched when this method is called, the sensor will be calibrated to a touched value. This may or may not be desireable based on application.
Method: | Stop |
---|---|
Description: | Disables component interrupts, and calls CapSense_ClearSensors() to reset all sensors to an inactive state |
Returns: | None |
Warning
This will affect functionality of all CapSense sensors, use it only if this is intended.
Method: | Wakeup |
---|---|
Description: | Restores CapSense configuration and nonretention register values after the device wake from a low power mode sleep mode |
Returns: | None |
Warning
This will affect functionality of all CapSense sensors, use it only if this is intended.
Method: | get_register |
---|---|
Description: | Calculates a touched event for all enabled CapSense sensors, and returns the result as a single 8-bit hexadecimal value containing the state of each sensor. |
Returns: | 8-bit hexadceimal value where the binary representation contains the state information for each pin. The n-th bit of this value will be 1 if pin n is touched, or 0 if pin n is not touched. Bit-0 is the LSB of the returned result. |
Method: | is_running |
---|---|
Description: | Checks to see if the CapSense component and all subcomponents are currently operational |
Returns: | A boolean variable which evaluates to True if CapSense is active, or False if it is not |
Method: | is_touched |
---|---|
Description: | Uses the calibrated baseline and provided threshold value to determine if the requested CapSense button is being touched. This is the suggested method for touch detection. |
Parameters: | bitmap (int) – An optional input, which when provided will be used to decide if the sensor has been touched instead of asking the PiSoC. It is a hexadecimal value which represents the state of all capsense sensors, as returned by get_register(). Providing a bitmap to this function simply abstracts the bit manipulation required to decode that result. |
Returns: | A boolean (True or False) value when the output is determined to be touched or not touched, respectively |
Use these for fine control of your analog input. For general analog input needs, analogPin is almost always sufficient
Class: | The ADC class provides functionality for using the Delta Sigma ADC and two Succesive Approximation ADC’s on the PiSoC. |
---|---|
Example: | Define ADC objects in the following way: >>> My_DELSIG = ADC('DELSIG')
>>> My_SAR = ADC('SAR0')
>>> My_other_SAR = ADC('SAR1')
|
Method: | __init__ |
---|---|
Description: | Constructs and initializes an ADC object for use of a SAR or DELSIG ADC |
Parameters: | c_type (str) – Specifies the type of ADC to be used. Valid arguments are:
|
Returns: | None |
Method: | CountsTo_Volts |
---|---|
Description: | Converts the ADC output to a Voltage, taking into account any set gains or offsets |
Parameters: | counts (int) – Digital value to be converted to it’s analog equivalent (voltage in Volts) |
Returns: | Floating point value representative of converted voltage |
Method: | GetResult |
---|---|
Description: | Gets the result of a conversion which has been completed. StartConvert() must be called prior to this function, and StopConvert() must be called after |
Returns: | Digital value which represents the result of the most recent AD conversion |
Method: | IsEndConversion |
---|---|
Description: | Checks to see if the ADC is done converting |
Returns: | Boolean value (True/False) that will evaluate True if the most recent conversion is complete, otherwise False. |
Method: | Read |
---|---|
Description: | Simplifies the reading process by starting conversion, waiting for conversion to complete, stopping conversion, and returing the result, when called. |
Returns: | Digital value which represents the result of the most recent AD conversion |
Method: | SetBufferGain |
---|---|
Description: | Sets the input buffer gain |
Parameters: | gain (int) – The number by which the ADC output will be multiplied after conversion . Valid arguments are 1, 2, 4, or 8 |
Returns: | None |
Note
Increasing the gain will lower the buffer bandwidth. This method is only available for the Delta-Sigma ADC; use with a SAR ADC will raise a ValueError
Method: | SetGain |
---|---|
Description: | Sets the ADC gain in counts per volt, which will be applied before voltage conversion |
Parameters: | gain (int) – Output gain in counts per volt to be applied before conversion. |
Returns: | None |
Warning
gain is set by default by the reference and input range settings. It should only be used to further calibrate the ADC with a known input or if an external reference is used
Method: | SetOffset |
---|---|
Description: | Sets an offset on the ADC which is used for the voltage conversion. It will subtract the given offset before making the conversion |
Parameters: | offset (int) – Digital value which will be subtracted from any digital result before its conversion to a voltage takes place |
Returns: | None |
Method: | SetResolution |
---|---|
Description: | This function sets the resolution of the SAR ADCs only. This method is unavailable for the DELSIG ADC. The resolution is defaulted to 12, so this method is only needed if this needs to be changed |
Parameters: | resolution (int) – An integer value, in bits, that represents the new resolution of the SAR ADC. Valid arguments are 8, 10, or 12 only |
Returns: | None |
Note
The ADC resolution cannot be changed during a conversion cycle. The recommended bestpractice is to stop conversions with Stop() before changing the resolution, and then restarting with Start() If you call SetResolution() during a conversion, the resolution will not change until the current conversion is complete, and data will not be available in the new resolution for another 6+resolution clock cycles
Method: | Sleep |
---|---|
Description: | Checks to see if the component is enabled, then it stops the ADC and saves the current configuration for later use |
Returns: | None |
Method: | Start |
---|---|
Description: | Sets the initVar variable on the PiSoC, calls the ADC_Init() function, and then calls the ADC_Enable() function. This function configures and powers up the ADC, but does not start conversions |
Returns: | None |
Method: | StartConvert |
---|---|
Description: | Forces the ADC to initialize a conversion. This is handled internally for the Delsig ADC, using the Read() function, but it is kept seperate for the SAR. However, It can also be used for the Delsig |
Returns: | None |
Method: | Stop |
---|---|
Description: | Disables and powers down the ADC |
Returns: | None |
Method: | StopConvert |
---|---|
Description: | Forces the ADC to end conversion. This is handled internally for the Delsig ADC, using the Read() function, but it is kept seperate for the SAR. However, It can also be used for the Delsig |
Returns: | None |
Method: | Wakeup |
---|---|
Description: | Restores and enables the most recently saved configuration of the ADC |
Returns: | None |
Method: | is_running |
---|---|
Description: | Checks to see if the ADC component and all subcomponents are currently operational |
Returns: | A boolean variable which evaluates to True if the ADC is active, or False if it is not |
Use these to generate analog voltages, currents, or waveforms.
Class: | The VDAC class provides functionality for using the VDAC’s available on the PiSoC. |
---|---|
Example: | Define VDAC objects in the following way: >>> My_VDAC = VDAC(0)
>>> My_other_VDAC = VDAC(1)
|
Method: | __init__ |
Description: | Constructs and initializes a VDAC object |
Parameters: | channel – Determines which VDAC is to be utilized. 0 for the first VDAC, output is on P0[1]. Second VDAC not available by default. |
Returns: | None |
Method: | SetRange | ||||
---|---|---|---|---|---|
Description: | Sets the full scale range for the VDAC | ||||
Parameters: | mode (int) – Choices are 0 or 1
|
||||
Returns: | None |
Method: | SetSpeed |
---|---|
Description: | Sets the DAC speed, and consequently the power level |
Parameters: | speed (str) – HIGH or LOW for high speed or low speed, respectively |
Returns: | None |
Method: | SetValue |
---|---|
Description: | Sets a digital value to be converted into an analog voltage and output by the VDAC |
Parameters: | value (int) – Value between 0 and 255
|
Returns: | None |
Method: | SetVoltage |
---|---|
Description: | Sets a voltage in Volts to be output on the specified VDAC |
Parameters: | volts (float) – A number between 0 and the full scale range, as selected by SetRange(). This will be converted to an analog voltage and output. |
Returns: | None |
Method: | Sleep |
---|---|
Description: | Checks to see if the component is enabled, then it stops the VDAC and saves the current configuration for later use |
Returns: | None |
Method: | Start |
---|---|
Description: | Enables and powers up the VDAC |
Returns: | None |
Method: | Stop |
---|---|
Description: | Powers down VDAC to lowest power state and disables output |
Returns: | None |
Method: | Wakeup |
---|---|
Description: | Restores and enables the most recently saved configuration of the VDAC |
Returns: | None |
Method: | is_running |
---|---|
Description: | Checks to see if the DAC component and all subcomponents are currently operational |
Returns: | A boolean variable which evaluates to True if the DAC is active, or False if it is not |
Class: | The IDAC class provides functionality for using the IDAC’s available on the PiSoC. |
---|---|
Example: | Define IDAC objects in the following way: >>> My_IDAC = IDAC(0)
>>> My_other_IDAC = IDAC(1)
|
Method: | __init__ |
---|---|
Description: | Constructs and initializes an IDAC object |
Parameters: | channel (int) – Determines which IDAC is to be utilized. V2.0 only exposes channel 0 by default - output on P0[7] |
Returns: | None |
Method: | SetCurrent |
---|---|
Description: | Sets a current in milliamps to be output on the specified IDAC |
Parameters: | m_amps (float) – A number between 0 and the full scale range (in milliamps), as selected by SetRange(). This will be converted to an analog current and output from the IDAC. |
Returns: | None |
Method: | SetPolarity |
---|---|
Description: | Sets the DAC output polarity |
Parameters: | polarity (str) – String argument which should be SOURCE or SINK |
Returns: | None |
Method: | SetRange | ||||||
---|---|---|---|---|---|---|---|
Description: | Sets the full scale range for the IDAC | ||||||
Parameters: | mode (int) – Choices are 0, 1, and 2
|
||||||
Returns: | None |
Method: | SetSpeed |
---|---|
Description: | Sets the DAC speed, and consequently the power level |
Parameters: | speed (str) – HIGH or LOW for high speed or low speed, respectively |
Returns: | None |
Method: | SetValue |
---|---|
Description: | Sets a digital value to be converted into an analog current and output by the IDAC |
Parameters: | value (int) – Value between 0 and 255
|
Returns: | None |
Method: | Sleep |
---|---|
Description: | Checks to see if the component is enabled, then it stops the DAC and saves the current configuration for later use |
Returns: | None |
Method: | Start |
---|---|
Description: | Sets the initVar variable on the PiSoC, calls the IDAC8_Init() function and then calls the IDAC8_Enable() function. Enables and powers up the IDAC |
Returns: | None |
Method: | Stop |
---|---|
Description: | Powers down IDAC to lowest power state and disables output |
Returns: | None |
Method: | Wakeup |
---|---|
Description: | Restores and enables the most recently saved configuration of the DAC |
Returns: | None |
Method: | is_running |
---|---|
Description: | Checks to see if the DAC component and all subcomponents are currently operational |
Returns: | A boolean variable which evaluates to True if the DAC is active, or False if it is not |
Class: | The WaveDAC class provides functionality for using the WaveDAC available on the PiSoC. |
---|---|
Example: | Define WaveDAC objects in the following way: >>> My_Wave = WaveDAC()
|
Method: | __init__ |
Description: | Constructs and initializes an WaveDAC object |
Returns: | None |
Method: | Provides functionality for generating a specific waveform |
---|---|
Description: | Provides functionality for generating a specific waveform |
Parameters: |
|
Returns: | None |
Method: | GetFrequency |
---|---|
Description: | Calculates the actual wave frequency based on the most recently confirmed clock divider value |
Returns: | (float) The actual frequency of the wave, not a requested frequency |
Method: | SetFrequency |
---|---|
Description: | Sets an approximate frequency by using an appropriate clock divider so that the resulting wave is as close to the desired frequency as possible |
Parameters: | frequency (float) – A frequency in Hz that will be representative of the output wave rate (Valid range is between 0.46 and 2500) |
Returns: | None |
Method: | SetSpeed |
---|---|
Description: | Dets the DAC speed to one of the defined settings |
Parameters: | speed (str) – HIGH or LOW for high speed or low speed, respectively |
Returns: | None |
Method: | SetValue |
---|---|
Description: | Sets a digital value to be converted into a voltage and output by the WaveDAC. |
Parameters: | val (int) – Value between 0 and 255 |
Returns: | None |
Method: | Sleep |
---|---|
Description: | Checks to see if the component is enabled, then it stops the DAC and saves the current configuration for later use |
Returns: | None |
Method: | Start |
---|---|
Description: | Performs all of the required initialization for the component and enables power to the block |
Returns: | None |
Method: | StartClock |
---|---|
Description: | Restarts the WaveDAC clock after it has been stopped |
Returns: | None |
Method: | Stop |
---|---|
Description: | Powers down the WaveDAC to its lowest power state and disables output |
Returns: | None |
Method: | StopClock |
---|---|
Description: | Stops the WaveDAC clock so that a value can be set without interference by the clock |
Returns: | None |
Method: | Wakeup |
---|---|
Description: | Restores and enables the most recently saved configuration of the DAC |
Returns: | None |
Method: | is_running |
---|---|
Description: | Checks to see if the DAC component and all subcomponents are currently operational |
Returns: | A boolean variable which evaluates to True if the DAC is active, or False if it is not |