Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
b3eaa57
EHL-1 #time 4h Messed with the build system until test file built
wmpmiles Jun 23, 2018
a4feec8
EHL-2 Initial commit #time 3hr finished common i2c interface and si7021
burrrrrr Jul 5, 2018
807c13d
EHL-2 Added libraries #time 2hr ported arduino libraries for lis3mdl …
burrrrrr Jul 6, 2018
7be4c78
EHL-2 #time 30min hx711 library and cleaned up bugs
burrrrrr Jul 13, 2018
ea32507
EHL-2 #time 10min Added makefile
burrrrrr Jul 14, 2018
22205f3
EHL-2 #time 2hr Added science module
burrrrrr Jul 21, 2018
020ea31
Merge branch 'master' into EHL-2-I2C-Library
burrrrrr Jul 21, 2018
a885a54
EHL-2 #time 20m Fixed compile errors
burrrrrr Jul 23, 2018
75ac603
EHL-2 #time 1m Re-added some headers as uppercase
burrrrrr Jul 24, 2018
728f557
EHL-2 #time 5m Modified CMakeLists
Jul 28, 2018
00bc5bf
EHL-2 #time 2h Science library now working
burrrrrr Aug 8, 2018
74175a7
EHL-1 #time 3h debugging, adc working in polling and interrupt mode
burrrrrr Aug 14, 2018
049457d
Merge branch 'EHL-1-adc' into EHL-2-I2C-Library
burrrrrr Aug 27, 2018
cc4c7c4
EHL-2 #time 30m added moisture, weight, multiplexer to test file
burrrrrr Aug 29, 2018
34ac382
EHL-2 #time 5m modified weight sensor sample average
burrrrrr Sep 5, 2018
2953c22
EHL-2 #time 3h Science servo calibrated, added everything to science …
burrrrrr Sep 6, 2018
ab221d8
Increase stack size for good measure
sajidanower23 Sep 12, 2018
3416e3c
Whitespace cleanup
sajidanower23 Sep 12, 2018
2d1ee93
Initialise all sensors on all boards
sajidanower23 Sep 12, 2018
e141f78
Comment in code for testing
sajidanower23 Sep 12, 2018
2fd108d
Ignore editor settings
sajidanower23 Sep 12, 2018
8d581e1
Add in adc sensors
sajidanower23 Sep 12, 2018
f0ee6e6
Fix license header
sajidanower23 Sep 13, 2018
7db9c1b
Change from 4 to 3 modules
sajidanower23 Sep 13, 2018
fd7c697
Style tweaks
sajidanower23 Sep 13, 2018
2b0f083
Use 3 boards instead of 4
sajidanower23 Sep 13, 2018
3a7133f
Add adc_capure_polling back in
sajidanower23 Sep 13, 2018
ebe74ee
Make topic use float64
sajidanower23 Sep 14, 2018
8fa976b
Add dummy data
sajidanower23 Sep 14, 2018
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -189,3 +189,4 @@ venv.bak/

# mypy
.mypy_cache/
.vscode/
22 changes: 22 additions & 0 deletions debug.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
#!/bin/sh

