Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. Mobile and Embedded
  4. Time from HIGH to LOW

Time from HIGH to LOW

Scheduled Pinned Locked Moved Unsolved Mobile and Embedded
2 Posts 2 Posters 462 Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • A Offline
    A Offline
    arthuki
    wrote on last edited by
    #1

    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 create 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.

    1 Reply Last reply
    0
    • ? Offline
      ? Offline
      A Former User
      wrote on last edited by
      #2

      Hi! You start with the following:

      
             if(gpio_get_value(PINO)==HIGH){
      
                 tempo.start();
      
             }
      

      So with some bad luck (everytime you come here and gpio_get_value(PIN0) is low) your timer doesn't get started. And in that case, nsecsElapsed's behaviour is undefined.

      1 Reply Last reply
      2

      • Login

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • Users
      • Groups
      • Search
      • Get Qt Extensions
      • Unsolved