Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependencies: mbed
Diff: main.cpp
- Revision:
- 29:207111ffd6e6
- Parent:
- 27:da783f414f67
- Child:
- 31:cfdb014ff086
--- a/main.cpp Mon May 25 10:46:02 2020 +0000
+++ b/main.cpp Mon May 25 20:00:31 2020 +0000
@@ -8,19 +8,9 @@
Username: el18loc
Student ID Number: 201225242
Start Date: 06/02/2020
-Last Edited: 23/05/2020
+Last Edited: 25/05/2020
*/
-/* TO DO:
-Filter algo
-Wire Amp to Vin
-Sort Squarewave+tri Sound
-Add Menu from front.cpp
-Master Volume
-Possible ADSR bug
-Wiki
-Video
-*/
// Includes
#include "mbed.h"
#include "Gamepad.h"
@@ -40,48 +30,34 @@
startup start;
Ticker tick;
-//DigitalOut rca(PTC4);
-//Serial pc(USBTX, USBRX);
-
//Functions
-//void squareWave();
-//void sinspeak();
void noise_isr();
-
//Global Variables
-volatile extern int g_isr_flag; //may need extern
-
+volatile extern int g_isr_flag; //flag set by ISR for sound
int main()
{
- printf("RUNNING CODE \n");
+ //printf("RUNNING CODE \n");
start.initialise(lcd,pad); //initialises board and displays start screen
-
#ifdef DEBUG
printf("DEBUG COMPILE RUNNING\n");
- run_LUTs_debug();
+ run_LUTs_debug(); //debug value checking function
#endif
-
-#ifdef SLOW_TIME //ATTACH TICKERS FOR SOUND
+#ifdef SLOW_TIME
printf("Running in SLOW_TIME\n");
tick.attach(&noise_isr, 1); //extended for debug (1Hz)
#endif
#ifdef CSV
- printf("Running in SLOW_TIME\n");
- tick.attach_us(&noise_isr, 5000); //extended for debug (1Hz)
-#endif
-#ifndef SLOW_TIME
-#ifndef CSV
- tick.attach_us(&noise_isr, 100); //normal mode SR=10kHz
+ printf("Running CSV\n");
+ tick.attach_us(&noise_isr, 5000); //extended for CV printfs (200Hz)
#endif
+#ifndef SLOW_TIME
+#ifndef CSV //ATTACH TICKERS FOR SOUND
+ tick.attach_us(&noise_isr, 100); //normal mode Fs=10kHz
+#endif
#endif
-
- menu.mainmenu(lcd,pad);
-
-//UNUSED FUNCTIONS:-------------------------------------------------------------
- //squareWave(); //generates pulse wave modulated by sin wave
- //sinspeak();
+ while (1) { menu.mainmenu(lcd,pad); }
}
void noise_isr() {
@@ -91,76 +67,4 @@
}
#endif
g_isr_flag=1;
- }
-
-/*
-void squareWave()
-{
- printf("Generating SIN PWM \n");
-
- int i=0; //int based iterator
- float ifl=0; //float based itterator
- float f=50; //frequency of sin wave produced
- period.attach_us(&up_isr,g_period_us); //ticker to write 1 to rca
- down.attach_us(&down_isr,g_uptime_us); //ticker to write 0 to rca
-
-
- printf("g_period_us: %d \n", g_period_us);
- printf("sin Frequency: %f \n", f);
-
- while (1) { //continual loop for pulse production
- float dutyratio = wavtable[i]; //calcualtes duty ratio of pulse
-
- g_uptime_us= dutyratio*g_period_us; //calculates duty ratio in usecs
- if (g_uptime_us<1) {
- g_uptime_us=g_period_us/100;
- } //sets to be value for timebeing to eliminate 0 error
- //float f=440*(pad.read_pot1()+1); //removed for simplification
-
- if (g_upflag==0) {
-
- ifl = ifl + (4096*f*g_period); //once rca=1 itterate sin function
- if (ifl>4096) {
- ifl= ifl-4096;
- }
- i=ifl;
-
- g_upflag=1; //reset flag
- //printf("iterate i: i= %d, ifl= %f \n", i, ifl);
- }
-
- //printf("DR: %f \n",dutyratio);
- //printf("sleep \n");
- sleep(); //sleeps till next isr
- }
-}
-
-void sinspeak ()
-{
- float f1=440.0;
- float i=0;
- unsigned short v=0;
- int inc=0;
- pad.reset_buttons();
- f1 = pad.read_pot1();
- f1 = 440.0f+440.0f*f1;
- //printf("f1= %f \n",f1); // Used for Debug
-
- while (inc<3000) {
- int inti = i;
- v = o[inti];
- printf("OUTPUT: %u \n", v);
- //pad.write_u16(v);
- wait_us(230); //fs= 4k Ts=250us
-
- i = i + ((4096.0f*f1)/4000.0f); //i+((samples*f)*Ts)
- if (i>=4096.0f) {
- i=i-4096.0f;
- }
- else {
- wait_us(3); // used to attempt note stabilisation to match other loop
- }
- inc++;
- }
-}
-*/
\ No newline at end of file
+ }
\ No newline at end of file