capture and process waveform
This commit is contained in:
parent
6b16664b22
commit
e1419da297
2 changed files with 143 additions and 0 deletions
114
main.c
114
main.c
|
@ -11,6 +11,7 @@
|
|||
/* BIOS Header files */
|
||||
#include <ti/sysbios/BIOS.h>
|
||||
#include <ti/sysbios/knl/Task.h>
|
||||
#include <ti/sysbios/knl/Semaphore.h>
|
||||
|
||||
#include <stdint.h>
|
||||
#include <stdbool.h>
|
||||
|
@ -33,6 +34,48 @@
|
|||
|
||||
uint32_t gSystemClock = 120000000; // [Hz] system clock frequency
|
||||
|
||||
#define LOCAL_BUF_LEN 128
|
||||
uint16_t adc_buffer_sample[LOCAL_BUF_LEN]; // copy of g adc buffer
|
||||
uint8_t adc_buffer_processed[LOCAL_BUF_LEN]; // copy of g adc buffer
|
||||
|
||||
uint8_t voltage_scale = 4; // 2v
|
||||
uint8_t time_scale = 5; // 20us
|
||||
uint8_t trigger_mode = 1; // rising
|
||||
|
||||
// assuming square lcd
|
||||
#define HEIGHT LCD_VERTICAL_MAX
|
||||
#define WIDTH LCD_HORIZONTAL_MAX
|
||||
#define PIXELS_PER_DIV 20
|
||||
|
||||
#define VIN_RANGE 3.3 // volts
|
||||
#define ADC_BITS 12
|
||||
#define ADC_OFFSET 30
|
||||
|
||||
#define VOLTAGE_SCALES 5
|
||||
const char * const gVoltageScaleStr[VOLTAGE_SCALES] = {
|
||||
"100 mV", "200 mV", "500 mV", " 1 V", " 2 V"
|
||||
};
|
||||
|
||||
const float gVoltageScale[VOLTAGE_SCALES] = {
|
||||
0.1, 0.2, 0.5, 1., 2.
|
||||
};
|
||||
|
||||
#define TIME_SCALES 6
|
||||
const char * const gTimeScaleStr[TIME_SCALES] = {
|
||||
"100 ms", "50 ms", "20 ms", " 10 ms", "50 us", "20 us"
|
||||
};
|
||||
|
||||
const uint64_t gTImeScale[TIME_SCALES] = {
|
||||
100 * 1000 / PIXELS_PER_DIV,
|
||||
50 * 1000 / PIXELS_PER_DIV,
|
||||
20 * 1000 / PIXELS_PER_DIV,
|
||||
10 * 1000 / PIXELS_PER_DIV,
|
||||
50 / PIXELS_PER_DIV,
|
||||
20 / PIXELS_PER_DIV,
|
||||
};
|
||||
|
||||
int Trigger(bool rising);
|
||||
|
||||
// start a pwm test signal
|
||||
void start_signal() {
|
||||
// configure M0PWM2, at GPIO PF2, BoosterPack 1 header C1 pin 2
|
||||
|
@ -80,3 +123,74 @@ void task0_func(UArg arg1, UArg arg2)
|
|||
// do nothing
|
||||
}
|
||||
}
|
||||
|
||||
void capture_waveform(UArg arg1, UArg arg2)
|
||||
{
|
||||
while(true) {
|
||||
Semaphore_pend(capture_sem, BIOS_WAIT_FOREVER);
|
||||
|
||||
int32_t adc_current_index;
|
||||
int32_t j;
|
||||
int trigger;
|
||||
if (trigger_mode == 2) {
|
||||
trigger = gADCBufferIndex - (WIDTH / 2); // show latest if trigger disabled
|
||||
} else {
|
||||
trigger = Trigger(trigger_mode);
|
||||
}
|
||||
|
||||
adc_current_index = trigger - (WIDTH / 2);
|
||||
for (j=0; j<LOCAL_BUF_LEN; j++) {
|
||||
adc_buffer_sample[j] = gADCBuffer[ADC_BUFFER_WRAP(adc_current_index + j)];
|
||||
}
|
||||
|
||||
Semaphore_post(process_sem);
|
||||
}
|
||||
}
|
||||
|
||||
void process_waveform(UArg arg1, UArg arg2) {
|
||||
while(true) {
|
||||
Semaphore_pend(process_sem, BIOS_WAIT_FOREVER);
|
||||
|
||||
float fVoltsPerDiv = gVoltageScale[voltage_scale];
|
||||
float fScale = (VIN_RANGE * PIXELS_PER_DIV)/((1 << ADC_BITS) * fVoltsPerDiv);
|
||||
|
||||
int j;
|
||||
for(j=0; j<LOCAL_BUF_LEN; j++) {
|
||||
#define MIN(a,b) (((a)<(b))?(a):(b))
|
||||
#define MAX(a,b) (((a)>(b))?(a):(b))
|
||||
#define CONSTRAIN(x) MAX(MIN(HEIGHT - 1, x), 0)
|
||||
#define TRANSPOSE(x) CONSTRAIN((HEIGHT/2) - (int)roundf(fScale * ((int)x - ADC_OFFSET)))
|
||||
adc_buffer_processed[j] = TRANSPOSE(adc_buffer_sample[j]);
|
||||
}
|
||||
|
||||
Semaphore_post(display_sem);
|
||||
Semaphore_post(capture_sem);
|
||||
}
|
||||
}
|
||||
|
||||
void display_waveform(UArg arg1, UArg arg2)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
int Trigger(bool rising) // search for edge trigger
|
||||
{
|
||||
int x = gADCBufferIndex - (WIDTH / 2); // half screen width
|
||||
int x_stop = x - ADC_BUFFER_SIZE/2;
|
||||
for (; x > x_stop; x--) {
|
||||
if (rising) {
|
||||
if ( gADCBuffer[ADC_BUFFER_WRAP(x)] >= ADC_OFFSET &&
|
||||
gADCBuffer[ADC_BUFFER_WRAP(x-1)] < ADC_OFFSET) {
|
||||
break;
|
||||
}
|
||||
} else { // falling edge trigger
|
||||
if ( gADCBuffer[ADC_BUFFER_WRAP(x)] <= ADC_OFFSET &&
|
||||
gADCBuffer[ADC_BUFFER_WRAP(x-1)] > ADC_OFFSET) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (x == x_stop) // for loop ran to the end
|
||||
x = gADCBufferIndex - (WIDTH / 2); // reset x back to how it was initialized
|
||||
return x;
|
||||
}
|
||||
|
|
29
rtos.cfg
29
rtos.cfg
|
@ -544,3 +544,32 @@ var m3Hwi0Params = new m3Hwi.Params();
|
|||
m3Hwi0Params.instance.name = "m3Hwi0";
|
||||
m3Hwi0Params.priority = 0;
|
||||
Program.global.m3Hwi0 = m3Hwi.create(62, "&ADC_ISR", m3Hwi0Params);
|
||||
var task1Params = new Task.Params();
|
||||
task1Params.instance.name = "waveform";
|
||||
task1Params.priority = 15;
|
||||
Program.global.waveform = Task.create("&capture_waveform", task1Params);
|
||||
var semaphore0Params = new Semaphore.Params();
|
||||
semaphore0Params.instance.name = "capture_sem";
|
||||
semaphore0Params.mode = Semaphore.Mode_BINARY;
|
||||
Program.global.capture_sem = Semaphore.create(1, semaphore0Params);
|
||||
var semaphore1Params = new Semaphore.Params();
|
||||
semaphore1Params.instance.name = "process_sem";
|
||||
semaphore1Params.mode = Semaphore.Mode_BINARY;
|
||||
Program.global.process_sem = Semaphore.create(null, semaphore1Params);
|
||||
var semaphore2Params = new Semaphore.Params();
|
||||
semaphore2Params.instance.name = "display";
|
||||
Program.global.display = Semaphore.create(null, semaphore2Params);
|
||||
var task2Params = new Task.Params();
|
||||
task2Params.instance.name = "processing";
|
||||
task2Params.stackSize = 1024;
|
||||
task2Params.priority = 2;
|
||||
Program.global.processing = Task.create("&process_waveform", task2Params);
|
||||
var task3Params = new Task.Params();
|
||||
task3Params.instance.name = "display";
|
||||
task3Params.priority = 3;
|
||||
task3Params.stackSize = 1024;
|
||||
Program.global.display = Task.create("&display_waveform", task3Params);
|
||||
var semaphore2Params0 = new Semaphore.Params();
|
||||
semaphore2Params0.instance.name = "display_sem";
|
||||
semaphore2Params0.mode = Semaphore.Mode_BINARY;
|
||||
Program.global.display_sem = Semaphore.create(null, semaphore2Params0);
|
||||
|
|
Loading…
Reference in a new issue