PDA

View Full Version : Time from HIGH to LOW



arthuki
27th October 2016, 19:01
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:



#include "mainwindow.h"
#include "ui_mainwindow.h"
#include <QElapsedTimer>
#include "SimpleGPIO.h"

MainWindow::MainWindow(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::MainWindow)
{
ui->setupUi(this);
}

MainWindow::~MainWindow()
{
delete ui;
}

void MainWindow::on_pushButton_clicked()
{

QElapsedTimer tempo;
qint64 nanoSeg = 0;
QString seg;

unsigned int PINO = 60; // GPIO1_28 = (1x32) + 28 = 60
gpio_export(PINO); // The LED is in pin 60
gpio_set_dir(PINO, INPUT_PIN); // The LED is an INPUT

// unsigned int valor = LOW;



if(gpio_get_value(PINO)==HIGH){

tempo.start();

}

while(gpio_get_value(PINO)==HIGH){
ui->textEdit_2->setText("HIGH");
}

while(gpio_get_value(PINO)==LOW){

}

nanoSeg = tempo.nsecsElapsed();

seg = QString::number(nanoSeg); // Converte o inteiro 'nanoSeg' em string 'seg'
ui->textEdit->setText(seg);

}

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.

anda_skoa
27th October 2016, 19:42
You will have to check were it crashes.

One thing that is unrelated to crashing but looks very wrong is the second loop.
If the signal stays at LOW it will never break.

Also be aware that this will block your UI as long as the signal period is.

Cheers,
_