Sign in

username:

password:



Not a member?

Search basicx



Search tips

Subscribe to basicx



basicx by Keywords

Accelerometer | ADC | ADXL | Adxl20 | AVR | BasicStamp | BX-35 | BX28 | BX35 | COM3 | Compiler | Downloader | EEPROM | Electromagnet | GetADC | GP2D1 | GPS | I2C | IDE | Keypad | LCD | LCD+ | MIDI | Motors | Multitasking | Netmedia | Networking | PCB | PID | PlaySound | PWM | Relays | RTC | Servo | ShiftOut | SitePlayer | SPI | Stack | Timer | USB

Ads

Discussion Groups

Discussion Groups | BasicX | RE: Push and Hold Timer

Discussion forum for the BasicX family of microcontroller chips.

Push and Hold Timer - Don Kirby - Apr 4 18:12:32 2006

OK, I'm out of RAM, and the application just keeps getting bigger...
This is going to be interesting..

As I look for ways to reduce RAM usage, I am open to suggestions for
the following:

Sub Main is running a Do Loop in which a few different things are
going on. At some point during the loop, the user can push a button,
which normally doesn't do anything. However, if the user presses that
button for more than say 3 seconds, something does happen. What
happens is irrelevent. The problem is how to track the 3 seconds.
The timing of Sub Main is not critical, as long as the other tasks and
the RTC are still running, so I can actually halt it and wait for the
time to elapse.

What I'm trying to avoid is using another variable to store the
initial time.

Slightly OT: I think I am learning more about programming now, than I
have in the past. I've worked in a few different platforms, but none
so limiting (I don't think I've ever run out of room for variables in
VB) as the BX is. The process get's the creative juices flowing, and
forces one to think outside the box. I believe that it is much more
challenging to create a simple application with very limited resources
than it is to create a very complex application with almost limitless
resources.
-Don



(You need to be a member of basicx -- send a blank email to basicx-subscribe@yahoogroups.com )


Re: Push and Hold Timer - Mike Perks - Apr 4 18:56:26 2006

Don Kirby wrote:

> OK, I'm out of RAM, and the application just keeps getting bigger...
> This is going to be interesting..
>
> As I look for ways to reduce RAM usage, I am open to suggestions for
> the following:
>
> Sub Main is running a Do Loop in which a few different things are
> going on. At some point during the loop, the user can push a button,
> which normally doesn't do anything. However, if the user presses that
> button for more than say 3 seconds, something does happen. What
> happens is irrelevent. The problem is how to track the 3 seconds.
> The timing of Sub Main is not critical, as long as the other tasks and
> the RTC are still running, so I can actually halt it and wait for the
> time to elapse.
>
> What I'm trying to avoid is using another variable to store the
> initial time.
>
You might be over optimizing too early. You need to look at the whole
program. Changing an algorithm or implementation in another place might
free up lots of RAM and so this won't become a problem. The standard
tool to help figure out the RAM usage for a BasicX program is bxDism:
http://home.austin.rr.com/perks/micros/bxDism/

Mike
http://home.austin.rr.com/perks/micros/



(You need to be a member of basicx -- send a blank email to basicx-subscribe@yahoogroups.com )

Re: Push and Hold Timer - Tom Becker - Apr 4 19:19:03 2006

> ... so I can actually halt it and wait for the time to elapse.

What about calling Sleep(3.0) after detecting a closed switch, then
checking it again?

This does not guarantee it has been closed continuously but, if you can
assume it has been closed, if it is closed after the delay you can do
the irrelevant event.
Tom



(You need to be a member of basicx -- send a blank email to basicx-subscribe@yahoogroups.com )

Re: Push and Hold Timer - andy...@aol.com - Apr 4 19:48:21 2006

Using that sleep(3.0) method but checking the button every 10th of a second
and if the button is on in that 10th of a second add 1 to a variable and if
the variable equals 30 then it will perform the code (thirty 10ths of a second
is 3 seconds). Try this code:
dim pin As Integer
'choose what pin the button is on like this
pin = 5
dim i As Integer
dim c As Integer
const button As Byte = Pin

