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 Servo LM75B C12832_lcd
Revision 0:c56707c70c71, committed 2019-05-28
- Comitter:
- qosay147
- Date:
- Tue May 28 11:43:01 2019 +0000
- Commit message:
- Reading frequency from mains at a very fast rate and displaying on PC.
Changed in this revision
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/C12832_lcd.lib Tue May 28 11:43:01 2019 +0000 @@ -0,0 +1,1 @@ +http://mbed.org/users/dreschpe/code/C12832_lcd/#8f86576007d6
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/LM75B.lib Tue May 28 11:43:01 2019 +0000 @@ -0,0 +1,1 @@ +http://developer.mbed.org/users/chris/code/LM75B/#6a70c9303bbe
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Servo.lib Tue May 28 11:43:01 2019 +0000 @@ -0,0 +1,1 @@ +http://mbed.org/users/simon/code/Servo/#36b69a7ced07
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/main.cpp Tue May 28 11:43:01 2019 +0000
@@ -0,0 +1,53 @@
+ //This code is for 8Vpp or amplitude of 4V when connected to mbed
+
+#include "mbed.h"
+#include "C12832_lcd.h"
+#include <complex>
+#include "Servo.h"
+
+C12832_LCD lcd;
+AnalogIn VIN(A2);
+Servo s1(p22);
+Servo s2(p23);
+Serial pc(USBTX, USBRX); // see how to use this to print off to PC
+
+float y;
+float f;
+int counter = 1;
+Timer t;
+
+int main()
+{ //open1
+ lcd.printf("STARTING! \n") ;
+ while(1) //Repeat process loop
+ { //open2
+ counter = 1; // resets counter back to 1 every time frequency has been read
+ t.reset(); // reset timer every time the frequency has been read out
+ while (counter < 22) // while loop counts for 21 hits on peak point
+ { //open3
+ float V = 3.2 * VIN.read(); // Converting the Voltage input to a higher decimal for more accurate readings. Check if needed by dividing the next if statement by 3.2...
+ if( V >= 0.9&& V <= 1.1) // Checks when the voltage on the sinusoidal input is at a given range to measure time taken for certain amount of hitpoints to calculate frequency...
+ { //open4
+ lcd.printf("V = %2.4f Counter is : %d \n", V, counter) ; // just a checking for myself to ensure counter is working, Will be taken out because unnecessary reading...
+ if (counter == 1) //when counter is equal to 1 and the previous if statement is correct then will start the timer once, until counter is < 21
+ { //open5
+ t.start();
+ } //close5
+ counter++; // adds to counter 1, everytime the while loop has been gone through
+ } //close4
+ } //close3
+ t.stop(); // Timer stops when the counter loop is finished
+ y = t.read()/10.01 ; // averaging the time it has taken to take
+ f = ((1/y)+0.013);
+ lcd.cls();
+ //lcd.printf("time taken is : %3.4f sec \n", t.read()) ;
+ lcd.printf(" %3.3f Hz \n", f) ; // print frequency reading to 3 decimal places
+
+s1 = ((1*f)- 49.5) ;
+s2 = ((1*f)- 49.45);
+//s2 = 0.5;
+ // No need for this when printing off on computer screen
+ pc.printf("$%d %d;", f, y); // SEE HOW TO USE THIS TO PRINT OFF FREQUENCY READING TO PC
+ wait_ms(2000);
+ } //close2
+} //close1
\ No newline at end of file
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/mbed.bld Tue May 28 11:43:01 2019 +0000 @@ -0,0 +1,1 @@ +https://os.mbed.com/users/mbed_official/code/mbed/builds/e7ca05fa8600 \ No newline at end of file