Shield Code 6.0
Loading...
Searching...
No Matches
main.cpp File Reference

Main file for the 317 lab project. More...

#include <Arduino.h>
#include <Pip.hpp>
#include <PDC.hpp>
#include <AT25M02.hpp>
#include <PipController.hpp>
#include <IMU.hpp>
#include <Wire.h>
#include <LSM6.h>
#include <LIS3MDL.h>
#include "sweep_values_v5_1.h"
Include dependency graph for main.cpp:

Go to the source code of this file.

Macros

#define BUFFER   1000
 
#define SWEEP_OFFSET   500
 
#define RAM_BUFFER_DELAY   10
 
#define SWEEP_STEPS   28
 
#define SHIELD_NUMBER   5
 
#define SWEEP_DELAY   46.875
 
#define SWEEP_AVERAGES   8
 
#define IMU_TIMESTAMP_OFFSET   0
 
#define IMU_DATA_OFFSET   (sizeof(IMUTimeStamp) + IMU_TIMESTAMP_OFFSET)
 
#define SWEEP_TIMESTAMP_OFFSET   (sizeof(IMUData) + IMU_DATA_OFFSET)
 
#define SWEEP_DATA_OFFSET   (sizeof(sweepTimeStamp) + SWEEP_TIMESTAMP_OFFSET)
 
#define RAM_BUF_LEN   (sizeof(IMUTimeStamp) + sizeof(IMUData) + sizeof(sweepTimeStamp) + sizeof(sweep_buffer))
 
#define SYNC_PIN   53
 

Enumerations

enum  BobState {
  idle , startSweep , sendSweep , takeIMU ,
  sendIMU , sendStored , sendTimeStamps , waitForNewCycle ,
  interrupted , store , read
}
 

Functions

void blink ()
 Blinks the onboard LED. Used for debugging.
 
