Shop OBEX P1 Docs P2 Docs Learn Events
Turn on a led for two minutes each 13 minutes all day ... — Parallax Forums

Turn on a led for two minutes each 13 minutes all day ...

ArchiverArchiver Posts: 46,084
edited 2003-04-30 01:04 in General Discussion
Of the millions of microcontrollers in use world-wide, most don't use
interrupts. I used to work in the irrigation business for a company the
sells tens of millions of sprikler timers every year. Every one of them had
a microcontroller in them, and only the top-of-the-line golf course
controller ($3500 ea) used a micro with interrupts.

I'm not saying that interrupts are never needed, but I am saying is that they
are rarely required -- and you won't find them on any BASIC language micro
because BASIC is NOT reentrant.

The best you can do is poll an input between instructions (BS2p and BS2pe
does this -- as well as competitive products that claim interrupts) or
structure your code so that the input can be polled with some frequency.
PBASIC is sturctured very nicely for embedded control and allows this.
Here's a "template" control structure that I like to use:

Main:
DO
' do critical item (like poll an input)
ON task GOSUB Task_0, Task_1, Task_2
task = task + 1 // 3
LOOP


With this sturcture, the critical item (like checking an input) gets
processed between each of the other program tasks. This is a very simplistic
approach; on more sophisticated projects each task is responsible for
updating the task pointer.

-- Jon Williams
-- Parallax



In a message dated 4/28/2003 8:28:54 AM Central Standard Time,
allan.lane@h... writes:

> I believe the DS1305 does have an alarm pin -- but this
> doesn't help much with the BS2, which has no interrupt
> inputs.
>
> One approach would be to set up a DS1302 time chip,
> 'sleep' the BS2 for some period, then on wake up ask
> the time chip what time it REALLY is, and cycle on
> that until the desired time occurs.
>



[noparse][[/noparse]Non-text portions of this message have been removed]

