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
Fork of TAU_ZOOLOG_Chirp_Generator by
Diff: main.cpp
- Revision:
- 21:7aa784deffc8
- Parent:
- 20:048516dc1015
- Child:
- 23:6dbd2d20697c
--- a/main.cpp Tue Mar 27 07:58:22 2018 +0000
+++ b/main.cpp Sun Apr 08 07:40:55 2018 +0000
@@ -14,12 +14,18 @@
*/
#include "mbed.h"
#include "chirp.h"
-#define PULSE_RATE 10.0f // in HZ
+#define PULSE_RATE 20.0f // in HZ
+#define FREQ_POT_EN // Potentiometer to set PULSE Rate
+#define MIN_FREQ 0.5f //(HZ)
+
+float pulseRate=PULSE_RATE;
// Serial over USB as input device
Serial pc(SERIAL_TX, SERIAL_RX);
// mbed variables, Settings
AnalogOut out(PA_4);
+AnalogIn potFreq(A0);
+// Potentiometer analog INPUT
// digital pins
DigitalOut led(LED1);
@@ -68,9 +74,9 @@
while(true) {
if (mybutton.read()==0) { // if button pressed, generate pulse out
led.write(1);
-
+
/////////////////////////////////////////////////////////////////////////////////
- __disable_irq(); // Disable Interrupts
+ __disable_irq(); // Disable Interrupts
// generate chirp out
for (int ii=0; ii<NUM_SAMPLES; ii++) {
// toogle io for loop frequency
@@ -95,15 +101,15 @@
*(__IO uint32_t *) Dac_Reg = (uint16_t)(4095/2);
__enable_irq(); // Enable Interrupts
//////////////////////////////////////////////////////////////////////////////////
-
+
// generate delay between pulses
// delay post pulse // sets the pulse rate
- float waitTime = (1.0f/(2.0f*PULSE_RATE) - (((float)NUM_SAMPLES)/1000000.0f));
+ float waitTime = (1.0f/(2.0f*pulseRate) - (((float)NUM_SAMPLES)/1000000.0f));
if (waitTime > 0) {
led.write(0);
wait(waitTime);
led.write(1);
- wait(1.0f/(2.0f*PULSE_RATE));
+ wait(1.0f/(2.0f*pulseRate));
} else {
wait(0.5);
printf("!!! Error Wait time is negative %f !!!\r\n", waitTime);
@@ -111,6 +117,13 @@
}
} // end button press
led.write(0);
+
+ // update freq based on potentiometer
+#ifdef FREQ_POT_EN
+ pulseRate = potFreq * PULSE_RATE;
+ if (pulseRate < MIN_FREQ) pulseRate = MIN_FREQ;
+ //printf("Pulse Rate %f\r\n", pulseRate);
+#endif
}// end while(True)
}