void configureTimerInterrupt ()
 Configures timer counter for interrupt Documentation for internal functions - see tc.c (system/libsam/source/tc.c at https://github.com/swallace23/framework-arduino-sam) The processor has 3 clocks, each have 3 channels and 3 registers (RA, RB, RC). This is set up to use TC0 and channel 0. RC is used to store the compare value. The interrupt is triggered when the counter reaches the compare value. Calculate interrupt frequency with: interrupt frequency = clock frequency / (RC+1) Note that the clock frequency for TC0 is configured to be 656.25 kHz.
 
void syncHandler ()
 
void FSMUpdate ()
 Finite State Machine update function.
 
void FSMAction ()
 Finite State Machine action function.
 
void startSweepOnShield ()
 Attaches last data buffer to UART PDC, runs DAC sweep, and saves pip data into a combined buffer.
 
void sendIMUData ()
 
void sendSweepData ()
 
void takeIMUData ()
 
void sendStoredData ()
 
void storeData ()
 
void readData ()
 
void sendData ()
 
void setup ()
 
void loop ()
 
void TC0_Handler ()
 

Variables

bool debug = false
 
int cycle_counter = 0
 
PDC pdc
 
Max1148 adc0 (Channel::CHAN2)
 
Max1148 adc1 (Channel::CHAN1)
 
Pip pip0 (SWEEP_DELAY, SWEEP_AVERAGES, SWEEP_STEPS, 339, 3752, DAC0, adc0)
 
Pip pip1 (SWEEP_DELAY, SWEEP_AVERAGES, SWEEP_STEPS, 339, 3752, DAC1, adc1)
 
PipController pipController (pip0, pip1)
 
LIS3MDL compass
 
LSM6 gyro
 
AT25M02 ram
 
uint8_t shieldID = 60
 
int16_t IMUData [10]
 
uint32_t IMUTimeStamp
 
uint32_t * p_IMUTimeStamp = &IMUTimeStamp
 
uint8_t sweepSentinel [3] = {'#', '#', 'S'}
 
uint8_t sweepSentinelBuf [3] = {'#', '#', 'T'}
 
uint8_t imuSentinel [3] = {'#', '#', 'I'}
 
uint8_t imuSentinelBuf [3] = {'#', '#', 'J'}
 
bool savedSweep = false
 
bool sendFromRam = false
 
bool storeToRam = true
 
uint16_t sweep_buffer [2 *SWEEP_STEPS]
 
uint32_t startTime = 0
 
uint32_t sweepStartTime = 0
 
uint32_t sweepTimeStamp = 0
 
uint32_t * p_sweepTimeStamp = &sweepTimeStamp
 
uint8_t ramBuf [RAM_BUF_LEN]
 
const size_t totalSize = 294
 
uint8_t memory_block [totalSize]
 
uint8_t * p_memory_block = memory_block
 
volatile uint32_t timer
 
volatile bool syncPulse
 
volatile bool newCycle
 
BobState currentState = idle
 
bool isFirst = true
 
bool goLow = true
 Interrupt handler for the TC0 timer.
 
int shortSize = sizeof(sweepSentinel)+sizeof(sweepTimeStamp)+sizeof(sweep_buffer)+sizeof(imuSentinel)+sizeof(IMUTimeStamp)+sizeof(IMUData)
 

Detailed Description

Main file for the 317 lab project.

Contains shield initialization, state machine implementation and functions, and interrupt handling.

Definition in file main.cpp.

Macro Definition Documentation

◆ BUFFER

#define BUFFER   1000

Definition at line 55 of file main.cpp.

◆ IMU_DATA_OFFSET

#define IMU_DATA_OFFSET   (sizeof(IMUTimeStamp) + IMU_TIMESTAMP_OFFSET)

Definition at line 122 of file main.cpp.

◆ IMU_TIMESTAMP_OFFSET

#define IMU_TIMESTAMP_OFFSET   0

Definition at line 121 of file main.cpp.

◆ RAM_BUF_LEN

#define RAM_BUF_LEN   (sizeof(IMUTimeStamp) + sizeof(IMUData) + sizeof(sweepTimeStamp) + sizeof(sweep_buffer))

Definition at line 125 of file main.cpp.

◆ RAM_BUFFER_DELAY

#define RAM_BUFFER_DELAY   10

Definition at line 57 of file main.cpp.

◆ SHIELD_NUMBER

#define SHIELD_NUMBER   5

Definition at line 67 of file main.cpp.

◆ SWEEP_AVERAGES

#define SWEEP_AVERAGES   8

Definition at line 76 of file main.cpp.

◆ SWEEP_DATA_OFFSET

#define SWEEP_DATA_OFFSET   (sizeof(sweepTimeStamp) + SWEEP_TIMESTAMP_OFFSET)

Definition at line 124 of file main.cpp.

◆ SWEEP_DELAY

#define SWEEP_DELAY   46.875

Definition at line 75 of file main.cpp.

◆ SWEEP_OFFSET

#define SWEEP_OFFSET   500

Definition at line 56 of file main.cpp.

◆ SWEEP_STEPS

#define SWEEP_STEPS   28

Definition at line 65 of file main.cpp.

◆ SWEEP_TIMESTAMP_OFFSET

#define SWEEP_TIMESTAMP_OFFSET   (sizeof(IMUData) + IMU_DATA_OFFSET)

Definition at line 123 of file main.cpp.

◆ SYNC_PIN

#define SYNC_PIN   53

Definition at line 133 of file main.cpp.

Enumeration Type Documentation

◆ BobState

enum BobState
Enumerator
idle 
startSweep 
sendSweep 
takeIMU 
sendIMU 
sendStored 
sendTimeStamps 
waitForNewCycle 
interrupted 
store 
read 

Definition at line 141 of file main.cpp.

Function Documentation

◆ blink()

void blink ( )

Blinks the onboard LED. Used for debugging.

Definition at line 392 of file main.cpp.

◆ configureTimerInterrupt()

void configureTimerInterrupt ( )

Configures timer counter for interrupt Documentation for internal functions - see tc.c (system/libsam/source/tc.c at https://github.com/swallace23/framework-arduino-sam) The processor has 3 clocks, each have 3 channels and 3 registers (RA, RB, RC). This is set up to use TC0 and channel 0. RC is used to store the compare value. The interrupt is triggered when the counter reaches the compare value. Calculate interrupt frequency with: interrupt frequency = clock frequency / (RC+1) Note that the clock frequency for TC0 is configured to be 656.25 kHz.

Definition at line 431 of file main.cpp.

◆ FSMAction()

void FSMAction ( )

Finite State Machine action function.

This function performs the action associated with the current state.

Definition at line 354 of file main.cpp.

◆ FSMUpdate()

void FSMUpdate ( )

Finite State Machine update function.

This function updates the state machine based on the current state.

Definition at line 235 of file main.cpp.

◆ loop()

void loop ( )

Definition at line 217 of file main.cpp.

◆ readData()

void readData ( )

Definition at line 496 of file main.cpp.

◆ sendData()

void sendData ( )

Definition at line 504 of file main.cpp.

◆ sendIMUData()

void sendIMUData ( )

◆ sendStoredData()

void sendStoredData ( )

◆ sendSweepData()

void sendSweepData ( )

◆ setup()

void setup ( )

Definition at line 170 of file main.cpp.

◆ startSweepOnShield()

void startSweepOnShield ( )

Attaches last data buffer to UART PDC, runs DAC sweep, and saves pip data into a combined buffer.

Definition at line 459 of file main.cpp.

◆ storeData()

void storeData ( )

Definition at line 487 of file main.cpp.

◆ syncHandler()

void syncHandler ( )

Definition at line 417 of file main.cpp.

◆ takeIMUData()

void takeIMUData ( )

Definition at line 482 of file main.cpp.

◆ TC0_Handler()

void TC0_Handler ( )

Definition at line 403 of file main.cpp.

Variable Documentation

◆ adc0

◆ adc1

◆ compass

LIS3MDL compass

Definition at line 88 of file main.cpp.

◆ currentState

BobState currentState = idle

Definition at line 154 of file main.cpp.

◆ cycle_counter

int cycle_counter = 0

Definition at line 62 of file main.cpp.

◆ debug

bool debug = false

Definition at line 61 of file main.cpp.

◆ goLow

bool goLow = true

Interrupt handler for the TC0 timer.

Definition at line 402 of file main.cpp.

◆ gyro

LSM6 gyro

Definition at line 89 of file main.cpp.

◆ IMUData

int16_t IMUData[10]

Definition at line 96 of file main.cpp.

◆ imuSentinel

uint8_t imuSentinel[3] = {'#', '#', 'I'}

Definition at line 102 of file main.cpp.

◆ imuSentinelBuf

uint8_t imuSentinelBuf[3] = {'#', '#', 'J'}

Definition at line 103 of file main.cpp.

◆ IMUTimeStamp

uint32_t IMUTimeStamp

Definition at line 97 of file main.cpp.

◆ isFirst

bool isFirst = true

Definition at line 168 of file main.cpp.

◆ memory_block

uint8_t memory_block[totalSize]

Definition at line 130 of file main.cpp.

◆ newCycle

volatile bool newCycle

Definition at line 136 of file main.cpp.

◆ p_IMUTimeStamp

uint32_t* p_IMUTimeStamp = &IMUTimeStamp

Definition at line 98 of file main.cpp.

◆ p_memory_block

uint8_t* p_memory_block = memory_block

Definition at line 131 of file main.cpp.

◆ p_sweepTimeStamp

uint32_t* p_sweepTimeStamp = &sweepTimeStamp

Definition at line 118 of file main.cpp.

◆ pdc

PDC pdc

Definition at line 79 of file main.cpp.

◆ pip0

Pip pip0(SWEEP_DELAY, SWEEP_AVERAGES, SWEEP_STEPS, 339, 3752, DAC0, adc0) ( SWEEP_DELAY  ,
SWEEP_AVERAGES  ,
SWEEP_STEPS  ,
339  ,
3752  ,
DAC0  ,
adc0   
)

◆ pip1

Pip pip1(SWEEP_DELAY, SWEEP_AVERAGES, SWEEP_STEPS, 339, 3752, DAC1, adc1) ( SWEEP_DELAY  ,
SWEEP_AVERAGES  ,
SWEEP_STEPS  ,
339  ,
3752  ,
DAC1  ,
adc1   
)

◆ pipController

PipController pipController(pip0, pip1) ( pip0  ,
pip1   
)

◆ ram

AT25M02 ram

Definition at line 90 of file main.cpp.

◆ ramBuf

uint8_t ramBuf[RAM_BUF_LEN]

Definition at line 127 of file main.cpp.

◆ savedSweep

bool savedSweep = false

Definition at line 105 of file main.cpp.

◆ sendFromRam

bool sendFromRam = false

Definition at line 106 of file main.cpp.

◆ shieldID

uint8_t shieldID = 60

Definition at line 93 of file main.cpp.

◆ shortSize

int shortSize = sizeof(sweepSentinel)+sizeof(sweepTimeStamp)+sizeof(sweep_buffer)+sizeof(imuSentinel)+sizeof(IMUTimeStamp)+sizeof(IMUData)

Definition at line 502 of file main.cpp.

◆ startTime

uint32_t startTime = 0

Definition at line 115 of file main.cpp.

◆ storeToRam

bool storeToRam = true

Definition at line 107 of file main.cpp.

◆ sweep_buffer

uint16_t sweep_buffer[2 *SWEEP_STEPS]

Definition at line 110 of file main.cpp.

◆ sweepSentinel

uint8_t sweepSentinel[3] = {'#', '#', 'S'}

Definition at line 100 of file main.cpp.

◆ sweepSentinelBuf

uint8_t sweepSentinelBuf[3] = {'#', '#', 'T'}

Definition at line 101 of file main.cpp.

◆ sweepStartTime

uint32_t sweepStartTime = 0

Definition at line 116 of file main.cpp.

◆ sweepTimeStamp

uint32_t sweepTimeStamp = 0

Definition at line 117 of file main.cpp.

◆ syncPulse

volatile bool syncPulse

Definition at line 135 of file main.cpp.

◆ timer

volatile uint32_t timer

Definition at line 134 of file main.cpp.

◆ totalSize

const size_t totalSize = 294

Definition at line 129 of file main.cpp.