![]() |
Lab 4
Code for ECE 474 lab4
|
Code for Task RT-3+4. More...
#include <arduinoFFT.h>
#include <Arduino_FreeRTOS.h>
#include "queue.h"
Macros | |
#define | RAND_SIZE 128 |
Size of the random array size. More... | |
#define | TIME_SIZE 5 |
Size of the size of the time array. More... | |
#define | STACK_SMALL 128 |
Size of the stack size 1. More... | |
#define | RAND_MIN -32000 |
Minimum number for creating a random number. More... | |
#define | RAND_MAX 32000 |
Maximum number for creating a random number. More... | |
Functions | |
void | RT3p0 (void *pvParameters) |
Function to run task RT3p0. More... | |
void | RT3p1 (void *pvParameters) |
Function to run task RT3p1. More... | |
void | RT4 (void *pvParameters) |
Function to run task RT-4. More... | |
void | setup () |
Funciton to setup RtOS tasks. More... | |
void | loop () |
Variables | |
arduinoFFT | FFT = arduinoFFT() |
Create FFT object. More... | |
const double | signalFrequency = 1000 |
frequency (Hz) of the FFT signal More... | |
const double | samplingFrequency = 5000 |
frequency (Hz) of the FFT sample More... | |
const uint8_t | amplitude = 100 |
amplitude of the FFT signal More... | |
const uint16_t | samples = RAND_SIZE |
numbers of samples for the FFT More... | |
double | vReal [samples] |
sample arrays real part More... | |
double | vImag [samples] |
sample arrays imaginary part More... | |
double | rand_array [RAND_SIZE] |
random array RT-3 sent to More... | |
double | store_rand [RAND_SIZE] |
random array RT-4 received from More... | |
unsigned long | time_array [TIME_SIZE] |
time array that each FFT takes to compute that RT-4 will sent back More... | |
unsigned long | store_time [TIME_SIZE] |
time array that each FFT takes to compute that RT-3 will receive once RT-4 sent back More... | |
unsigned long | start_time |
time indicator that the FFTs started to compute More... | |
unsigned long | end_time |
time indicator that the FFTs completed to compute More... | |
unsigned long | duration |
time indicator that each FFT takes to compute More... | |
QueueHandle_t | xQueue1 |
FreeRTOS Queue for RT3p0. More... | |
QueueHandle_t | xQueue2 |
FreeRTOS Queue shared between RT-3 and 4. More... | |
Code for Task RT-3+4.
The program to use FreeRTOS library to generates an array of N pseudo-random 16-bit ints doubles and initializes a FreeRTOS Queue. The it will have the queue to sent and recive data between task RT-3 and 4, which does the following invovlving FFT :
#define RAND_MAX 32000 |
Maximum number for creating a random number.
#define RAND_MIN -32000 |
Minimum number for creating a random number.
#define RAND_SIZE 128 |
Size of the random array size.
#define STACK_SMALL 128 |
Size of the stack size 1.
#define TIME_SIZE 5 |
Size of the size of the time array.
void loop | ( | ) |
void RT3p0 | ( | void * | pvParameters | ) |
Function to run task RT3p0.
This task would create a RAND_SIZE
number random array in rand_array
. Then it will use FreeRTOS xQueueCreate
function. to create a queue on xQueue1
. It then uses FreeRTOS's xTaskCreate()
function to create task RT3p1
's function and then stop itself using vTaskSuspend
pvParameters | parameters that FreeRTOS can pass in |
void RT3p1 | ( | void * | pvParameters | ) |
Function to run task RT3p1.
This task would sent back rand_array
pointer to the data into xQueue1
using the FreeRTOS xQueueSendToBack()
function. in a loop that repeats TIME_SIZE
times then it will use xQueueReceive()
to receive store_time
pointer with portMAX_DELAY
delay to back and wait. Then it use serial to print out the the time to compute FFT in another loop that repeats TIME_SIZE
times
pvParameters | parameters that FreeRTOS can pass in |
void RT4 | ( | void * | pvParameters | ) |
Function to run task RT-4.
This task first stores the time it started each loop in start_time
. It will recieve the store_rand
pointer from xQueue1
using the xQueueReceive()
function. It then loop samples
of times to fill the vReal
and vImag
part of the FFT and compute the ramdom buffer. It recorde another time mark end_time
and using the difference between start_time
and end_time
to compute amount of time it took to compute th FFT and store this value into duration
. It put each of such variable into time_array
and report its pointer back to xQueue2
using xQueueSendToBack()
pvParameters | parameters that FreeRTOS can pass in |
void setup | ( | ) |
Funciton to setup RtOS tasks.
Setup serial communication method and creat RTOS tasks. Set the priority of each task as well as its size.
const uint8_t amplitude = 100 |
amplitude of the FFT signal
unsigned long duration |
time indicator that each FFT takes to compute
unsigned long end_time |
time indicator that the FFTs completed to compute
arduinoFFT FFT = arduinoFFT() |
Create FFT object.
double rand_array[RAND_SIZE] |
random array RT-3 sent to
const uint16_t samples = RAND_SIZE |
numbers of samples for the FFT
const double samplingFrequency = 5000 |
frequency (Hz) of the FFT sample
const double signalFrequency = 1000 |
frequency (Hz) of the FFT signal
unsigned long start_time |
time indicator that the FFTs started to compute
double store_rand[RAND_SIZE] |
random array RT-4 received from
unsigned long store_time[TIME_SIZE] |
time array that each FFT takes to compute that RT-3 will receive once RT-4 sent back
unsigned long time_array[TIME_SIZE] |
time array that each FFT takes to compute that RT-4 will sent back
double vImag[samples] |
sample arrays imaginary part
double vReal[samples] |
sample arrays real part
QueueHandle_t xQueue1 |
FreeRTOS Queue for RT3p0.
QueueHandle_t xQueue2 |
FreeRTOS Queue shared between RT-3 and 4.