if [ $# -eq 0 ]
then
echo "Usage: sudo $0 <module>"
exit 1
fi

if [ ! `ls elfs | grep "^$1\.elf$"` ]
then
echo "No module called \"$1\""
exit 1
fi

openocd="sudo openocd -f board/ek-tm4c123gxl.cfg"
serial="sleep 1; picocom -b 115200 /dev/ttyACM0"
debug="sleep 2; ./flash.sh elfs/$1.elf"

gnome-terminal --tab --command="bash -c '$openocd; $SHELL'" \
--tab --command="bash -c '$serial; $SHELL'" \
--tab --command="bash -c '$debug; $SHELL'" \
--disable-factory
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

would be better to use something more portable like tmux

21 changes: 21 additions & 0 deletions src/libs/adc/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
project(adc)
cmake_minimum_required(VERSION 3.5)

find_package(catkin REQUIRED
COMPONENTS ti)

catkin_package(
INCLUDE_DIRS ./
LIBRARIES adc
CATKIN_DEPENDS ti
)

set(BUILD_TOOLS_DIR ../../../build-tools)
include(../../../build-tools/build_env.cmake)

add_library(adc STATIC adc.c)
target_include_directories(adc PUBLIC
${CMAKE_INCLUDE_PATH}
./
${catkin_INCLUDE_DIRS}
)
12 changes: 12 additions & 0 deletions src/libs/adc/DESIGNS
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
Initialisation:
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

for all files that are in common please address comments on #12 before merging this (all the adc stuff)

1. Enable ADC clock if not enabled
2. Enable GPIO clock if not enabled
3. Set GPIO AFSEL bit ?
4. Clear GPIO DEN bit in GPIODEN
5. Disable analogue isolation via GPIOAMSEL
6. Disable sample sequencer via ASENn in ADCACTSS
7. Append new source to sequencer via ADCSSCTLn
8. Enable sample sequencer via ASENn in ADCACTSS

Notes
- ADC should use PIOSC for clock at 1 divider for clock
11 changes: 11 additions & 0 deletions src/libs/adc/DIFFERENTIAL_PAIR
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
Differential pair count = 4

When VIN+ == VIN- the output will be 0x800

Pair map
VIND0 <= AIN0 - AIN1
VIND1 <= AIN2 - AIN3
VIND2 <= AIN4 - AIN5
VIND3 <= AIN6 - AIN7


6 changes: 6 additions & 0 deletions src/libs/adc/INTERNAL_TEMP_SENS
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
The internal temperature sensor can be accessed as part of a sample
sequence by setting the relevant TSn bit in ADCSSCTLn register.

The sample can be converted into a temperature with:
TEMP = 147.5 - ((75 * (VREFP - VREFN) × ADC CODE ) / 4096)
Accuracy is +- 5 degrees celsius.
33 changes: 33 additions & 0 deletions src/libs/adc/PIN_DESCRIPTION
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
Pin count = 9

Pin map:
AIN0 => PE3
AIN1 => PE2
AIN2 => PE1
AIN3 => PE0
AIN4 => PD7
AIN5 => PD6
AIN6 => PD5
AIN7 => PD4
AIN20 => PE7

Pin inputs:
GPIO
AIN0
AIN1
AIN2
AIN3
AIN4
AIN5
AIN6
AIN7
AIN20
Filtered input?
AIN0
AIN1
AIN2
AIN3
Current sensor
AIN7
Temperature sensor
AIN20
2 changes: 2 additions & 0 deletions src/libs/adc/VREF
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
VREFA+ => 3V from a precision voltage reference IC
VREFA- => 0V from ground
180 changes: 180 additions & 0 deletions src/libs/adc/adc.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,180 @@
//------------------------------INCLUDES------------------------------//
#include "adc.h"

//---------------------------ERROR_HANDLING---------------------------//

//---------------------------SIZE_CONSTANTS---------------------------//
#define PC 8 /* ADC pin count */
#define GPIO_PORT_COUNT 2 /* number of GPIO ports used by ADC */


//-------------------------------ENUMS--------------------------------//
enum {
PRE_INIT,
POST_INIT
};

//------------------------------STRUCTS-------------------------------//
struct gpio_port {
const uint32_t sysctl;
const uint32_t base;
}; /* struct for data required for manipulating GPIO ports */

struct gpio_pin {
const struct gpio_port port;
const uint8_t pin;
};


//---------------------SHARED_HARDWARE_CONSTANTS----------------------//
/* ADC configuration arguments */
const uint32_t adc_clock_div = 1;
const uint32_t adc_clock_config =
ADC_CLOCK_SRC_PIOSC | ADC_CLOCK_RATE_FULL;
const uint32_t sequence_num = 0;
const uint32_t adc_sc_module = SYSCTL_PERIPH_ADC0;


//----------------------BOARD_SPECIFIC_CONSTANTS----------------------//
#ifdef PART_TM4C123GH6PM
const uint32_t adc_reference = ADC_REF_INT;

const struct gpio_pin gpio_lut[PC] = {
{{SYSCTL_PERIPH_GPIOE, GPIO_PORTE_BASE}, GPIO_PIN_3},
{{SYSCTL_PERIPH_GPIOE, GPIO_PORTE_BASE}, GPIO_PIN_2},
{{SYSCTL_PERIPH_GPIOE, GPIO_PORTE_BASE}, GPIO_PIN_1},
{{SYSCTL_PERIPH_GPIOE, GPIO_PORTE_BASE}, GPIO_PIN_0},
{{SYSCTL_PERIPH_GPIOB, GPIO_PORTB_BASE}, GPIO_PIN_7},
{{SYSCTL_PERIPH_GPIOB, GPIO_PORTB_BASE}, GPIO_PIN_6},
{{SYSCTL_PERIPH_GPIOB, GPIO_PORTB_BASE}, GPIO_PIN_5},
{{SYSCTL_PERIPH_GPIOB, GPIO_PORTB_BASE}, GPIO_PIN_4}};
#endif
#ifdef PART_TM4C123GH6PGE
const uint32_t adc_reference = ADC_REF_EXT_3V;

const struct gpio_pin gpio_lut[PC] = {
{{SYSCTL_PERIPH_GPIOE, GPIO_PORTE_BASE}, GPIO_PIN_3},
{{SYSCTL_PERIPH_GPIOE, GPIO_PORTE_BASE}, GPIO_PIN_2},
{{SYSCTL_PERIPH_GPIOE, GPIO_PORTE_BASE}, GPIO_PIN_1},
{{SYSCTL_PERIPH_GPIOE, GPIO_PORTE_BASE}, GPIO_PIN_0},
{{SYSCTL_PERIPH_GPIOD, GPIO_PORTD_BASE}, GPIO_PIN_7},
{{SYSCTL_PERIPH_GPIOD, GPIO_PORTD_BASE}, GPIO_PIN_6},
{{SYSCTL_PERIPH_GPIOD, GPIO_PORTD_BASE}, GPIO_PIN_5},
{{SYSCTL_PERIPH_GPIOD, GPIO_PORTD_BASE}, GPIO_PIN_4}};
#endif


//------------------------------GLOBALS-------------------------------//
int status = PRE_INIT;
uint8_t active_pins = 0;
uint32_t *adc_buffer = (void *)0;
void (*adc_callback)(void) = (void *)0;


//--------------------------LOCAL_FUNCTIONS---------------------------//
/* If a module is not already enabled: enables it, then waits until it
* is responding as ready. */
void init_module(uint32_t sysctl_module) {
if (SysCtlPeripheralReady(sysctl_module) == false) {
SysCtlPeripheralEnable(sysctl_module);
while (SysCtlPeripheralReady(sysctl_module) == false)
;
}
}


//-------------------------EXTERNAL_FUNCTIONS-------------------------//
/* Interrupt handler that needs to be configured in a module's prx file
* if the interrupt mode is used.
*/
void adc_irq_handler(void) {
/* Clear interrupt flag so we don't instantly return to the handler */
ADCIntClear(ADC0_BASE, sequence_num);
ADCSequenceDataGet(ADC0_BASE, sequence_num, adc_buffer);
/* call the callback */
adc_callback();
}

enum adc_return adc_init_pins(enum adc_pin *pins, uint8_t num_pins, bool interrupt_mode) {
// adc_assert(status == PRE_INIT);
// adc_assert(num_pins < 9);
// adc_assert(pins != (void *)0);

active_pins = num_pins;

/* initialise ADC module */
init_module(adc_sc_module);
ADCIntDisable(ADC0_BASE, sequence_num);

/* configure ADC module */
ADCClockConfigSet(ADC0_BASE, adc_clock_config, adc_clock_div);
ADCReferenceSet(ADC0_BASE, adc_reference);

/* pin initialisation and configuration */
for (int i = 0; i < num_pins; i++) {
/* initialise GPIO module */
init_module(gpio_lut[pins[i]].port.sysctl);
/* configure ADC/GPIO pins */
GPIOPinTypeADC(gpio_lut[pins[i]].port.base, gpio_lut[pins[i]].pin);
}

/* disable before configuring sequencer */
ADCSequenceDisable(ADC0_BASE, sequence_num);

/* setup ADC sample sequencer, trigger manually in software */
ADCSequenceConfigure(ADC0_BASE, sequence_num,
ADC_TRIGGER_PROCESSOR, 0);

/* configure each step of sequence to be an analog input source */
int i = 0;
for (i = 0; i < num_pins-1; i++) {
ADCSequenceStepConfigure(ADC0_BASE, sequence_num, i, pins[i]);
}
/* last step is end of sequence, generate an interrupt here */
ADCSequenceStepConfigure(ADC0_BASE, sequence_num, i,
pins[i] | ADC_CTL_IE | ADC_CTL_END);
/* never use this function, echronos handles irq registration */
// ADCIntRegister(ADC0_BASE, sequence_num, adc_irq_handler);
ADCSequenceEnable(ADC0_BASE, sequence_num);
/* enable interrupts if in interrupt mode */
if (interrupt_mode) {
ADCIntEnable(ADC0_BASE, sequence_num);
IntEnable(INT_ADC0SS0);
}
/* ready for capture */
status = POST_INIT;
return ADC_SUCCESS;
}

enum adc_return adc_capture_interrupt(uint32_t *buffer, void (*callback)(void)) {
// adc_assert(status == POST_INIT);
// adc_assert(buffer != (void *)0);
// adc_assert(callback !=(void *)0);
adc_buffer = buffer;
adc_callback = callback;
ADCProcessorTrigger(ADC0_BASE, sequence_num);
return ADC_SUCCESS;
}



uint32_t adc_capture_polling(uint32_t *buffer) {
// adc_assert(status == POST_INIT);
ADCProcessorTrigger(ADC0_BASE, sequence_num);
while (!ADCIntStatus(ADC0_BASE, sequence_num, false)) {};
uint32_t num_samples = ADCSequenceDataGet(ADC0_BASE, sequence_num, buffer);
return num_samples;
}


enum adc_return adc_interrupt_disable() {
ADCIntDisable(ADC0_BASE, sequence_num);
IntDisable(INT_ADC0SS0);
return ADC_SUCCESS;
}

enum adc_return adc_interrupt_enable() {
ADCIntEnable(ADC0_BASE, sequence_num);
IntEnable(INT_ADC0SS0);
return ADC_SUCCESS;
}
Loading