Serial Wombat 4A and 4B Firmware
Classes | Macros | Typedefs | Functions
analogInput.c File Reference
#include "serialWombat.h"
#include <stdint.h>

Classes

struct  analogInput_n
 

Macros

#define analogInput   ((analogInput_t*) CurrentPinRegister)
 

Typedefs

typedef struct analogInput_n analogInput_t
 

Functions

void initAnalogInput (void)
 
void updateAnalogInput ()
 Periodic call to service the Analog Input State Machine for a pin. More...
 

Detailed Description

This file contains the Analog Input pin mode for the SerialWombat 4A and 4B.

Macro Definition Documentation

◆ analogInput

#define analogInput   ((analogInput_t*) CurrentPinRegister)

Typedef Documentation

◆ analogInput_t

typedef struct analogInput_n analogInput_t

Function Documentation

◆ initAnalogInput()

void initAnalogInput ( void  )
\brief Initialization routine for Analog Input

Retrevial of Raw A/D conversions

Configure the A/D using the CONFIGURE_CHANNEL_MODE_0 command before reading values.
Raw A/D conversions are stored in the Pin's 16-bit Public data area. Use the Read Pin Buffer command to retreive it.


CONFIGURE_CHANNEL_MODE_0:

Initialize Analog Input. Disables averaged and filtered values.

BYTE 0 BYTE 1 BYTE 2 BYTE 3 BYTE 4 BYTE 5 BYTE 6 BYTE 7
0xC0 Pin To Set 0x02 (Analog Input) 0x55* 0x55* 0x55* 0x55* 0x55*

*0x55 is recommended, but any byte is acceptable

Response:

Command is echoed back.

Examples:

Set pin 3 to Analog Input.

0xC0 0x03 0x02 0x55 0x55 0x55 0x55 0x55


CONFIGURE_CHANNEL_MODE_1:

Configure analog input averaging and filtering. CONFIGURE_CHANNEL_MODE_0 should be sent for the pin prior to sending this command.

Filtering is done by the following algorithm:

Filtered Value = Prior Filtered value * (constant / 65536) + New Sample * ((65536 - constant)

This happens every 1mS (1000 hZ).

BYTE 0 BYTE 1 BYTE 2 BYTE 3 BYTE 4 BYTE 5 BYTE 6 BYTE 7
0xC1 Pin To Set 0x02 (Analog Input) Averaging Count low byte (0 = off, 64 = 64 counts) Averaging Count high byte (set to 0, for compatability with SW19) Filter Constant Low Byte Filter Constant High Byte 0x55*

*0x55 is recommended, but any byte is acceptable

Response:

Command is echoed back.

Examples:

Configure pin 3 Analog input to turn on averaging, set filter constant to 64358 (0xFB66)

0xC1 0x03 0x02 0x40 0x00 0x66 0xFB 0x55


CONFIGURE_CHANNEL_MODE_2:

Unused on the SW4A and SW4B.


CONFIGURE_CHANNEL_MODE_3:

Retreive the Minimum and Maximum recorded raw values.

This command can optionally reset the minimum and maximum values after reading. This will cause them both to be set to the next A/D sample taken.

The pin should have previously been configured as an analog input before sending this command.

BYTE 0 BYTE 1 BYTE 2 BYTE 3 BYTE 4 BYTE 5 BYTE 6 BYTE 7
0xC3 Pin Number 0x02 (Analog Input) 0: Don't reset values 1: Reset Minimum and Maximum 0x55* 0x55* 0x55* 0x55*

*0x55 is recommended, but any byte is acceptable

Response:

BYTE 0 BYTE 1 BYTE 2 BYTE 3 BYTE 4 BYTE 5 BYTE 6 BYTE 7
0xC3 Pin Number 0x02 (Analog Input) Minimum Low Byte Minimum High Byte Maximum Low Byte Maximum High Byte Echo of Byte 7

Examples:

Get Minimum and maximum values from pin 3, and reset after reading. (Assume minimum value was 0x3F80, and Maximum was 0xDC40 )

Sent:

0xC3 0x03 0x02 0x01 0x55 0x55 0x55 0x55

Received:

0xC3 0x03 0x02 0x80 0x3F 0x40 0xDC 0x55


CONFIGURE_CHANNEL_MODE_4:

Retreive the averaged and filtered values.

The pin should have previously been configured as an analog input using CONFIGURE_CHANNEL_MODE_0 and the average and/or filtered values enabled using CONFIGURE_CHANNEL_MODE_1 before sending this command.

BYTE 0 BYTE 1 BYTE 2 BYTE 3 BYTE 4 BYTE 5 BYTE 6 BYTE 7
0xC4 Pin Number 0x02 (Analog Input) 0x55* 0x55* 0x55* 0x55* 0x55*

*0x55 is recommended, but any byte is acceptable

Response:

BYTE 0 BYTE 1 BYTE 2 BYTE 3 BYTE 4 BYTE 5 BYTE 6 BYTE 7
0xC4 Pin Number 0x02 (Analog Input) Average Low Byte Average High Byte Filtered Low Byte Filtered High Byte Echo of Byte 7

Examples:

Get Averaged and Filtered values from pin 3. (Assume Averaged value was 0x3F80, and Filtered was 0xDC40 )

Sent:

0xC4 0x03 0x02 0x55 0x55 0x55 0x55 0x55

Received:

0xC4 0x03 0x02 0x80 0x3F 0x40 0xDC 0x55

◆ updateAnalogInput()

void updateAnalogInput ( )

Periodic call to service the Analog Input State Machine for a pin.

This function expects to get called every mS.

This function does A/D conversions during the servicing of the function using the internal 10-bit A/D converter. Values are shifted six bits left to scale to 0-65535 public data range.
Conversions which yield 1023 (Maximum value) are Scaled to 65535 to indicate maximum value. This happens after the A/D conversion is used to calculate averaged and filtered values, so Averaged values could reach a maximum value of 65472, not 65535 (64 * 1023 = 65472).

Filtered value and averaged value are updated every call if enabled. These values are based on scaled values.

Minimum and Maximum are updated every call and are based on raw A/D values.