Results 1 to 2 of 2

Thread: Time from HIGH to LOW

  1. #1
    Join Date
    Oct 2016
    Posts
    1
    Qt products
    Qt3 Qt4 Qt/Embedded
    Platforms
    Unix/X11

    Default Time from HIGH to LOW

    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.

  2. #2
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,419
    Thanks
    37
    Thanked 1,545 Times in 1,495 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: Time from HIGH to LOW

    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,
    _

Similar Threads

  1. High DPI support on windows
    By Daylight in forum Qt Tools
    Replies: 1
    Last Post: 17th March 2014, 19:20
  2. Replies: 2
    Last Post: 23rd April 2013, 18:34
  3. High CPU Utilization
    By navi1084 in forum Qt Programming
    Replies: 4
    Last Post: 10th July 2009, 09:37
  4. Very high CPU usage with QTableView and MVC
    By montylee in forum Qt Programming
    Replies: 7
    Last Post: 24th March 2009, 06:14
  5. Error--High Priority
    By sujan.dasmahapatra in forum Qt Programming
    Replies: 2
    Last Post: 5th February 2009, 16:14

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.