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

Classes

struct  quadEnc_n
 

Macros

#define quadEnc   ((quadEnc_t*) CurrentPinRegister)
 

Typedefs

typedef struct quadEnc_n quadEnc_t
 

Functions

void initQuadEnc (void)
 
void update_quadEnc (void)
 Periodic call to service the Quadrature Encoder decoder State Machine for a pin. More...
 

Variables

uint8_t copy_IOC_PortBuffer [IOC_BUFFER_SIZE]
 

Detailed Description

This file contains the Quadrature Encoder pin mode for the Serial Wombat 4A and 4B

This file contains the Watchdog pin mode for the Serial Wombat 4A and 4B

Macro Definition Documentation

◆ quadEnc

#define quadEnc   ((quadEnc_t*) CurrentPinRegister)

Typedef Documentation

◆ quadEnc_t

typedef struct quadEnc_n quadEnc_t

Function Documentation

◆ initQuadEnc()

void initQuadEnc ( void  )
\brief Initialization routine for Quadrature Encoder pin mode

Retrevial of Quadrature Encoder Position Value

Configure the QuadEnc pin mode using the CONFIGURE_CHANNEL_MODE_0 command before reading values.
The Quadrature Encoder Position value is stored in the Primary Pin's 16-bit Public data area. Use the Read Pin Buffer command to retreive it.

The Position value is a 16-bit unsigned number. Transitions that decrement a value of 0 will roll over to 65535. Transitions which incrment a value of 65535 will roll over to 0.


CONFIGURE_CHANNEL_MODE_0:

Initialize Quadrature Encoder Reader.

BYTE 0 BYTE 1 BYTE 2 BYTE 3 BYTE 4 BYTE 5 BYTE 6 BYTE 7
0xC0 Pin To Set 0x05 (Quadrature Encoder) Debounce Frames (low byte) Debounce Frames (high byte, ignored) Second Pin Number Read State (0,1,2,4,5 or 6) 0: Pull ups off, 1: Pull ups on

Read State Values:

0 = Read on Primary Pin High to Low transition, sampled with interrupts

1 = Read on Primary Pin Low to High transition, sampled with interrupts

2 = Read on Both transitions, sampled with interrupts

4 = Read on Primary Pin High to Low transition, polled every 1mS frame

5 = Read on Primary Pin Low to High transition, polled every 1mS frame

6 = Read on Both transitions, polled every 1mS frame

Response:

Command is echoed back.

Examples:

Set pins 1 (primary) and 2 (secondary) to quadrature encoder reading, 10 mS of debounce, Pull ups on, Read both transitions in polled mode

0xC0 0x01 0x05 0x0A 0x00 0x02 0x06 0x01

◆ update_quadEnc()

void update_quadEnc ( void  )

Periodic call to service the Quadrature Encoder decoder State Machine for a pin.

This State machine monitors inputs from two pins (Primary and Secondary) to increment or decrement a counter based on transitions of a rotary encoder.

This State machine is called every 1 mS by the executive when the Primary pin is serviced. Initialization of this state machine sets the secondary pin mode to PIN_MODE_CONTROLLED, which is not serviced by the executive.

The quadrature encoder monitors the state of the Primary and Secondary pins via either polling (the pins are read when the state machine is serviced) or via interrupt when a change is state on the Primary pin is detected, at which time the state of both pins is recorded and saved for later processing when the state machine is serivced.

Saved interrupt transitions are stored in copy_IOC_PortBuffer, which is an array which is copied once for all pins from a similar interrupt modified array just prior to beginning the pin-servicing process every 1 mS. copy_IOC_PortBuffer stores the state of all 4 SW pins whenever an interrupt-on-change occurs. The array is initialized to 0xFF. Any interrupt on change sets the most significant bit of the value to 0 indicating that the element has new data. The array is filled from end to start so that incrementing indexing gets events as they happened in chronological order. Unused elements are therefore at the beginning of the array.

The update routine first looks to see if transitions are ignored due to being in a debounce period. If so, it decrements the debounce counter and returns.

If not in debounce, the state machine either samples and processes the primary pin state, or iterates through the copy_IOC_PortBuffer looking for transitions of the primary pin.

When a transition that is relevant based on readState occurs, the state of the second pin is checked against the primary pin. If they are the same the position counter is incremented. If they are different, then the position counter is decremented. The debounce counter is then set to the configured value. If the debounce counter is >0 and interrupt processing is occuring then the remainder of interrupts during that service are ignored.

Variable Documentation

◆ copy_IOC_PortBuffer

uint8_t copy_IOC_PortBuffer[IOC_BUFFER_SIZE]