Comments

  • ArchiverArchiver Posts: 46,084
    edited 2003-04-28 20:35
    But of course. I wasn't being critical, merely pointing
    out something to be aware of. The BS2 is a very nice
    package with a very nice feature set, especially
    considering the price and simple learning curve.

    There are some things it doesn't do very well,
    but these things (like keeping accurate time) tend to
    be easily added with minimal cost (like $5.00 for a
    DS1302 based solution).

    --- In basicstamps@yahoogroups.com, jonwms@a... wrote:
    > Of the millions of microcontrollers in use world-wide, most don't
    use
    > interrupts. I used to work in the irrigation business for a
    company the
    > sells tens of millions of sprikler timers every year. Every one of
    them had
    > a microcontroller in them, and only the top-of-the-line golf course
    > controller ($3500 ea) used a micro with interrupts.
    >
    > I'm not saying that interrupts are never needed, but I am saying is
    that they
    > are rarely required -- and you won't find them on any BASIC
    language micro
    > because BASIC is NOT reentrant.
    >
    > The best you can do is poll an input between instructions (BS2p and
    BS2pe
    > does this -- as well as competitive products that claim interrupts)
    or
    > structure your code so that the input can be polled with some
    frequency.
    > PBASIC is sturctured very nicely for embedded control and allows
    this.
    > Here's a "template" control structure that I like to use:
    >
    > Main:
    > DO
    > ' do critical item (like poll an input)
    > ON task GOSUB Task_0, Task_1, Task_2
    > task = task + 1 // 3
    > LOOP
    >
    >
    > With this sturcture, the critical item (like checking an input)
    gets
    > processed between each of the other program tasks. This is a very
    simplistic
    > approach; on more sophisticated projects each task is responsible
    for
    > updating the task pointer.
    >
    > -- Jon Williams
    > -- Parallax
    >
    >
    >
    > In a message dated 4/28/2003 8:28:54 AM Central Standard Time,
    > allan.lane@h... writes:
    >
    > > I believe the DS1305 does have an alarm pin -- but this
    > > doesn't help much with the BS2, which has no interrupt
    > > inputs.
    > >
    > > One approach would be to set up a DS1302 time chip,
    > > 'sleep' the BS2 for some period, then on wake up ask
    > > the time chip what time it REALLY is, and cycle on
    > > that until the desired time occurs.
    > >
    >
    >
    >
    > [noparse][[/noparse]Non-text portions of this message have been removed]
  • ArchiverArchiver Posts: 46,084
    edited 2003-04-29 02:00
    Why not use the 60Hz timebase built into our power lines? I'm
    thinking that since this project "runs all day long" that it must be
    powered by an AC power supply. By carefully tapping into the
    transformer secondary and using a few simple components such as a
    resistor, diode, and NPN transistor to condition the 60Hz sine wave.
    Apply the resulting square wave to one of the stamp pins and let the
    software count like a clock. (If you are in Europe then its 50Hz,
    still same principle).

    Hal


    --- In basicstamps@yahoogroups.com, "Allan Lane" <allan.lane@h...>
    wrote:
    > But of course. I wasn't being critical, merely pointing
    > out something to be aware of. The BS2 is a very nice
    > package with a very nice feature set, especially
    > considering the price and simple learning curve.
    >
    > There are some things it doesn't do very well,
    > but these things (like keeping accurate time) tend to
    > be easily added with minimal cost (like $5.00 for a
    > DS1302 based solution).
    >
    > --- In basicstamps@yahoogroups.com, jonwms@a... wrote:
    > > Of the millions of microcontrollers in use world-wide, most don't
    > use
    > > interrupts. I used to work in the irrigation business for a
    > company the
    > > sells tens of millions of sprikler timers every year. Every one
    of
    > them had
    > > a microcontroller in them, and only the top-of-the-line golf
    course
    > > controller ($3500 ea) used a micro with interrupts.
    > >
    > > I'm not saying that interrupts are never needed, but I am saying
    is
    > that they
    > > are rarely required -- and you won't find them on any BASIC
    > language micro
    > > because BASIC is NOT reentrant.
    > >
    > > The best you can do is poll an input between instructions (BS2p
    and
    > BS2pe
    > > does this -- as well as competitive products that claim
    interrupts)
    > or
    > > structure your code so that the input can be polled with some
    > frequency.
    > > PBASIC is sturctured very nicely for embedded control and allows
    > this.
    > > Here's a "template" control structure that I like to use:
    > >
    > > Main:
    > > DO
    > > ' do critical item (like poll an input)
    > > ON task GOSUB Task_0, Task_1, Task_2
    > > task = task + 1 // 3
    > > LOOP
    > >
    > >
    > > With this sturcture, the critical item (like checking an input)
    > gets
    > > processed between each of the other program tasks. This is a
    very
    > simplistic
    > > approach; on more sophisticated projects each task is responsible
    > for
    > > updating the task pointer.
    > >
    > > -- Jon Williams
    > > -- Parallax
    > >
    > >
    > >
    > > In a message dated 4/28/2003 8:28:54 AM Central Standard Time,
    > > allan.lane@h... writes:
    > >
    > > > I believe the DS1305 does have an alarm pin -- but this
    > > > doesn't help much with the BS2, which has no interrupt
    > > > inputs.
    > > >
    > > > One approach would be to set up a DS1302 time chip,
    > > > 'sleep' the BS2 for some period, then on wake up ask
    > > > the time chip what time it REALLY is, and cycle on
    > > > that until the desired time occurs.
    > > >
    > >
    > >
    > >
    > > [noparse][[/noparse]Non-text portions of this message have been removed]
  • ArchiverArchiver Posts: 46,084
    edited 2003-04-29 18:06
    Somebody knows how
    can I get the seconds only from
    the 1302 RTC?

    I think that I could make blink a led
    each 13 minutes (13x60=780 sec) but
    somebody knows how can read the seconds only?

    Sorry I am not an expert.
    But it has been difficult to write
    a program with seconds only.

    My idea is to read the second number
    780th and an write something like:

    ...
    if nnn=780 then blink
    blink
    High 5
    pause 1000
    Low 5
    return
    ...

    But my problem is the nnn.
    Thanks in advence

    __________________________________
    Do you Yahoo!?
    The New Yahoo! Search - Faster. Easier. Bingo.
    http://search.yahoo.com
  • ArchiverArchiver Posts: 46,084
    edited 2003-04-29 18:24
    Being a real-time-clock, the seconds value will be in the range of zero to
    59, so you'll have to create a separate counter. What you can do is read the
    seconds register from the 1302, then check to see if it's the same as last
    time. If it isn't, then a new second has passed and you increment your
    counter. Then do your logic.

    Something like this (pseudo-code):

    Setup:
    GOSUB Read_Secs_Reg
    oldSecs = secsReg

    Main:
    GOSUB Read_Secs_Regs
    IF (secsReg <> oldSecs) THEN
    nnn = nnn + 1
    oldSecs = secsReg

    SELECT CASE nnn
    CASE 0 TO 778
    LOW LedPin

    CASE 779
    HIGH LedPin
    nnn = 0
    ENDSELECT
    ENDIF

    GOTO Main


    -- Jon Williams
    -- Parallax



    In a message dated 4/29/2003 12:08:21 PM Central Standard Time,
    joeterk@y... writes:

    > Somebody knows how
    > can I get the seconds only from
    > the 1302 RTC?
    >
    > I think that I could make blink a led
    > each 13 minutes (13x60=780 sec) but
    > somebody knows how can read the seconds only?
    >
    > Sorry I am not an expert.
    > But it has been difficult to write
    > a program with seconds only.
    >
    > My idea is to read the second number
    > 780th and an write something like:
    >
    > ...
    > if nnn=780 then blink
    > blink
    > High 5
    > pause 1000
    > Low 5
    > return
    > ...
    >
    > But my problem is the nnn.
    > Thanks in advence



    [noparse][[/noparse]Non-text portions of this message have been removed]
  • ArchiverArchiver Posts: 46,084
    edited 2003-04-29 18:56
    I don't think you can.
    The 1302 uses hours, minutes, seconds.

    HIGH RTCCS
    SHIFTOUT DTA, Clk, LSBFIRST, [noparse][[/noparse]%1\1,BrstReg\5,%10\2]
    SHIFTIN DTA, Clk, LSBPRE,
    [noparse][[/noparse]Seconds,Minutes,Hours,Date,Month,Day,Year]
    LOW RTCCS

    The above will read the values from the chip.
    See '1302.bs2' in the 'Files' area for a full example.
    Note the 1302 returns 'BCD' coded numbers.

    Really, you need to look at the 'minutes' field, see
    if it's 13, and output your blink.

    --- In basicstamps@yahoogroups.com, Joe Terk <joeterk@y...> wrote:
    > Somebody knows how
    > can I get the seconds only from
    > the 1302 RTC?
    >
    > I think that I could make blink a led
    > each 13 minutes (13x60=780 sec) but
    > somebody knows how can read the seconds only?
    >
    > Sorry I am not an expert.
    > But it has been difficult to write
    > a program with seconds only.
    >
    > My idea is to read the second number
    > 780th and an write something like:
    >
    > ...
    > if nnn=780 then blink
    > blink
    > High 5
    > pause 1000
    > Low 5
    > return
    > ...
    >
    > But my problem is the nnn.
    > Thanks in advence
    >
    > __________________________________
    > Do you Yahoo!?
    > The New Yahoo! Search - Faster. Easier. Bingo.
    > http://search.yahoo.co
  • ArchiverArchiver Posts: 46,084
    edited 2003-04-29 20:50
    Thanks:
    Yes, I see the minutes too but
    all is ok when I read until 9
    , 10 is not allowed by the program.
    Perhaps it is because there are two
    digits. (That is my problem)

    Many Thanks: Joe


    --- Allan Lane <allan.lane@h...> wrote:
    > I don't think you can.
    > The 1302 uses hours, minutes, seconds.
    >
    > HIGH RTCCS
    > SHIFTOUT DTA, Clk, LSBFIRST,
    > [noparse][[/noparse]%1\1,BrstReg\5,%10\2]
    > SHIFTIN DTA, Clk, LSBPRE,
    > [noparse][[/noparse]Seconds,Minutes,Hours,Date,Month,Day,Year]
    > LOW RTCCS
    >
    > The above will read the values from the chip.
    > See '1302.bs2' in the 'Files' area for a full
    > example.
    > Note the 1302 returns 'BCD' coded numbers.
    >
    > Really, you need to look at the 'minutes' field, see
    > if it's 13, and output your blink.
    >
    > --- In basicstamps@yahoogroups.com, Joe Terk
    > <joeterk@y...> wrote:
    > > Somebody knows how
    > > can I get the seconds only from
    > > the 1302 RTC?
    > >
    > > I think that I could make blink a led
    > > each 13 minutes (13x60=780 sec) but
    > > somebody knows how can read the seconds only?
    > >
    > > Sorry I am not an expert.
    > > But it has been difficult to write
    > > a program with seconds only.
    > >
    > > My idea is to read the second number
    > > 780th and an write something like:
    > >
    > > ...
    > > if nnn=780 then blink
    > > blink
    > > High 5
    > > pause 1000
    > > Low 5
    > > return
    > > ...
    > >
    > > But my problem is the nnn.
    > > Thanks in advence
    > >
    > > __________________________________
    > > Do you Yahoo!?
    > > The New Yahoo! Search - Faster. Easier. Bingo.
    > > http://search.yahoo.co
    >
    >
    > To UNSUBSCRIBE, just send mail to:
    > basicstamps-unsubscribe@yahoogroups.com
    > from the same email address that you subscribed.
    > Text in the Subject and Body of the message will be
    > ignored.
    >
    >
    > Your use of Yahoo! Groups is subject to
    > http://docs.yahoo.com/info/terms/
    >
    >


    __________________________________
    Do you Yahoo!?
    The New Yahoo! Search - Faster. Easier. Bingo.
    http://search.yahoo.com
  • ArchiverArchiver Posts: 46,084
    edited 2003-04-29 23:40
    Try this.

    I assume that you have a RTC and you get the variable MINUTE with the sub.
    RTC_Minute from it.

    '========================================
    '{$STAMP BS2}
    '{$PBASIC 2.5}

    LED pin 0
    COUNTER var nib
    MINUTE var byte
    OLD_MINUTE var byte

    high LED
    COUNTER = 0
    MINUTE = 0
    OLD_MINUTE = 0

    Main:
    gosub RTC_Minute
    if (OLD_MINUTE <> MINUTE) then
    OLD_MINUTE = MINUTE
    COUNTER = COUNTER + 1
    if (COUNTER > 3) then low LED
    endif
    if (COUNTER = 12) then
    COUNTER = 0
    high LED
    endif
    goto Main

    ' Of course the next isn't a RCT X-)
    ' but you can test if the code works...
    RTC_Minute:
    MINUTE = (MINUTE + 1) // 60
    pause 59990
    return
    '========================================

    Luis.



    Mensaje original
    De: Joe Terk [noparse]/noparse]mailto:[url=http://forums.parallaxinc.com/group/basicstamps/post?postID=IHfEvvHFdwrHZ4ltu3Q8YP_YRVdyVdUdvPqMaQBvL-Zl8ibRBleYq2hZmStf8DvTDm5sxryoCWHYALys]joeterk@y...[/url
    Enviado el: martes, 29 de abril de 2003 21:50
    Para: basicstamps@yahoogroups.com
    Asunto: Re: [noparse][[/noparse]basicstamps] Re: Turn on a led for two minutes each 13
    minutes all day ...


    Thanks:
    Yes, I see the minutes too but
    all is ok when I read until 9
    , 10 is not allowed by the program.
    Perhaps it is because there are two
    digits. (That is my problem)

    Many Thanks: Joe
  • ArchiverArchiver Posts: 46,084
    edited 2003-04-30 01:04
    Sorry. The code for a period of 15min with 2min LED=on at o'clock + 13min
    LED=off, would be

    '========================================
    '{$STAMP BS2}
    '{$PBASIC 2.5}
    LED pin 0
    COUNTER var nib
    MINUTE var byte
    OLD_MINUTE var byte

    low LED
    COUNTER = 0
    MINUTE = 0
    OLD_MINUTE = 0

    do
    gosub RTC_Minute
    loop until (MINUTE = 0)
    high LED

    Main:
    gosub RTC_Minute
    if (OLD_MINUTE <> MINUTE) then
    OLD_MINUTE = MINUTE
    COUNTER = COUNTER + 1
    if (COUNTER = 3) then low LED
    endif
    if (COUNTER = 15) then
    COUNTER = 0
    high LED
    endif
    goto Main
    stop

    ' Of course the next isn't a RCT X-)
    ' but you can test if the code works...
    RTC_Minute:
    debug DEC2 ? MINUTE
    MINUTE = (MINUTE + 1) // 60
    pause 59990
    return
    '========================================

    Luis.





    Mensaje original
    De: Luis [noparse]/noparse]mailto:[url=http://forums.parallaxinc.com/group/basicstamps/post?postID=AgHIVT8Gu64DmgvqIEH9V2JzSthS1CSvkxqJiR-U9iArwFG3H1dP7YC8B8ekHxjKI-kmpI4YsN0]lullamas@y...[/url
    Enviado el: miercoles, 30 de abril de 2003 00:41
    Para: basicstamps@yahoogroups.com
    Asunto: [noparse][[/noparse]basicstamps] Re: Turn on a led for two minutes each 13 minutes
    all day ...


    Try this.

    I assume that you have a RTC and you get the variable MINUTE with the sub.
    RTC_Minute from it.

    '========================================
    '{$STAMP BS2}
    '{$PBASIC 2.5}

    LED pin 0
    COUNTER var nib
    MINUTE var byte
    OLD_MINUTE var byte

    high LED
    COUNTER = 0
    MINUTE = 0
    OLD_MINUTE = 0

    Main:
    gosub RTC_Minute
    if (OLD_MINUTE <> MINUTE) then
    OLD_MINUTE = MINUTE
    COUNTER = COUNTER + 1
    if (COUNTER > 3) then low LED
    endif
    if (COUNTER = 12) then
    COUNTER = 0
    high LED
    endif
    goto Main

    ' Of course the next isn't a RCT X-)
    ' but you can test if the code works...
    RTC_Minute:
    MINUTE = (MINUTE + 1) // 60
    pause 59990
    return
    '========================================

    Luis.



    Mensaje original
    De: Joe Terk [noparse]/noparse]mailto:[url=http://forums.parallaxinc.com/group/basicstamps/post?postID=mXrDJs3lBfrc2CMChoQzkyNPQQzf90bXXmGkMARuHn9m1iWVZaoSlwRmUrT19Rz8wctKkTjitA]joeterk@y...[/url
    Enviado el: martes, 29 de abril de 2003 21:50
    Para: basicstamps@yahoogroups.com
    Asunto: Re: [noparse][[/noparse]basicstamps] Re: Turn on a led for two minutes each 13
    minutes all day ...


    Thanks:
    Yes, I see the minutes too but
    all is ok when I read until 9
    , 10 is not allowed by the program.
    Perhaps it is because there are two
    digits. (That is my problem)

    Many Thanks: Joe



    To UNSUBSCRIBE, just send mail to:
    basicstamps-unsubscribe@yahoogroups.com
    from the same email address that you subscribed. Text in the Subject and
    Body of the message will be ignored.


    Your use of Yahoo! Groups is subject to http://docs.yahoo.com/info/terms/
Sign In or Register to comment.