saadc

package
v0.5.7 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jan 9, 2025 License: BSD-3-Clause Imports: 8 Imported by: 0

Documentation

Index

Constants

View Source
const (
	Over1x   = 0 // Bypass oversampling.
	Over2x   = 1 // Oversample 2x
	Over4x   = 2 // Oversample 4x
	Over8x   = 3 // Oversample 8x
	Over16x  = 4 // Oversample 16x
	Over32x  = 5 // Oversample 32x
	Over64x  = 6 // Oversample 64x
	Over128x = 7 // Oversample 128x
	Over256x = 8 // Oversample 256x
)

Variables

This section is empty.

Functions

func AnalogInit

func AnalogInit(resBits int)

AnalogInit provides a convenient way to configure the SAADC peripheral to use it by AnalogRead function. It configures and calibrates SAADC(0), disconnnects all irs channels from analog inputs and changes the configuration of channel 0.

The SAADC resolution is set to resBits. The 4x hardware oversampling in burst mode is used to reduce the noise. The channel 0 configuration is set to G1_4|RVDD1_4|T10us|Burst. You can modify these settings using SAADC(0) StoreOVERSAMPLE and StoreCONFIG methods.

func AnalogRead

func AnalogRead(ain gpio.AIN) int

AnalogRead works like Arduino analogRead function. It connects SAADC channel 0 to ain and performs a conversion triggering START and SAMPLE tasks. If the 4x oversampling is used (AnalogInit default) the conversion takes about 100 microsecond just like the original analogRead on Arduino UNO, Nano, Mini, Mega. Use SAADC directly in continuous mode to achieve the maximum 200 kHz sampling rate (5 microseconds per sample).

The SAADC peripheral and its channel 0 must be properly configured before using this function (see AnalogInit).

Types

type Config

type Config uint32
const (
	Rp       Config = 3 << 0 // Positive channel pull up/down resistors control
	RpNone   Config = 0 << 0 // Disconnect resistor ladder.
	RpVSS    Config = 1 << 0 // Pull down to VSS (GND).
	RpVDD    Config = 2 << 0 // Pull up to VDD.
	RpVDD1_2 Config = 3 << 0 // Activate both resistors to set input at VDD/2.

	Rn       Config = 3 << 4 // Negative channel pull up/down resistors control
	RnNone   Config = 0 << 4 // Disconnect resistor ladder.
	RnVSS    Config = 1 << 4 // Pull down to VSS (GND).
	RnVDD    Config = 2 << 4 // Pull up to VDD.
	RnVDD1_2 Config = 3 << 4 // Activate both resistors to set input at VDD/2.

	G    Config = 7 << 8 // Gain controll.
	G1_6 Config = 0 << 8 // 1/6
	G1_5 Config = 1 << 8 // 1/5
	G1_4 Config = 2 << 8 // 1/4
	G1_3 Config = 3 << 8 // 1/3
	G1_2 Config = 4 << 8 // 1/2
	G1   Config = 5 << 8 // 1
	G2   Config = 6 << 8 // 2
	G4   Config = 7 << 8 // 4

	RVDD1_4 Config = 1 << 12 // VDD/4 as reference instead of internal 0.6V.

	T     Config = 7 << 16 // Acquistion time.
	T3us  Config = 0 << 16 //  3 us
	T5us  Config = 1 << 16 //  5 us
	T10us Config = 2 << 16 // 10 us
	T15us Config = 3 << 16 // 15 us
	T20us Config = 4 << 16 // 20 us
	T40us Config = 5 << 16 // 40 us

	Diff Config = 1 << 20 // Enable differentail mode.

	Burst Config = 1 << 24 // Enable burst mode.
)

type Event

type Event uint8
const (
	STARTED       Event = 0  // The SAADC has started.
	END           Event = 1  // The SAADC has filled up the result buffer.
	DONE          Event = 2  // A conversion task has been completed.
	RESULTDONE    Event = 3  // Result ready for transfer to RAM.
	CALIBRATEDONE Event = 4  // Calibration is complete.
	STOPPED       Event = 5  // The SAADC has stopped.
	CH0LIMITH     Event = 6  // Last result is equal or above CH[0].LIMIT.HIGH
	CH0LIMITL     Event = 7  // Last result is equal or below CH[0].LIMIT.LOW
	CH1LIMITH     Event = 8  // Last result is equal or above CH[1].LIMIT.HIGH
	CH1LIMITL     Event = 9  // Last result is equal or below CH[1].LIMIT.LOW
	CH2LIMITH     Event = 10 // Last result is equal or above CH[2].LIMIT.HIGH
	CH2LIMITL     Event = 11 // Last result is equal or below CH[2].LIMIT.LOW
	CH3LIMITH     Event = 12 // Last result is equal or above CH[3].LIMIT.HIGH
	CH3LIMITL     Event = 13 // Last result is equal or below CH[3].LIMIT.LOW
	CH4LIMITH     Event = 14 // Last result is equal or above CH[4].LIMIT.HIGH
	CH4LIMITL     Event = 15 // Last result is equal or below CH[4].LIMIT.LOW
	CH5LIMITH     Event = 16 // Last result is equal or above CH[5].LIMIT.HIGH
	CH5LIMITL     Event = 17 // Last result is equal or below CH[5].LIMIT.LOW
	CH6LIMITH     Event = 18 // Last result is equal or above CH[6].LIMIT.HIGH
	CH6LIMITL     Event = 19 // Last result is equal or below CH[6].LIMIT.LOW
	CH7LIMITH     Event = 20 // Last result is equal or above CH[7].LIMIT.HIGH
	CH7LIMITL     Event = 21 // Last result is equal or below CH[7].LIMIT.LOW
)

