![]() |
Serial Wombat 18AB Firmware
|
#include "serialWombat.h"#include <stdint.h>#include "inputProcess.h"#include "pic24fj256ga702/mcc_generated_files/mcc.h"Classes | |
| struct | analogInput_n |
Macros | |
| #define | analogInput ((analogInput_t*) CurrentPinRegister) |
Typedefs | |
| typedef struct analogInput_n | analogInput_t |
Functions | |
| uint16_t | GetADCConversion (uint8_t pin) |
| void | initAnalogInput (void) |
| void | updateAnalogInput () |
| void | initAnalogSimple () |
Variables | |
| analogInput_t * | debugAnalog |
| #define analogInput ((analogInput_t*) CurrentPinRegister) |
| typedef struct analogInput_n analogInput_t |
| uint16_t GetADCConversion | ( | uint8_t | pin | ) |
| void initAnalogInput | ( | void | ) |
\brief Initialization routine for Analog Input
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.
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 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
Unused on the SW4A and SW4B.
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
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
| void initAnalogSimple | ( | ) |
| void updateAnalogInput | ( | ) |
| analogInput_t* debugAnalog |
1.8.17