Oliver Keller
/
Nucleo_timer_test
timer tests with the STM32F303K8 nucleo board
Embed:
(wiki syntax)
Show/hide line numbers
main.cpp
00001 #include "mbed.h" 00002 00003 Timer t; 00004 int rise_time = 0; 00005 int fall_time = 0; 00006 bool new_rise = false; 00007 bool new_fall = false; 00008 00009 void pin_up(){ 00010 rise_time=t.read_us(); 00011 new_rise=true; 00012 } 00013 00014 void pin_down(){ 00015 fall_time=t.read_us(); 00016 new_fall=true; 00017 } 00018 00019 Serial pc(USBTX, USBRX); 00020 00021 int main() { 00022 pc.baud(230400); 00023 t.start(); 00024 InterruptIn _interrupt(D1); 00025 _interrupt.rise(&pin_up); 00026 _interrupt.fall(&pin_down); 00027 pc.printf("Hello World!"); 00028 while(1) { 00029 if(new_rise && new_fall) { 00030 pc.printf("%d\n\r", fall_time - rise_time); 00031 new_rise=false; 00032 new_fall=false; 00033 } 00034 } 00035 }
Generated on Sat Aug 6 2022 20:42:46 by 1.7.2