Sz_Insper / Mbed 2 deprecated Leitura_Velocidade_Akyama

Dependencies:   mbed

Files at this revision

API Documentation at this revision

Comitter:
Marcelocostanzo
Date:
Thu Aug 06 16:53:38 2020 +0000
Commit message:
primeira versao

Changed in this revision

main.cpp Show annotated file Show diff for this revision Revisions of this file
mbed.bld Show annotated file Show diff for this revision Revisions of this file
diff -r 000000000000 -r c665d23a7e36 main.cpp
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/main.cpp	Thu Aug 06 16:53:38 2020 +0000
@@ -0,0 +1,64 @@
+/*****************************************************************
+* Projeto para leitura da rotação do motor Akyama ak360/25PL12S3500S
+*
+* 
+*
+* Insper instituto e pesquisa
+*
+* Autor: Marcelo Costanzo Miranda
+* Data: 06/08/2020
+**************************************************************/
+
+#include "mbed.h"
+
+//------------------Pino para o sinal de rotação-----------------------------
+InterruptIn pulse(D7);
+
+//----------------Timers para amostragem ------------------------------------
+Ticker calc_rpm;
+Ticker send_serial;
+
+//----------------Comunicação----------------------------------------
+Serial pc(USBTX, USBRX); // tx, rx
+
+//----------------Variaveis----------------------------------------
+int tooth_counter = 0;
+int RPM = 0;
+//float RPS = 0;
+//float tooth_period = 0;
+
+//----------------Interrupçao de pulso----------------------------------------
+void pulse_read()
+{
+    tooth_counter++;
+}
+
+//----------------Calcula a rotação a 40Hz----------------------------------------
+void rpm_counter()
+{
+    RPM = tooth_counter * 40;
+    //tooth_period = 25000 / tooth_counter;
+    //RPS = RPM / 60;
+    tooth_counter = 0;
+}
+
+//----------------Envia a rotação a 1Hz----------------------------------------
+void send_rpm()
+{
+    pc.printf("%i\r\n",RPM);
+}
+
+int main() 
+{     
+    pc.baud(38400);// ajusta o baudrate
+    
+    pulse.rise(&pulse_read);//habilita a interrupção por borda de subida
+    
+    calc_rpm.attach_us(&rpm_counter, 25000);//habilita a chamada a 40Hz para calculo da rotaçao
+    
+    send_serial.attach(&send_rpm, 1.0f);//habilita a chamada a 1Hz para envio da rotaçao
+
+    while(1) 
+    {
+    }
+}
\ No newline at end of file
diff -r 000000000000 -r c665d23a7e36 mbed.bld
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/mbed.bld	Thu Aug 06 16:53:38 2020 +0000
@@ -0,0 +1,1 @@
+https://os.mbed.com/users/mbed_official/code/mbed/builds/65be27845400
\ No newline at end of file