Timer interrupts

100 views
Skip to first unread message

Barrie

unread,
May 1, 2013, 2:24:58 PM5/1/13
to hipi...@googlegroups.com
I am in the process of implementing an environmental controller. Its requirements on GPIO facilities are quite limited and most of the process functionality will be implemented in interrupt routines - the state machine is simple enough to do this. HiPi seems to be just what I am looking for as Perl is my preferred environment. However, I have one gaping hole at the moment. I will obviously need timer interrupts, probably between 1Hz to 10Hz and I can find nothing to provide this ... which surprises me as I would have thought it would be a common requirement. The GPIO provides GPCLK0 on GPIO4 under ALT0 although the maximum value of the divisor appears (from the BCM2835 specification section 6.3) to give a minimum frequency of about 40KHz. Obviously one could divide this by software but the details of how to set the clock are skimpy (e.g. none of the "Clock Sources" for GPCLK0/1/2 appear to be mentioned elsewhere in the document) and I don't know how to integrate clock interrupts (if there are such things) with HiPi. I was wondering if anyone had a solution to this problem.

Mark Dootson

unread,
May 1, 2013, 3:16:50 PM5/1/13
to hipi...@googlegroups.com
Hi,

I'm not sure quite what you require ?

If you want to do something in software once every tenth of a second (
approx ), the simplest approach is:

use strict;
use warnings;
use Time::HiRes qw ( usleep );

my $continue = 1;

while( $continue ) {
... do something
usleep( 100000 ); # microseconds
}

In a none threaded application you might alternatively choose to use
'settimer' ( see the Time::HiRes docs ) and catch SIGALRM.

On the other hand, if you are saying that you have an external device
that requires an accurate clock signal then I'd have to look at
submitting the necessary updates to bcm2835 library and incorporating
these in the HiPi wrapper. You could do this with the software and
wrapper as is, but I won't venture there as I'm guessing this isn't
actually what you are interested in.

Regards

Mark
> --
> You received this message because you are subscribed to the Google
> Groups "HiPi Perl" group.
> To unsubscribe from this group and stop receiving emails from it, send
> an email to hipi-perl+...@googlegroups.com.
> For more options, visit https://groups.google.com/groups/opt_out.
>
>

Barrie

unread,
May 3, 2013, 1:44:00 AM5/3/13
to hipi...@googlegroups.com


Thanks for your reply, Mark. It was the first scenario that I was referring to but the issue I saw was how to integrate timer interrupts with HiPi (GPIO) interrupts. This may be due to my lack of experience in this area but it seemed to me that if there were two independent sources of interrupts then there needed to be a common dispatcher otherwise the interrupt method on the object could be invoked whilst it was processing a previous interrupt. I therefore saw the GPIO clock as a means of ensuring that there was only one source of interrupts and only one dispatcher.

But let me give a concrete example because it may be that I am approaching this from the wrong angle. Say I have a PIR detector which, when a presence is detected, changes state. This change of state raises an interrupt and the on_action_interrupt method causes a light to be switched on. Now the light should be turned off 30 seconds, say, after the last presence detection. I envisage the presence detection setting a count which is decremented by a clock interrupt which, when it gets to zero, turns off the light. But plainly there has to be one object instance which receives interrupts from both the PIR detector and the clock. How does one do this? Do I have to write my own event dispatcher to serialise the events from two independent sources? If so how? AnyEvent, POE, ... I assume "there is more than one way to do it" but all seem more complex than simply using the GPIO clock.
Reply all
Reply to author
Forward
0 new messages