prajwaldr9
Posts: 4
Joined: Tue Jul 11, 2017 6:13 am

Timers in Raspberry Pi

Tue Jul 11, 2017 6:22 am

I have seen the implemetation of timer using SIGALRM signal.

1.Aren't there any built in timers available in Raspberry pi ?

2.Is there any way to implement Raspberry Pi timers ?

Heater
Posts: 16092
Joined: Tue Jul 17, 2012 3:02 pm

Re: Timers in Raspberry Pi

Tue Jul 11, 2017 7:14 am

Sure.

What actually is it you want to measure the time of?

What periods and resolution do you need?

The answer to those questions might suggest the best solution to us folks out here.

Be aware that Raspberry Pi generally run Raspbian, a version of a Linux operating system, so direct access to timer hardware is not possible. It's all mediated by the Linux kernel.

High speed, real-time response is not what Linux is all about.
Memory in C++ is a leaky abstraction .

prajwaldr9
Posts: 4
Joined: Tue Jul 11, 2017 6:13 am

Re: Timers in Raspberry Pi

Tue Jul 11, 2017 8:27 am

Heater wrote:Sure.

What actually is it you want to measure the time of?

What periods and resolution do you need?

The answer to those questions might suggest the best solution to us folks out here.

Be aware that Raspberry Pi generally run Raspbian, a version of a Linux operating system, so direct access to timer hardware is not possible. It's all mediated by the Linux kernel.

High speed, real-time response is not what Linux is all about.
I want to generate the pulses
6s high voltage
2s low volatage ..
I want to repeat this n times.

To do this I needa timer.

User avatar
PeterO
Posts: 5951
Joined: Sun Jul 22, 2012 4:14 pm

Re: Timers in Raspberry Pi

Tue Jul 11, 2017 8:57 am

You don't need a timer ! Take this "flash a led" code as an example.

Code: Select all

/*
 * blink.c:
 *      Standard "blink" program in wiringPi. Blinks an LED connected
 *      to the first GPIO pin.
 *
 * Copyright (c) 2012-2013 Gordon Henderson. <projects@drogon.net>
 ***********************************************************************
 * This file is part of wiringPi:
 *      https://projects.drogon.net/raspberry-pi/wiringpi/
 *
 *    wiringPi is free software: you can redistribute it and/or modify
 *    it under the terms of the GNU Lesser General Public License as published by
 *    the Free Software Foundation, either version 3 of the License, or
 *    (at your option) any later version.
 *
 *    wiringPi is distributed in the hope that it will be useful,
 *    but WITHOUT ANY WARRANTY; without even the implied warranty of
 *    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *    GNU Lesser General Public License for more details.
 *
 *    You should have received a copy of the GNU Lesser General Public License
 *    along with wiringPi.  If not, see <http://www.gnu.org/licenses/>.
 ***********************************************************************
 */

#include <stdio.h>
#include <wiringPi.h>

// LED Pin - wiringPi pin 0 is BCM_GPIO 17.

#define LED     0

int main (void)
{
  printf ("Raspberry Pi blink\n") ;

  wiringPiSetup () ;
  pinMode (LED, OUTPUT) ;

  for (;;)
  {
    digitalWrite (LED, HIGH) ;  // On
    delay (500) ;               // mS
    digitalWrite (LED, LOW) ;   // Off
    delay (500) ;
  }
  return 0 ;
}
Discoverer of the PI2 XENON DEATH FLASH!
Interests: C,Python,PIC,Electronics,Ham Radio (G0DZB),1960s British Computers.
"The primary requirement (as we've always seen in your examples) is that the code is readable. " Dougie Lawson

Return to “General discussion”