Compare commits
3 commits
92e1128e5a
...
081baecac9
Author | SHA1 | Date | |
---|---|---|---|
![]() |
081baecac9 | ||
![]() |
1a1d72be7e | ||
![]() |
ad661c5c03 |
4 changed files with 110 additions and 24 deletions
77
frequency.c
Normal file
77
frequency.c
Normal file
|
@ -0,0 +1,77 @@
|
|||
#include <stdint.h>
|
||||
#include <stdbool.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 "frequency.h"
|
||||
|
||||
// start a pwm test signal
|
||||
void start_signal() {
|
||||
// configure M0PWM2, at GPIO PF2, BoosterPack 1 header C1 pin 2
|
||||
SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOF);
|
||||
GPIOPinTypePWM(GPIO_PORTF_BASE, GPIO_PIN_2 | GPIO_PIN_3);
|
||||
GPIOPinConfigure(GPIO_PF2_M0PWM2);
|
||||
GPIOPinConfigure(GPIO_PF3_M0PWM3);
|
||||
GPIOPadConfigSet(GPIO_PORTF_BASE, GPIO_PIN_2 | GPIO_PIN_3, GPIO_STRENGTH_2MA,
|
||||
GPIO_PIN_TYPE_STD);
|
||||
// configure the PWM0 peripheral, gen 1, outputs 2 and 3
|
||||
SysCtlPeripheralEnable(SYSCTL_PERIPH_PWM0);
|
||||
// use system clock without division
|
||||
PWMClockSet(PWM0_BASE, PWM_SYSCLK_DIV_1);
|
||||
PWMGenConfigure(PWM0_BASE, PWM_GEN_1,
|
||||
PWM_GEN_MODE_DOWN | PWM_GEN_MODE_NO_SYNC);
|
||||
gPWMPeriod = roundf((float)gSystemClock / PWM_FREQUENCY);
|
||||
set_pwm_period(gPWMPeriod);
|
||||
PWMOutputState(PWM0_BASE, PWM_OUT_2_BIT | PWM_OUT_3_BIT, true);
|
||||
PWMGenEnable(PWM0_BASE, PWM_GEN_1);
|
||||
}
|
||||
|
||||
void set_pwm_period(uint32_t period) {
|
||||
PWMGenPeriodSet(PWM0_BASE, PWM_GEN_1,
|
||||
gPWMPeriod);
|
||||
PWMPulseWidthSet(PWM0_BASE, PWM_OUT_2,
|
||||
roundf((float)gPWMPeriod * 0.4f));
|
||||
PWMPulseWidthSet(PWM0_BASE, PWM_OUT_3,
|
||||
roundf((float)gPWMPeriod * 0.4f));
|
||||
}
|
||||
|
||||
|
||||
|
||||
void start_frequency_scan() {
|
||||
// config GPIO PD0 as timer input T0CCP0 at BoosterPack Connector #1 pin 14
|
||||
SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOD);
|
||||
GPIOPinTypeTimer(GPIO_PORTD_BASE, GPIO_PIN_0);
|
||||
GPIOPinConfigure(GPIO_PD0_T0CCP0);
|
||||
SysCtlPeripheralEnable(SYSCTL_PERIPH_TIMER0);
|
||||
TimerDisable(TIMER0_BASE, TIMER_BOTH);
|
||||
TimerConfigure(TIMER0_BASE, TIMER_CFG_SPLIT_PAIR | TIMER_CFG_A_CAP_TIME_UP);
|
||||
TimerControlEvent(TIMER0_BASE, TIMER_A, TIMER_EVENT_POS_EDGE);
|
||||
// use maximum load value
|
||||
TimerLoadSet(TIMER0_BASE, TIMER_A, 0xffff);
|
||||
// use maximum prescale value
|
||||
TimerPrescaleSet(TIMER0_BASE, TIMER_A, 0xff);
|
||||
TimerIntEnable(TIMER0_BASE, TIMER_CAPA_EVENT);
|
||||
TimerEnable(TIMER0_BASE, TIMER_A);
|
||||
}
|
||||
|
||||
uint32_t previous;
|
||||
void capture_handler() {
|
||||
TimerIntClear(TIMER0_BASE, TIMER_CAPA_EVENT);
|
||||
|
||||
uint32_t current = TimerValueGet(TIMER0_BASE, TIMER_A);
|
||||
|
||||
uint32_t delta = current - previous;
|
||||
gPeriod = delta;
|
||||
|
||||
previous = current;
|
||||
}
|
12
frequency.h
Normal file
12
frequency.h
Normal file
|
@ -0,0 +1,12 @@
|
|||
#ifndef FREQUENCY_C
|
||||
#define FREQUENCY_C
|
||||
#define gSystemClock 120000000 // [Hz] system clock frequency
|
||||
|
||||
#define PWM_FREQUENCY 20000 // PWM frequency = 20 kHz
|
||||
|
||||
void start_frequency_scan(void);
|
||||
void set_pwm_period(uint32_t period);
|
||||
|
||||
uint32_t gPeriod;
|
||||
uint32_t gPWMPeriod;
|
||||
#endif
|
39
main.c
39
main.c
|
@ -31,12 +31,11 @@
|
|||
#include "driverlib/pin_map.h"
|
||||
#include "sampling.h"
|
||||
#include "buttons.h"
|
||||
#include "frequency.h"
|
||||
#include "kiss_fft.h"
|
||||
#include "_kiss_fft_guts.h"
|
||||
|
||||
#define PWM_FREQUENCY 20000 // PWM frequency = 20 kHz
|
||||
|
||||
uint32_t gSystemClock = 120000000; // [Hz] system clock frequency
|
||||
|
||||
#define PI 3.14159265358979f
|
||||
|
||||
|
@ -92,27 +91,7 @@ const float gVoltageScale[VOLTAGE_SCALES] = {
|
|||
|
||||
int Trigger(bool rising);
|
||||
|
||||
// start a pwm test signal
|
||||
void start_signal() {
|
||||
// configure M0PWM2, at GPIO PF2, BoosterPack 1 header C1 pin 2
|
||||
SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOF);
|
||||
GPIOPinTypePWM(GPIO_PORTF_BASE, GPIO_PIN_2);
|
||||
GPIOPinConfigure(GPIO_PF2_M0PWM2);
|
||||
GPIOPadConfigSet(GPIO_PORTF_BASE, GPIO_PIN_2, GPIO_STRENGTH_2MA,
|
||||
GPIO_PIN_TYPE_STD);
|
||||
// configure the PWM0 peripheral, gen 1, outputs 2 and 3
|
||||
SysCtlPeripheralEnable(SYSCTL_PERIPH_PWM0);
|
||||
// use system clock without division
|
||||
PWMClockSet(PWM0_BASE, PWM_SYSCLK_DIV_1);
|
||||
PWMGenConfigure(PWM0_BASE, PWM_GEN_1,
|
||||
PWM_GEN_MODE_DOWN | PWM_GEN_MODE_NO_SYNC);
|
||||
PWMGenPeriodSet(PWM0_BASE, PWM_GEN_1,
|
||||
roundf((float)gSystemClock / PWM_FREQUENCY));
|
||||
PWMPulseWidthSet(PWM0_BASE, PWM_OUT_2,
|
||||
roundf((float)gSystemClock / PWM_FREQUENCY * 0.4f));
|
||||
PWMOutputState(PWM0_BASE, PWM_OUT_2_BIT, true);
|
||||
PWMGenEnable(PWM0_BASE, PWM_GEN_1);
|
||||
}
|
||||
|
||||
|
||||
uint32_t cpu_load_count(void)
|
||||
{
|
||||
|
@ -146,6 +125,7 @@ int main(void)
|
|||
start_sampler();
|
||||
ButtonInit();
|
||||
start_cputimer();
|
||||
start_frequency_scan();
|
||||
|
||||
Crystalfontz128x128_Init(); // Initialize the LCD display driver
|
||||
Crystalfontz128x128_SetOrientation(LCD_ORIENTATION_UP); // set screen orientation
|
||||
|
@ -269,6 +249,12 @@ void handle_user_input() {
|
|||
case Down: // previous scale
|
||||
local_options.voltage_scale = (local_options.voltage_scale + VOLTAGE_SCALES - 1) % VOLTAGE_SCALES;
|
||||
break;
|
||||
case SW1:
|
||||
set_pwm_period(++gPWMPeriod);
|
||||
break;
|
||||
case SW2:
|
||||
set_pwm_period(--gPWMPeriod);
|
||||
break;
|
||||
}
|
||||
|
||||
Semaphore_pend(options_sem, BIOS_WAIT_FOREVER);
|
||||
|
@ -315,7 +301,14 @@ void display_waveform(UArg arg1, UArg arg2)
|
|||
GrContextForegroundSet(&sContext, ClrWheat);
|
||||
|
||||
snprintf(str, sizeof(str), "CPU Load %.1f%%", usage_percent);
|
||||
GrStringDraw(&sContext, str, /*length*/ -1, /*x*/ 0, /*y*/ HEIGHT - 30, /*opaque*/ false);
|
||||
|
||||
uint32_t period = gPeriod;
|
||||
float frequency = (float) gSystemClock / (float) period;
|
||||
snprintf(str, sizeof(str), "f = %.1fhz", frequency);
|
||||
GrStringDraw(&sContext, str, /*length*/ -1, /*x*/ 0, /*y*/ HEIGHT - 10, /*opaque*/ false);
|
||||
snprintf(str, sizeof(str), "T = %dc", period);
|
||||
GrStringDraw(&sContext, str, /*length*/ -1, /*x*/ 0, /*y*/ HEIGHT - 20, /*opaque*/ false);
|
||||
|
||||
|
||||
if (local_options.fft) {
|
||||
|
|
6
rtos.cfg
6
rtos.cfg
|
@ -535,7 +535,7 @@ var driversConfig = xdc.useModule('ti.drivers.Config');
|
|||
* Use TI-RTOS drivers library for debugging with asserts and logs enabled.
|
||||
*/
|
||||
driversConfig.libType = driversConfig.LibType_NonInstrumented;
|
||||
Clock.timerId = 0;
|
||||
Clock.timerId = 2;
|
||||
TimestampProvider.useClockTimer = true;
|
||||
var m3Hwi0Params = new m3Hwi.Params();
|
||||
m3Hwi0Params.instance.name = "m3Hwi0";
|
||||
|
@ -597,3 +597,7 @@ Program.global.options_sem = Semaphore.create(1, semaphore4Params);
|
|||
var gateHwi0Params = new GateHwi.Params();
|
||||
gateHwi0Params.instance.name = "gateHwiDMA";
|
||||
Program.global.gateHwi0 = GateHwi.create(gateHwi0Params);
|
||||
var m3Hwi1Params = new m3Hwi.Params();
|
||||
m3Hwi1Params.instance.name = "m3Hwi1";
|
||||
m3Hwi1Params.priority = 4;
|
||||
Program.global.m3Hwi1 = m3Hwi.create(35, "&capture_handler", m3Hwi1Params);
|
||||
|
|
Loading…
Reference in a new issue