View previous topic :: View next topic |
Author |
Message |
kamillas
Joined: 24 Oct 2011 Posts: 50
|
decrement counter in real time |
Posted: Sun Mar 04, 2012 1:28 pm |
|
|
In my program, I want the LCD displays the value of my delay_ms, as a counter decrement to zero,
example:
time of 500 ms, the display shows me
temp = 500 = 499= 498= 497=496=495=494=.........=0ms
and this account will display in real time, a counter will décémenter
Code: | #include <16F877A.h>
#fuses XT,NOWDT,NOPROTECT,NOLVP
#use delay(clock= 4000000)
#use standard_io(a)
#include <lcd_flex>
int time = 500 ;
#include <stdlib.h>
void main() {
port_b_pullups(TRUE);
while (TRUE) {
output_high(PIN_A0);
delay_ms( time );
output_low(PIN_A0); |
I want to decrement time, real-time. |
|
![](templates/subSilver/images/spacer.gif) |
asmboy
Joined: 20 Nov 2007 Posts: 2128 Location: albany ny
|
|
Posted: Sun Mar 04, 2012 2:03 pm |
|
|
thats what the PIC timers are for
timer 1 and timer 3 come to mind -
read how they work when driven by Fosc.....
however updating the LCD display at a 1 msec rate
may prove more of a challenge than you expect
your pic will certainly be busy enough |
|
![](templates/subSilver/images/spacer.gif) |
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Sun Mar 04, 2012 5:09 pm |
|
|
Quote: | time of 500 ms, the display shows me
temp = 500 = 499= 498= 497=496=495=494=.........=0ms
and this account will display in real time, a counter will décémenter |
You can't do this. No one can see numbers that exist for only 1 ms.
Also, the typical 16x2 lcd has a very slow optical update rate.
You probably can only update the lcd at maybe 4 times per second.
I can't test this right now, but that's what I recall from earlier experiments. |
|
![](templates/subSilver/images/spacer.gif) |
Mike Walne
Joined: 19 Feb 2004 Posts: 1785 Location: Boston Spa UK
|
LCD timer limits |
Posted: Sun Mar 04, 2012 5:46 pm |
|
|
What I THINK you are asking for is NOT realistic.
I understand that PCM programmer is now your LCD hero!!
You should have got the message, by now, that an LCD is a VERY VERY SLOW device:-
(1) It will NOT be able to refresh fast enough to count 10ms never mind 1ms.
(2) Even IF it could. ALL that you would SEE is a blur.
An LED matrix CAN work fast enough.
Your eyes will still NOT be able to follow the changing display.
You need to change your design brief.
I'm happy to give guidance/clues/help BUT I will NOT write code.
You COULD get an LCD to count down in 100ms steps, and your eyes MAY be able to follow it.
Is this counter/timer just a small part of a larger project? (If it is please enlighten us.)
Tell us what you REALLY want, and we MAY try to assist.
Mike |
|
![](templates/subSilver/images/spacer.gif) |
kamillas
Joined: 24 Oct 2011 Posts: 50
|
for 10ms |
Posted: Mon Mar 05, 2012 5:41 am |
|
|
PCM programmer wrote: |
You can't do this. No one can see numbers that exist for only 1 ms.
Also, the typical 16x2 lcd has a very slow optical update rate.
You probably can only update the lcd at maybe 4 times per second.
I can't test this right now, but that's what I recall from earlier experiments. |
and if I want, show 500ms, decrementing by 10 ms means that the LCD as I see it: time = 500 ms, after, time = 490, after, time = 480 .......... . up, time = 0, it can be done? in this case what I do. |
|
![](templates/subSilver/images/spacer.gif) |
temtronic
Joined: 01 Jul 2010 Posts: 9170 Location: Greensville,Ontario
|
|
Posted: Mon Mar 05, 2012 5:57 am |
|
|
PARTIAL CODE FRAGMENT...
i=500;
do {
your print statement goes here......;
delay_ms(10);
i=i-10;
while(i!=0); |
|
![](templates/subSilver/images/spacer.gif) |
Ttelmah
Joined: 11 Mar 2010 Posts: 19360
|
|
Posted: Mon Mar 05, 2012 6:21 am |
|
|
You still won't see it though.
The normal way to do this is to have the fast counter running, and only _write_ the data to the LCD perhaps 10* per second. Most multiplexed LCD's take something like 1/4 second to actually update anyway. Then when whatever happens that is meant to record the time, occurs, you take the full reading from the counter and write this.
If you look at digital watches with stopwatch functions, the display shows the seconds, and then when you hit the 'stop', the tenths and hundredths are displayed.
Best Wishes |
|
![](templates/subSilver/images/spacer.gif) |
temtronic
Joined: 01 Jul 2010 Posts: 9170 Location: Greensville,Ontario
|
|
Posted: Mon Mar 05, 2012 7:39 am |
|
|
'we' all know that, but unless he does it, he'll not understad why...
some learn by doing, others read the datasheets... |
|
![](templates/subSilver/images/spacer.gif) |
SherpaDoug
Joined: 07 Sep 2003 Posts: 1640 Location: Cape Cod Mass USA
|
|
Posted: Mon Mar 05, 2012 12:56 pm |
|
|
More practical might be to count down seconds and show a "spinning baton" made of | / - \ characters to indicate fractions of a second. _________________ The search for better is endless. Instead simply find very good and get the job done. |
|
![](templates/subSilver/images/spacer.gif) |
kamillas
Joined: 24 Oct 2011 Posts: 50
|
1 S |
Posted: Mon Mar 05, 2012 3:03 pm |
|
|
temtronic wrote: | PARTIAL CODE FRAGMENT...
i=500;
do {
your print statement goes here......;
delay_ms(10);
i=i-10;
while(i!=0);
|
For example, if I have a delay_ms(10000), and I want to display every 1000 ms (1s) is a decrement a counter to 0,
example: lcd displays: time = 10 seconds, after it appears, time = 9 seconds, until ......, time = 0 seconds, what method is used for its |
|
![](templates/subSilver/images/spacer.gif) |
temtronic
Joined: 01 Jul 2010 Posts: 9170 Location: Greensville,Ontario
|
|
Posted: Mon Mar 05, 2012 3:47 pm |
|
|
You could try something like this...
PARTIAL CODE FRAGMENT...
version 2
Code: |
i=10;
do {
your print statement goes here......;
delay_ms(1000);
i=i-1;
}while(i!=0);
|
...or a variation thereof. |
|
![](templates/subSilver/images/spacer.gif) |
kamillas
Joined: 24 Oct 2011 Posts: 50
|
|
Posted: Tue Mar 06, 2012 5:54 am |
|
|
temtronic wrote: | You could try something like this...
PARTIAL CODE FRAGMENT...
version 2
Code: |
i=10;
do {
your print statement goes here......;
delay_ms(1000);
i=i-1;
}while(i!=0);
|
...or a variation thereof. |
Thanks temtronic |
|
![](templates/subSilver/images/spacer.gif) |
|