Sub main()
Do
If (GetPin(button = bxOutputHigh) Then
For i = 1 to 30
Call Delay(0.1)
If (GetPin(button = bxOutputHigh) Then
c = c + 1
Else
c = 0
End If
Next
If (c = 30) Then
'code here
End If
End If
Loop
End Sub

If have not tested this code by the way.
[Non-text portions of this message have been removed]



(You need to be a member of basicx -- send a blank email to basicx-subscribe@yahoogroups.com )

Re: Push and Hold Timer - Don Kirby - Apr 4 19:50:11 2006

That was my first thought, except, as you mentioned, the
non-continuous button press.

Currently, I'm trying to figure out how to do something like, check
the button continously (after the first contact) while in a loop
that's counting the time...or something similar. I might be able to
use a local variable if it get's released when the 3 seconds is up,
but another Sub incurrs too much overhead to do that. The only thing
I can think of is using a for-next counter, although I don't think
that memory gets released after the loop is finished either.

-Don
--- In b...@yahoogroups.com, Tom Becker wrote:
>
> > ... so I can actually halt it and wait for the time to elapse.
>
> What about calling Sleep(3.0) after detecting a closed switch, then
> checking it again?
>
> This does not guarantee it has been closed continuously but, if you can
> assume it has been closed, if it is closed after the delay you can do
> the irrelevant event.
> Tom
>



(You need to be a member of basicx -- send a blank email to basicx-subscribe@yahoogroups.com )

Re: Push and Hold Timer - Don Kirby - Apr 4 19:57:47 2006

I have used it extensively, that's how I got as far as I did. I've
reduced the number of module level variables as much as I can, and
have been moving subs/modules around to find the most efficient
combination. Encapsulation is my friend... Everything possible is a
local variable, although there are a bunch of globals that I can't do
anything about. I've gone so far as to eliminate an entire task,
making it a sub instead, in order to reduce the memory usage. No
small feat, considering it's a sizable application in itself.

-Don

--- In b...@yahoogroups.com, Mike Perks wrote:
>
> Don Kirby wrote:
>
> > OK, I'm out of RAM, and the application just keeps getting bigger...
> > This is going to be interesting..
> >
> > As I look for ways to reduce RAM usage, I am open to suggestions for
> > the following:
> >
> > Sub Main is running a Do Loop in which a few different things are
> > going on. At some point during the loop, the user can push a button,
> > which normally doesn't do anything. However, if the user presses that
> > button for more than say 3 seconds, something does happen. What
> > happens is irrelevent. The problem is how to track the 3 seconds.
> > The timing of Sub Main is not critical, as long as the other tasks and
> > the RTC are still running, so I can actually halt it and wait for the
> > time to elapse.
> >
> > What I'm trying to avoid is using another variable to store the
> > initial time.
> >
> You might be over optimizing too early. You need to look at the whole
> program. Changing an algorithm or implementation in another place might
> free up lots of RAM and so this won't become a problem. The standard
> tool to help figure out the RAM usage for a BasicX program is bxDism:
> http://home.austin.rr.com/perks/micros/bxDism/
>
> Mike
> http://home.austin.rr.com/perks/micros/
>



(You need to be a member of basicx -- send a blank email to basicx-subscribe@yahoogroups.com )

Re: Push and Hold Timer - Don Kirby - Apr 4 19:58:09 2006

Hmm...That's not to shabby.

I think I can eliminate one of the variables there too, reducing it
the RAM to only 1 byte, by using the for next counter itself, and
exiting the for-next if the button isn't pressed.

Thanks Andy, I've got something to chew on for a while.
-Don

--- In b...@yahoogroups.com, andycamach@... wrote:
>
> Using that sleep(3.0) method but checking the button every 10th of a
second
> and if the button is on in that 10th of a second add 1 to a variable
and if
> the variable equals 30 then it will perform the code (thirty 10ths
of a second
> is 3 seconds). Try this code:
> dim pin As Integer
> 'choose what pin the button is on like this
> pin = 5
> dim i As Integer
> dim c As Integer
> const button As Byte = Pin
>
> Sub main()
> Do
> If (GetPin(button = bxOutputHigh) Then
> For i = 1 to 30
> Call Delay(0.1)
> If (GetPin(button = bxOutputHigh) Then
> c = c + 1
> Else
> c = 0
> End If
> Next
> If (c = 30) Then
> 'code here
> End If
> End If
> Loop
> End Sub
>
> If have not tested this code by the way.
> [Non-text portions of this message have been removed]
>



(You need to be a member of basicx -- send a blank email to basicx-subscribe@yahoogroups.com )

Re: Re: Push and Hold Timer - Tom Becker - Apr 4 21:17:49 2006

Maybe you can use the RTC tick count directly, Don.

Look at the Hobbs meter code I posted recently; it uses register.RTCTick
as a timer. http://groups.yahoo.com/group/basicx/message/21136
Tom



(You need to be a member of basicx -- send a blank email to basicx-subscribe@yahoogroups.com )

RE: Push and Hold Timer - "Westhoff, Thomas " - Apr 4 22:03:45 2006

You could just buy a ZX-24 from www.zbasic.net and you will have more ram. I just ported over a large application from the BX-35 to the ZX-44 just to get the additional ram. (also get a little more than 2X speed too)

You will need one variable to make your timer.
-----Original Message-----
From: Don Kirby [mailto:p...@yahoo.com]
Sent: Tue 4/4/2006 6:12 PM
To: b...@yahoogroups.com
Cc:
Subject: [BasicX] Push and Hold Timer
OK, I'm out of RAM, and the application just keeps getting bigger...
This is going to be interesting..

As I look for ways to reduce RAM usage, I am open to suggestions for
the following:

Sub Main is running a Do Loop in which a few different things are
going on. At some point during the loop, the user can push a button,
which normally doesn't do anything. However, if the user presses that
button for more than say 3 seconds, something does happen. What
happens is irrelevent. The problem is how to track the 3 seconds.
The timing of Sub Main is not critical, as long as the other tasks and
the RTC are still running, so I can actually halt it and wait for the
time to elapse.

What I'm trying to avoid is using another variable to store the
initial time.

Slightly OT: I think I am learning more about programming now, than I
have in the past. I've worked in a few different platforms, but none
so limiting (I don't think I've ever run out of room for variables in
VB) as the BX is. The process get's the creative juices flowing, and
forces one to think outside the box. I believe that it is much more
challenging to create a simple application with very limited resources
than it is to create a very complex application with almost limitless
resources.
-Don

_____

> .
_____

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



(You need to be a member of basicx -- send a blank email to basicx-subscribe@yahoogroups.com )

Re: Push and Hold Timer - Don Kirby - Apr 4 22:45:43 2006


> You could just buy a ZX-24

If it were only $20 cheaper, it could compete with the BX. Great
device though.

-Don



(You need to be a member of basicx -- send a blank email to basicx-subscribe@yahoogroups.com )

Re: Push and Hold Timer - Don Kirby - Apr 4 22:46:57 2006

Tom, you're a genious...did you know that? Thanks.

-Don

--- In b...@yahoogroups.com, Tom Becker wrote:
>
> Maybe you can use the RTC tick count directly, Don.
>
> Look at the Hobbs meter code I posted recently; it uses
register.RTCTick
> as a timer. http://groups.yahoo.com/group/basicx/message/21136
> Tom
>



(You need to be a member of basicx -- send a blank email to basicx-subscribe@yahoogroups.com )

Re: Push and Hold Timer - Ingvar Esk - Apr 5 15:51:10 2006

Test it 30 times instead of two times) with a sleep 0.1 sec
inbetween. Cost you ROM but not RAM.

Ingvar
--- In b...@yahoogroups.com, "Don Kirby" wrote:
>
> That was my first thought, except, as you mentioned, the
> non-continuous button press.
>
> Currently, I'm trying to figure out how to do something like, check
> the button continously (after the first contact) while in a loop
> that's counting the time...or something similar. I might be able
to
> use a local variable if it get's released when the 3 seconds is up,
> but another Sub incurrs too much overhead to do that. The only
thing
> I can think of is using a for-next counter, although I don't think
> that memory gets released after the loop is finished either.
>
> -Don
> --- In b...@yahoogroups.com, Tom Becker wrote:
> >
> > > ... so I can actually halt it and wait for the time to elapse.
> >
> > What about calling Sleep(3.0) after detecting a closed switch,
then
> > checking it again?
> >
> > This does not guarantee it has been closed continuously but, if
you can
> > assume it has been closed, if it is closed after the delay you
can do
> > the irrelevant event.
> >
> >
> > Tom
>



(You need to be a member of basicx -- send a blank email to basicx-subscribe@yahoogroups.com )