Skip to content

Commit fddbfbf

Browse files
committed
Merge branch 'sean.wallace.working' documentation updates
2 parents 352af51 + e75fbca commit fddbfbf

8 files changed

Lines changed: 40 additions & 62 deletions

File tree

include/AT25M02.hpp

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,14 @@
55
#include "SPI.h"
66

77
/**
8-
* Provides a library to interact with Microchip's AT25M02 chip.
8+
* @file AT25M02.hpp
9+
* @brief Provides a library to interact with Microchip's AT25M02 chip.
910
* This treats the chip as a circular queue that will not overwrite it's data.
1011
*
1112
*/
1213

13-
/*
14-
* Commands for the AT25M02 chip. Pulled from the data sheet for this chip.
14+
/**
15+
* @brief Commands for the AT25M02 chip. Pulled from the data sheet for this chip.
1516
* All commands are MSB first.
1617
*/
1718
enum Command

include/Max1148.hpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ class Max1148{
7777
*/
7878
void csh();
7979
/**
80-
* @brief Reads an average ADC value from the Max1148 ADC. Uses Arduino's SPI library.
80+
* @brief Reads an average ADC value from the Max1148 ADC. Uses Arduino's SPI library. We don't use this anymore because we wanted to interleave ADC sampling between channels.
8181
*
8282
* @param avg_num The number of samples to average.
8383
*/
@@ -89,7 +89,7 @@ class Max1148{
8989
public:
9090
/**
9191
* @brief ADC constructor. Sets cs_pin as per ADC_CS_PIN macro. Chooses channel from Channel enum.
92-
* @param channel The channel to read from. Format: CHAN0, CHAN1, etc.
92+
* @param channel The channel to read from. Format: CHAN0, CHAN1, etc. I don't remember why it has to be static_cast but it works.
9393
*/
9494
Max1148(Channel channel): cs_pin(ADC_CS_PIN) {
9595
this->channel = static_cast<uint8_t>(channel);

include/Pip.hpp

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -71,19 +71,15 @@ class Pip{
7171
uint16_t read_adc();
7272
public:
7373
/**
74-
* @brief Constructor for the Pip class. All parameters modifiable.
74+
* @brief Constructor for the Pip class.
75+
*
7576
*/
7677
Pip(int delay_us, uint16_t avg_num, uint16_t num_samples, uint16_t min, uint16_t max, uint8_t dac_pin, Max1148& adc);
7778
/**
7879
* @brief The data array for the sweep.
7980
*/
8081
uint16_t data[SWEEP_MAX_SAMPLES];
8182

82-
/**
83-
* @brief Sweeps the DAC output from min to max.
84-
* Step length, delay, and number of samples are all set by the constructor.
85-
*/
86-
void sweep();
8783

8884
};
8985
#endif

include/PipController.hpp

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
#include <Pip.hpp>
66
/**
77
* @brief Manages simultaneous sweep for two Pip sensors.
8-
* A bit hacky, but allows easily storing separate sweep data in each Pip object without compromising data privacy.
8+
* A bit hacky, but allows easily managing simultaneous sweeping while keeping data separate and clean.
99
*/
1010
class PipController{
1111
private:
@@ -14,8 +14,7 @@ class PipController{
1414
public:
1515
PipController(Pip& pip1, Pip& pip2) : pip1(pip1), pip2(pip2) {}
1616
/**
17-
* @brief Sweeps both DACs simultaneously, reads both ADC channels.
18-
* Functionally identical to the version committed by Max Roberts in 2015.
17+
* @brief Sweeps both DACs simultaneously, reads both ADC channels. Note that ADC sampling alternates between each pip channel.
1918
*/
2019
void sweep(){
2120
double value1 = pip1.sweep_min;
@@ -32,9 +31,11 @@ class PipController{
3231
analogWrite(pip2.dac_pin, (int)value2);
3332
value1 += step1;
3433
value2 += step2;
34+
//preamp settling time - experimentally derived
3535
delayMicroseconds(delay);
3636
int total_data1 = 0;
3737
int total_data2 = 0;
38+
//avg_num should be same across both pips.
3839
for (int i=0; i < pip1.avg_num; i++){
3940
total_data1 += pip1.read_adc();
4041
total_data2 += pip2.read_adc();

src/AT25M02.cpp

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ AT25M02::AT25M02()
3434
// Public Methods
3535

3636
/**
37-
* @brief Initialize the AT25M02 EEPROM device.
37+
* @brief Initialize the AT25M02 EEPROM device. Define spi settings, chip select pin, and set initial variables to zero.
3838
*/
3939
void AT25M02::init(){
4040
// Set up SPI device settings
@@ -49,16 +49,16 @@ void AT25M02::init(){
4949
setWRSR(0x00);
5050
}
5151

52-
/*
53-
* Returns how many bytes are free and available to be written to.
52+
/**
53+
* @brief Returns how many bytes are free and available to be written to.
5454
*/
5555
uint32_t AT25M02::freeBytes()
5656
{
5757
return RAM_SIZE - usedBytes();
5858
}
5959

60-
/*
61-
* Returns the number of bytes currently being used.
60+
/**
61+
* @brief Returns the number of bytes currently being used.
6262
*/
6363
uint32_t AT25M02::usedBytes()
6464
{
@@ -90,8 +90,8 @@ uint32_t AT25M02::freeBufferBytes()
9090
}
9191

9292

93-
/*
94-
* Write from the given array to the memory. This data is appended to the end of
93+
/**
94+
* @brief Write from the given array to the memory. This data is appended to the end of
9595
* the queue. Returns true if it successfully wrote all bytes. Returns false if
9696
* it could not write every byte without overwriting existing data.
9797
*/
@@ -164,8 +164,8 @@ uint32_t AT25M02::readMemory(byte *dest, uint32_t length)
164164
return len;
165165
}
166166

167-
/*
168-
* Write the given number of bytes from the ram into the destination array.
167+
/**
168+
* @brief Write the given number of bytes from the ram into the destination array.
169169
* These bytes are taken from the start of the queue.
170170
* Returns how many bytes were read and written to the array.
171171
*/
@@ -181,8 +181,8 @@ int AT25M02::readData(byte* dest, uint32_t length)
181181
return memlen + buflen;
182182
}
183183

184-
/*
185-
* Checks if the RAM is ready for a new command.
184+
/**
185+
* @brief Checks if the RAM is ready for a new command.
186186
*/
187187
bool AT25M02::isReady()
188188
{
@@ -199,8 +199,8 @@ bool AT25M02::isReady()
199199

200200
// Private Methods
201201

202-
/*
203-
* Write the given data to the RAM in a page write.
202+
/**
203+
* @brief Write the given data to the RAM in a page write.
204204
* Increments mem_end when done.
205205
*/
206206
void AT25M02::writePage(uint32_t addr, byte* bytes, uint32_t length)
@@ -266,8 +266,8 @@ void AT25M02::sendCommand(Command cmd)
266266
SPI.endTransaction();
267267
}
268268

269-
/*
270-
* Sets the WRSR (Write status reg)
269+
/**
270+
* @brief Sets the WRSR (Write status reg)
271271
*/
272272
void AT25M02::setWRSR(byte val)
273273
{
@@ -283,8 +283,8 @@ void AT25M02::setWRSR(byte val)
283283
SPI.endTransaction();
284284
}
285285

286-
/*
287-
* Waits until the RAM is ready to write.
286+
/**
287+
* @brief Waits until the RAM is ready to write.
288288
*/
289289
void AT25M02::waitUntilReady()
290290
{

src/Pip.cpp

Lines changed: 0 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,6 @@
22
* @file Pip.cpp
33
* @brief Source file for the Pip library for Dartmouth's 317 Lab.
44
*/
5-
/*Check how linear DAC output is
6-
7-
memory chips meant to be handed a page at a time, not bit by bit. that was the on board memory we had access to.
8-
That's what explains the weird page framing things. there may now be better ways to address now.
9-
should be able to use the 422 to program the arduino. we can't understand why not. Worried that we'll have to bring some of the
10-
usb aspect up, because need to program it.
11-
12-
Note - step time is 565 us.
13-
14-
*/
155
#include <Pip.hpp>
166
/** @copydoc Pip:Pip(int delay, uint16_t avg_num, uint16_t num_samples, uint16_t min, uint16_t max, uint8_t dac_pin, Max1148& adc) */
177
Pip::Pip(int delay, uint16_t avg_num, uint16_t num_samples, uint16_t min, uint16_t max, uint8_t dac_pin, Max1148& adc)
@@ -20,23 +10,6 @@ Pip::Pip(int delay, uint16_t avg_num, uint16_t num_samples, uint16_t min, uint16
2010
analogWriteResolution(12);
2111
}
2212

23-
24-
/** @copydoc Pip::sweep() */
25-
void Pip::sweep(){
26-
//clear data from last sweep. Shouldn't cause issues with sending since sweep won't begin until data is cleaned and loaded into PDC buffer.
27-
//Leaving commented because it shouldn't actually be necessary and impacts performance.
28-
//clear_data(data, sizeof(data) / sizeof(data[0]));
29-
30-
double value = sweep_min;
31-
double step = (double)(sweep_max - sweep_min) / (double)(num_samples - 1);
32-
for (int i = 0; i < num_samples; i++){
33-
analogWrite(DAC_PIN, (int)value);
34-
value += step;
35-
delayMicroseconds(delay_us);
36-
data[i] = adc.adc_read_avg(avg_num);
37-
}
38-
analogWrite(DAC_PIN, sweep_max);
39-
}
4013
/** @copydoc Pip::clear_data(uint16_t data[], uint16_t size) */
4114
void Pip::clear_data(uint16_t data[], uint16_t size){
4215
for (int i = 0; i < size; i++){

src/main.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ GSE-D is configured to program the board. Simply connect to the board with USB,
1717
1818
pio run
1919
20-
Make sure you fetch and pull changes from git before programming the board.
20+
Make sure you fetch and pull changes from git before programming the board. This will build the project again before uploading, but it should be very fast.
2121
2222
## Notes and Quirks
2323
The board uses an external crystal oscillator, rather than the included ceramic oscillator on the Due. This required some changes that are not included in this documentation. First, a modded_system_sam3xa.c file is included in src/ to change the startup clock settings. Then, replace_libsam.py replaces the gcc_rel.a file that contains the precompiled startup code with our modded version. This required manually including the CMSIS libraries in /src/.

src/modded_system_sam3xa.c

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,11 @@
11
#include "cmsis_include/sam3xa.h"
22

3-
// copied from C:\Users\<user>\.platformio\packages\framework-cmsis-atmel\CMSIS\Device\ATMEL\sam3xa\source\system_sam3xa.c
3+
/**
4+
* @file modded_system_sam3xa.c
5+
* @brief Rewrite of system_sam3xa.c to support the external crystal oscillator on the shield. 317 Lab changes are flagged in comments.
6+
* This is compiled into modded_libsam_3x8e_gcc_rel.a, which is linked into the final binary with replace_libsam.py. We have to do this because the Arduino framework uses a precompiled library for initial chip setup.
7+
* This allows us to modify clock settings without changing the Platformio build process.
8+
*/
49

510
/* @cond 0 */
611
/**INDENT-OFF**/
@@ -18,7 +23,7 @@ extern "C" {
1823
uint32_t SystemCoreClock = CHIP_FREQ_MAINCK_RC_4MHZ;
1924

2025
/**
21-
* \brief Setup the microcontroller system.
26+
* @brief Setup the microcontroller system.
2227
* Initialize the System and update the SystemFrequency variable.
2328
*/
2429
void SystemInit( void )
@@ -30,12 +35,13 @@ void SystemInit( void )
3035
/* Initialize main oscillator */
3136
if ( !(PMC->CKGR_MOR & CKGR_MOR_MOSCSEL) )
3237
{
38+
//317 LAB - the last flag here bypasses the internal RC oscillator
3339
PMC->CKGR_MOR = CKGR_MOR_KEY_PASSWD | SYS_BOARD_OSCOUNT | CKGR_MOR_MOSCRCEN | CKGR_MOR_MOSCXTBY;
3440
while ( !(PMC->PMC_SR & PMC_SR_MOSCXTS) )
3541
{
3642
}
3743
}
38-
44+
//317 LAB - I don't fully understand why this flag is necessary, but selecting the crystal oscillator with the bypass flag still routes through the external oscillator.
3945
/* Switch to 3-20MHz Xtal oscillator */
4046
PMC->CKGR_MOR = CKGR_MOR_KEY_PASSWD | SYS_BOARD_OSCOUNT | CKGR_MOR_MOSCRCEN | CKGR_MOR_MOSCXTBY | CKGR_MOR_MOSCSEL;
4147

@@ -68,6 +74,7 @@ void SystemInit( void )
6874
SystemCoreClock = CHIP_FREQ_CPU_MAX;
6975
}
7076

77+
//317 LAB - we did not modify this function.
7178
void SystemCoreClockUpdate( void )
7279
{
7380
/* Determine clock frequency according to clock register values */

0 commit comments

Comments
 (0)