Hey everyone,

I have a project with a LM555 timer and need to calculate how much time it takes for an input to go from LOW to HIGH and then to LOW again.

Basically, I want to know the period of a square wave generated by the LM555 timer.

I did it with Arduino using the function Pulseln. But I need to do this using a Beaglebone and programming in C++ (Using QtCreator).

I created this code but it is not working:


Qt Code:
  1. #include "mainwindow.h"
  2. #include "ui_mainwindow.h"
  3. #include <QElapsedTimer>
  4. #include "SimpleGPIO.h"
  5.  
  6. MainWindow::MainWindow(QWidget *parent) :
  7. QMainWindow(parent),
  8. ui(new Ui::MainWindow)
  9. {
  10. ui->setupUi(this);
  11. }
  12.  
  13. MainWindow::~MainWindow()
  14. {
  15. delete ui;
  16. }
  17.  
  18. void MainWindow::on_pushButton_clicked()
  19. {
  20.  
  21. QElapsedTimer tempo;
  22. qint64 nanoSeg = 0;
  23. QString seg;
  24.  
  25. unsigned int PINO = 60; // GPIO1_28 = (1x32) + 28 = 60
  26. gpio_export(PINO); // The LED is in pin 60
  27. gpio_set_dir(PINO, INPUT_PIN); // The LED is an INPUT
  28.  
  29. // unsigned int valor = LOW;
  30.  
  31.  
  32.  
  33. if(gpio_get_value(PINO)==HIGH){
  34.  
  35. tempo.start();
  36.  
  37. }
  38.  
  39. while(gpio_get_value(PINO)==HIGH){
  40. ui->textEdit_2->setText("HIGH");
  41. }
  42.  
  43. while(gpio_get_value(PINO)==LOW){
  44.  
  45. }
  46.  
  47. nanoSeg = tempo.nsecsElapsed();
  48.  
  49. seg = QString::number(nanoSeg); // Converte o inteiro 'nanoSeg' em string 'seg'
  50. ui->textEdit->setText(seg);
  51.  
  52. }
To copy to clipboard, switch view to plain text mode 

It compiles alright and when I run it I don't get an error messages, it just crashes.

I have already checked and the libraries are OK. The problem I think is with the while functions. Do you guys have any ideia of what might be the problem?

Thank you in advance.