type Periph

type Periph struct {
	te.Regs
	// contains filtered or unexported fields
}

func SAADC

func SAADC(n int) *Periph

func (*Periph) Event

func (p *Periph) Event(e Event) *te.Event

func (*Periph) LoadAMOUNT

func (p *Periph) LoadAMOUNT() int

LoadAMOUNT returns the number of 16-bit samples written to the output buffer since the previous START task.

func (*Periph) LoadCONFIG

func (p *Periph) LoadCONFIG(ch int) Config

LoadCONFIG returns the current configuratio of the SAADC channel ch.

func (*Periph) LoadENABLE

func (p *Periph) LoadENABLE() bool

LoadENABLE reports whether the SAADC peripheral is enabled.

func (*Periph) LoadLIMIT

func (p *Periph) LoadLIMIT(ch int) (low, high int16)

LoadLIMIT returns the current limits for channel ch.

func (*Periph) LoadMAXCNT

func (p *Periph) LoadMAXCNT() int

LoadMAXCNT returns the configured maximum number of 16-bit result samples.

func (*Periph) LoadOVERSAMPLE

func (p *Periph) LoadOVERSAMPLE() int

LoadOVERSAMPLE returns the current SAADC oversampling configuration.

func (*Periph) LoadPSELN

func (p *Periph) LoadPSELN(ch int) gpio.AIN

LoadPSELN returns the analog input used as of negative input of channel ch.

func (*Periph) LoadPSELP

func (p *Periph) LoadPSELP(ch int) gpio.AIN

LoadPSELP returns the analog input used as of positive input of channel ch.

func (*Periph) LoadPTR

func (p *Periph) LoadPTR() uintptr

LoadPTR returns the last set result data pointer. The PTR register is double buffered and you have no access to the internal one.

func (*Periph) LoadRESOLUTION

func (p *Periph) LoadRESOLUTION() int

LoadRESOLUTION returns the current SAADC resolution: 8, 10, 12 or 14 (bits).

func (*Periph) LoadSAMPLERATE

func (p *Periph) LoadSAMPLERATE() (cc int, localTimer bool)

LoadSAMPLERATE returns the "capture and compare" value and reports whether the SAADC local timer and cc is used to control SR. If localTimer is true the sample rate is equal to 16 MHz / cc, otherwise the SR is controlled by SAMPLE task.

func (*Periph) LoadSTATUS

func (p *Periph) LoadSTATUS() bool

LoadSTALSTAT reports busy status of the SAADC. It returns true if the conversion is in progress and false if there is no on-going conversions.

func (*Periph) StoreCONFIG

func (p *Periph) StoreCONFIG(ch int, cfg Config)

StoreCONFIG configrues the channel ch.

func (*Periph) StoreENABLE

func (p *Periph) StoreENABLE(en bool)

StoreENABLE enables or disables the SAADC peripheral.

func (*Periph) StoreLIMIT

func (p *Periph) StoreLIMIT(ch int, low, high int16)

StoreLIMIT sets the limits for channel ch.

func (*Periph) StoreMAXCNT

func (p *Periph) StoreMAXCNT(n int)

StoreMAXCNT sets the maximum number of 16-bit samples to be written to the output buffer set by StorePTR.

func (*Periph) StoreOVERSAMPLE

func (p *Periph) StoreOVERSAMPLE(over int)

StoreOVERSAMPLE sets the SAADC oversampling configuration. The oversampling should only be used when single input channel is enabled.

func (*Periph) StorePSELN

func (p *Periph) StorePSELN(ch int, a gpio.AIN)

StorePSELN configures the negative input of channel ch to use analog input a.

func (*Periph) StorePSELP

func (p *Periph) StorePSELP(ch int, a gpio.AIN)

StorePSELP configures the positive input of channel ch to use analog input a.

func (*Periph) StorePTR

func (p *Periph) StorePTR(ptr unsafe.Pointer)

StorePTR sets the result data pointer. The PTR register is double buffered and the internal one is unaffected until the START task is triggered.

func (*Periph) StoreRESOLUTION

func (p *Periph) StoreRESOLUTION(res int)

StoreRESOLUTION sets the SAADC resolution: 8, 10, 12 or 14 (bits).

func (*Periph) StoreSAMPLERATE

func (p *Periph) StoreSAMPLERATE(cc int, localTimer bool)

StoreSAMPLERATE configures the source of sample rate. If localTimer is true the SAADC local timer is used as sample rate source (SR = 16 MHz / cc). Otherwise the SAMPLE task is used. CC must be in the range [80..2047]. The local timer can only be used when single input channel is enabled.

func (*Periph) Task

func (p *Periph) Task(t Task) *te.Task

type Task

type Task uint8
const (
	START     Task = 0 // Start the SAADC and prepare the result buffer in RAM.
	SAMPLE    Task = 1 // Take one SAADC sample.
	STOP      Task = 2 // Stop the SAADC and terminate all on-going conversions.
	CALIBRATE Task = 3 // Start offset auto-calibration.
)

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL