Compare commits
4 commits
b73ed71bc2
...
852f78b4fe
Author | SHA1 | Date | |
---|---|---|---|
852f78b4fe | |||
6bfbf2366b | |||
c2a0fdd210 | |||
fa95b4a93a |
4 changed files with 82 additions and 11 deletions
|
@ -28,6 +28,7 @@ uint32_t gADCSamplingRate; // [Hz] actual ADC sampling rate
|
|||
// imported globals
|
||||
extern uint32_t gSystemClock; // [Hz] system clock frequency
|
||||
extern volatile uint32_t gTime; // time in hundredths of a second
|
||||
extern volatile uint8_t drawRequested;
|
||||
|
||||
// initialize all button and joystick handling hardware
|
||||
void ButtonInit(void)
|
||||
|
@ -189,6 +190,9 @@ void ButtonISR(void) {
|
|||
if (presses & 2) { // EK-TM4C1294XL button 2 pressed
|
||||
gTime = 0;
|
||||
}
|
||||
if (presses & 4) { // boosterpack button 1 pressed
|
||||
drawRequested = 1;
|
||||
}
|
||||
if (running) {
|
||||
if (tic) gTime++; // increment time every other ISR call
|
||||
tic = !tic;
|
||||
|
|
74
main.c
74
main.c
|
@ -15,17 +15,20 @@
|
|||
#include "driverlib/interrupt.h"
|
||||
#include "Crystalfontz128x128_ST7735.h"
|
||||
#include <stdio.h>
|
||||
#include "buttons.h"
|
||||
#include "sampling.h"
|
||||
#include "grlib/grlib.h"
|
||||
#include <math.h>
|
||||
#include <string.h>
|
||||
#include "inc/hw_memmap.h"
|
||||
#include "driverlib/gpio.h"
|
||||
#include "driverlib/pwm.h"
|
||||
#include "driverlib/pin_map.h"
|
||||
#include "sampling.h"
|
||||
#include "buttons.h"
|
||||
#define PWM_FREQUENCY 20000 // PWM frequency = 20 kHz
|
||||
|
||||
uint32_t gSystemClock; // [Hz] system clock frequency
|
||||
volatile uint32_t gTime = 0; // time in hundredths of a second
|
||||
volatile uint8_t drawRequested = 1;
|
||||
|
||||
// start a pwm test signal
|
||||
void start_signal() {
|
||||
|
@ -52,16 +55,14 @@ void start_signal() {
|
|||
int main(void) {
|
||||
IntMasterDisable();
|
||||
|
||||
start_signal();
|
||||
|
||||
start_sampler();
|
||||
|
||||
// Enable the Floating Point Unit, and permit ISRs to use it
|
||||
FPUEnable();
|
||||
FPULazyStackingEnable();
|
||||
|
||||
// Initialize the system clock to 120 MHz
|
||||
gSystemClock = SysCtlClockFreqSet(SYSCTL_XTAL_25MHZ | SYSCTL_OSC_MAIN | SYSCTL_USE_PLL | SYSCTL_CFG_VCO_480, 120000000);
|
||||
start_signal();
|
||||
start_sampler();
|
||||
|
||||
Crystalfontz128x128_Init(); // Initialize the LCD display driver
|
||||
Crystalfontz128x128_SetOrientation(LCD_ORIENTATION_UP); // set screen orientation
|
||||
|
@ -81,6 +82,66 @@ int main(void) {
|
|||
while (true) {
|
||||
GrContextForegroundSet(&sContext, ClrBlack);
|
||||
GrRectFill(&sContext, &rectFullScreen); // fill screen with black
|
||||
|
||||
// assumming square lcd
|
||||
#define HEIGHT LCD_VERTICAL_MAX
|
||||
#define PIXELS_PER_DIV 20
|
||||
|
||||
GrContextForegroundSet(&sContext, ClrBlue);
|
||||
|
||||
// draw gridlines from the center out
|
||||
uint8_t xy_pos;
|
||||
for (xy_pos = HEIGHT/2; xy_pos < HEIGHT; xy_pos += PIXELS_PER_DIV) {
|
||||
GrLineDrawV(&sContext, xy_pos, 0, 128); // right
|
||||
GrLineDrawV(&sContext, HEIGHT - xy_pos, 0, 128); // left
|
||||
|
||||
GrLineDrawH(&sContext, 0, 128, xy_pos); // down
|
||||
GrLineDrawH(&sContext, 0, 128, HEIGHT - xy_pos); // up
|
||||
}
|
||||
|
||||
|
||||
// display graph
|
||||
#define LOCAL_BUF_LEN 128
|
||||
uint16_t local_adc_buffer[LOCAL_BUF_LEN]; // copy of adc buffer
|
||||
int32_t adc_current_index;
|
||||
int32_t j;
|
||||
if (drawRequested) {
|
||||
IntMasterDisable(); // critical section
|
||||
adc_current_index = gADCBufferIndex - 128;
|
||||
for (j=0; j<LOCAL_BUF_LEN; j++) {
|
||||
local_adc_buffer[j] = gADCBuffer[ADC_BUFFER_WRAP(adc_current_index + j)];
|
||||
}
|
||||
IntMasterEnable();
|
||||
drawRequested = 0;
|
||||
}
|
||||
|
||||
GrContextForegroundSet(&sContext, ClrPink);
|
||||
for(j=0; j<LOCAL_BUF_LEN; j++) {
|
||||
#define TRANSPOSE(x) (HEIGHT/2) - (x >> 6) // reduce from twelve to six bits, then flip and center
|
||||
uint32_t upper,lower, current, last;
|
||||
|
||||
if (j==0) {
|
||||
upper = TRANSPOSE(local_adc_buffer[j]);
|
||||
lower = upper;
|
||||
last = upper;
|
||||
} else {
|
||||
current = TRANSPOSE(local_adc_buffer[j]);
|
||||
|
||||
// couldn't find these anywhere
|
||||
#define MIN(a,b) (((a)<(b))?(a):(b))
|
||||
#define MAX(a,b) (((a)>(b))?(a):(b))
|
||||
|
||||
upper = MAX(current, last);
|
||||
lower = MIN(current, last);
|
||||
|
||||
last = current;
|
||||
}
|
||||
|
||||
GrLineDrawV(&sContext, j, lower, upper);
|
||||
}
|
||||
|
||||
#ifdef DISPLAY_TIME
|
||||
// display time
|
||||
time = gTime; // read shared global only once
|
||||
|
||||
uint32_t hundredths = time % 100;
|
||||
|
@ -107,6 +168,7 @@ int main(void) {
|
|||
offset += 10;
|
||||
buttons >>= 1;
|
||||
}
|
||||
#endif // DISPLAY_TIME
|
||||
|
||||
GrFlush(&sContext); // flush the frame buffer to the LCD
|
||||
}
|
||||
|
|
|
@ -13,12 +13,7 @@
|
|||
#include "buttons.h"
|
||||
#include "sampling.h"
|
||||
|
||||
// index wrapping macro
|
||||
#define ADC_BUFFER_WRAP(i) ((i) & (ADC_BUFFER_SIZE - 1))
|
||||
// latest sample index
|
||||
volatile int32_t gADCBufferIndex = ADC_BUFFER_SIZE - 1;
|
||||
volatile uint16_t gADCBuffer[ADC_BUFFER_SIZE]; // circular buffer
|
||||
volatile uint32_t gADCErrors = 0; // number of missed ADC deadlines
|
||||
void ADC_ISR(void)
|
||||
{
|
||||
// clear ADC1 sequence0 interrupt flag in the ADCISC register
|
||||
|
@ -37,6 +32,9 @@ void ADC_ISR(void)
|
|||
|
||||
|
||||
void start_sampler() {
|
||||
gADCBufferIndex = ADC_BUFFER_SIZE - 1;
|
||||
gADCErrors = 0;
|
||||
|
||||
SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOE);
|
||||
GPIOPinTypeADC(GPIO_PORTE_BASE,
|
||||
GPIO_PIN_0); // GPIO setup for analog input AIN3
|
||||
|
|
|
@ -5,6 +5,13 @@
|
|||
|
||||
#define ADC_BUFFER_SIZE 2048 // size must be a power of 2
|
||||
|
||||
// index wrapping macro
|
||||
#define ADC_BUFFER_WRAP(i) ((i) & (ADC_BUFFER_SIZE - 1))
|
||||
|
||||
volatile int32_t gADCBufferIndex;
|
||||
volatile uint16_t gADCBuffer[ADC_BUFFER_SIZE]; // circular buffer
|
||||
volatile uint32_t gADCErrors; // number of missed ADC deadlines
|
||||
|
||||
// initialize ADC and ISR
|
||||
void start_sampler(void);
|
||||
|
||||
|
|
Loading…
Reference in a new issue