Compare commits
2 commits
Author | SHA1 | Date | |
---|---|---|---|
![]() |
ee0ac28714 | ||
![]() |
f9125357d0 |
7 changed files with 1518 additions and 1 deletions
65
audio.c
Normal file
65
audio.c
Normal file
|
@ -0,0 +1,65 @@
|
|||
#include <stdint.h>
|
||||
#include <stdbool.h>
|
||||
#include "driverlib/pwm.h"
|
||||
#include "driverlib/sysctl.h"
|
||||
#include "driverlib/gpio.h"
|
||||
#include "driverlib/timer.h"
|
||||
#include "driverlib/pin_map.h"
|
||||
#include "inc/tm4c1294ncpdt.h"
|
||||
#include "driverlib/interrupt.h"
|
||||
#include "inc/hw_types.h"
|
||||
#include "inc/hw_memmap.h"
|
||||
#include "driverlib/fpu.h"
|
||||
#include <math.h>
|
||||
#include "driverlib/pwm.h"
|
||||
#include <stdlib.h>
|
||||
#include "audio_waveform.h"
|
||||
#include "frequency.h"
|
||||
|
||||
#define AUDIO_PWM_PERIOD 258
|
||||
|
||||
uint32_t gSamplingRateDivider = 29; // sampling rate divider
|
||||
|
||||
void configure_audio() {
|
||||
// configure M0PWM2, at GPIO PF2, BoosterPack 1 header C1 pin 2
|
||||
SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOG);
|
||||
GPIOPinTypePWM(GPIO_PORTG_BASE, GPIO_PIN_1);
|
||||
GPIOPinConfigure(GPIO_PG1_M0PWM5);
|
||||
GPIOPadConfigSet(GPIO_PORTG_BASE, GPIO_PIN_1, GPIO_STRENGTH_2MA,
|
||||
GPIO_PIN_TYPE_STD);
|
||||
// configure the PWM0 peripheral, gen 2, outputs 5
|
||||
SysCtlPeripheralEnable(SYSCTL_PERIPH_PWM0);
|
||||
// use system clock without division
|
||||
PWMClockSet(PWM0_BASE, PWM_SYSCLK_DIV_1);
|
||||
PWMGenConfigure(PWM0_BASE, PWM_GEN_2,
|
||||
PWM_GEN_MODE_DOWN | PWM_GEN_MODE_NO_SYNC);
|
||||
|
||||
PWMGenPeriodSet(PWM0_BASE, PWM_GEN_2,
|
||||
AUDIO_PWM_PERIOD);
|
||||
PWMPulseWidthSet(PWM0_BASE, PWM_OUT_5,
|
||||
roundf((float)AUDIO_PWM_PERIOD * 0.5f));
|
||||
|
||||
gSamplingRateDivider = gSystemClock / AUDIO_PWM_PERIOD / AUDIO_SAMPLING_RATE;
|
||||
|
||||
PWMGenIntTrigEnable(PWM0_BASE, PWM_GEN_2, PWM_INT_CNT_ZERO);
|
||||
|
||||
PWMOutputState(PWM0_BASE, PWM_OUT_5_BIT, true);
|
||||
PWMGenEnable(PWM0_BASE, PWM_GEN_2);
|
||||
}
|
||||
|
||||
uint32_t gPWMSample = 0; // PWM sample counter
|
||||
void PWM_ISR(void)
|
||||
{
|
||||
PWMGenIntClear(PWM0_BASE, PWM_GEN_2, PWM_INT_CNT_ZERO); // clear PWM interrupt flag
|
||||
// waveform sample index
|
||||
int i = (gPWMSample++) / gSamplingRateDivider;
|
||||
// write directly to the PWM compare B register
|
||||
PWM0_2_CMPB_R = 1 + gWaveform[i];
|
||||
if (i > gWaveformSize) { // if at the end of the waveform array
|
||||
// disable these interrupts
|
||||
PWMIntDisable(PWM0_BASE, PWM_INT_GEN_2);
|
||||
// reset sample index so the waveform starts from the beginning
|
||||
gPWMSample = 0;
|
||||
}
|
||||
}
|
||||
|
6
audio.h
Normal file
6
audio.h
Normal file
|
@ -0,0 +1,6 @@
|
|||
#ifndef AUDIO_C
|
||||
#define AUDIO_C
|
||||
|
||||
void configure_audio();
|
||||
|
||||
#endif
|
1418
audio_waveform.c
Normal file
1418
audio_waveform.c
Normal file
File diff suppressed because it is too large
Load diff
17
audio_waveform.h
Normal file
17
audio_waveform.h
Normal file
|
@ -0,0 +1,17 @@
|
|||
/*
|
||||
* audio_waveform.h
|
||||
*
|
||||
* Created on: Apr 15, 2020
|
||||
* Author: Gene Bogdanov
|
||||
*
|
||||
* ECE 3849 Lab 3 Audio Waveform header
|
||||
*/
|
||||
|
||||
#ifndef AUDIO_WAVEFORM_H_
|
||||
#define AUDIO_WAVEFORM_H_
|
||||
|
||||
#define AUDIO_SAMPLING_RATE 16000 // [samples/sec] waveform sampling rate
|
||||
extern const uint8_t gWaveform[]; // waveform array, stored in the flash
|
||||
extern const size_t gWaveformSize; // number of elements in the waveform array
|
||||
|
||||
#endif /* AUDIO_WAVEFORM_H_ */
|
|
@ -4,6 +4,7 @@
|
|||
|
||||
#define PWM_FREQUENCY 20000 // PWM frequency = 20 kHz
|
||||
|
||||
void start_signal(void);
|
||||
void start_frequency_scan(void);
|
||||
void set_pwm_period(uint32_t period);
|
||||
|
||||
|
|
5
main.c
5
main.c
|
@ -32,6 +32,7 @@
|
|||
#include "sampling.h"
|
||||
#include "buttons.h"
|
||||
#include "frequency.h"
|
||||
#include "audio.h"
|
||||
#include "kiss_fft.h"
|
||||
#include "_kiss_fft_guts.h"
|
||||
|
||||
|
@ -126,6 +127,7 @@ int main(void)
|
|||
ButtonInit();
|
||||
start_cputimer();
|
||||
start_frequency_scan();
|
||||
configure_audio();
|
||||
|
||||
Crystalfontz128x128_Init(); // Initialize the LCD display driver
|
||||
Crystalfontz128x128_SetOrientation(LCD_ORIENTATION_UP); // set screen orientation
|
||||
|
@ -255,6 +257,9 @@ void handle_user_input() {
|
|||
case SW2:
|
||||
set_pwm_period(--gPWMPeriod);
|
||||
break;
|
||||
case Right:
|
||||
PWMIntEnable(PWM0_BASE, PWM_INT_GEN_2);
|
||||
break;
|
||||
}
|
||||
|
||||
Semaphore_pend(options_sem, BIOS_WAIT_FOREVER);
|
||||
|
|
7
rtos.cfg
7
rtos.cfg
|
@ -599,5 +599,10 @@ gateHwi0Params.instance.name = "gateHwiDMA";
|
|||
Program.global.gateHwi0 = GateHwi.create(gateHwi0Params);
|
||||
var m3Hwi1Params = new m3Hwi.Params();
|
||||
m3Hwi1Params.instance.name = "m3Hwi1";
|
||||
m3Hwi1Params.priority = 4;
|
||||
m3Hwi1Params.priority = 0;
|
||||
Program.global.m3Hwi1 = m3Hwi.create(35, "&capture_handler", m3Hwi1Params);
|
||||
var m3Hwi2Params = new m3Hwi.Params();
|
||||
m3Hwi2Params.instance.name = "m3Hwi2";
|
||||
m3Hwi2Params.priority = 0;
|
||||
m3Hwi2Params.enableInt = true;
|
||||
Program.global.m3Hwi2 = m3Hwi.create(28, "&PWM_ISR", m3Hwi2Params);
|
||||
|
|
Loading…
Reference in a new issue