|
|
View previous topic :: View next topic |
Author |
Message |
Guest Guest
|
"stoping" the counter |
Posted: Mon Jun 20, 2005 9:18 am |
|
|
If i reach some end time (5 Hours), how to "stop" further counting. Logicly i can't stop the counter so i must make some interrupt. The main problem is that i have to "wait" in this end time until button is pressed.
I can not reset counter or make something like that becuse it has no
effect and i will loose my end time ( that is displayed all the time ).
This end time is like some warning that can be breaked with button press.
If i make while or some for loop im stuck in the problem.
Chip has to go to sleep ( i one minute ) but he can not becuse he is spinning in while or in for loop.
So i have to this:
1. end time is reached
2. show warning
3. in no button pressed go to sleep
4. if button pressed show last state ( warning )
5. if deleteWarning button was pressed reset timer and start from begining
I hope i have described my problem well, so if someone knows how to solve this please share this with me.
John |
|
|
valemike Guest
|
|
Posted: Mon Jun 20, 2005 9:46 am |
|
|
Code: |
#INT_TIMER1 // This function is called every time
void clock_isr() // timer 1 overflows (65535->0), which is
{ // approximately 19 times per second for
if(--int_count==0) // this program.
{
++seconds;
int_count = INTS_PER_SECOND;
}
if (--int_count2==0)
{
++half_seconds;
int_count2 = INTS_PER_HALF_SECOND;
}
GLOBAL_timer1_ticks++;
if (GLOBAL_one_shot_timer) GLOBAL_one_shot_timer--;
if (GLOBAL_keypad_inactivity_timer > 0)
{
GLOBAL_keypad_inactivity_timer--;
}
}
|
Look how i handle my GLOBAL_one_shot_timer and my GLOBAL_keypad_inactivity_timer.
In both cases, they stop decrementing (and thus don't roll over) once they hit 0. If you need to reset the timer, then initialize it again to some big non-zero number. |
|
|
Guest Guest
|
|
Posted: Tue Jun 21, 2005 1:31 am |
|
|
Code: |
#include <18F452.h>
#fuses PUT, BROWNOUT, PROTECT, CPD
#use delay(clock=5000000)
#include "lcd.c"
int8 int_count,int_count2;
int half_seconds, GLOBAL_timer1_ticks,GLOBAL_one_shot_timer,GLOBAL_keypad_inactivity_timer;
#INT_TIMER1
void clock_isr()
{
if(--int_count==0)
{
++seconds;
int_count = 19;
}
if (--int_count2==0)
{
++half_seconds;
int_count2 = 9
}
GLOBAL_timer1_ticks++;
if (GLOBAL_one_shot_timer)
GLOBAL_one_shot_timer--;
if (GLOBAL_keypad_inactivity_timer > 0)
{
GLOBAL_keypad_inactivity_timer--;
}
}
//***********************************************
switch (number)
{
case 1:
if (hours==5)
{
printf(lcd_putc,"\f",5 Hours);
// waiting for button press but in the meentime go to sleep if no activity for 1 min.
}
break;
}
//**********************************************
void main()
{
setup_timer_1(T1_EXTERNAL|T1_DIV_BY_1);
enable_interrupts(INT_TIMER1);
enable_interrupts(GLOBAL);
lcd_init();
}
|
Can you please explain me your code and tell me if i go in the right way.. |
|
|
Guest Guest
|
|
Posted: Tue Jun 21, 2005 1:33 am |
|
|
Code: |
#include <18F452.h>
#fuses PUT, BROWNOUT, PROTECT, CPD
#use delay(clock=5000000)
#include "lcd.c"
int8 int_count,int_count2;
int half_seconds, GLOBAL_timer1_ticks,GLOBAL_one_shot_timer,GLOBAL_keypad_inactivity_timer;
#INT_TIMER1
void clock_isr()
{
if(--int_count==0)
{
++seconds;
int_count = 19;
}
if (--int_count2==0)
{
++half_seconds;
int_count2 = 9
}
GLOBAL_timer1_ticks++;
if (GLOBAL_one_shot_timer)
GLOBAL_one_shot_timer--;
if (GLOBAL_keypad_inactivity_timer > 0)
{
GLOBAL_keypad_inactivity_timer--;
}
}
//***********************************************
switch (number)
{
case 1:
if (hours==5)
{
printf(lcd_putc,"\f",5 Hours);
// waiting for button press but in the meentime go to sleep if no activity for 1 min.
}
break;
}
//**********************************************
void main()
{
setup_timer_1(T1_EXTERNAL|T1_DIV_BY_1);
enable_interrupts(INT_TIMER1);
enable_interrupts(GLOBAL);
lcd_init();
}
|
Can you please explain me your code and tell me if i go in the right way.. |
|
|
ckielstra
Joined: 18 Mar 2004 Posts: 3680 Location: The Netherlands
|
|
Posted: Tue Jun 21, 2005 5:33 am |
|
|
Basically you are going in the right direction, but there is still a lot of work to be done.
Code: | #fuses PUT, BROWNOUT, PROTECT, CPD
| The fuse for the clock generator is missing, if you are using an external crystal add HS to this line.
You specified BROWNOUT, but the voltage level for this brownout is missing, for example add BORV42.
Standard I always add NOLVP. Almost nobody is using this low voltage programming feature and without disabling it you might get spurious errors.
Code: | //***********************************************
switch (number)
{ |
Never create functions with a name equal to a C command.
Change your main() function so it will never 'end'. Now on reaching the end of your program it will exit the main function and execute a sleep instruction that the CCS compiler has put there and effectively stops everything. For example you can add a while(1) loop at the end of main.
Mentioning the sleep...... You also call sleep in your program, beware that there are some catches in calling this function. During sleep all clocks are suspended and all timers stop counting. How are you going to wake up again? There are several options:
1) Use an external clock driver and connect this to one of the counter inputs.
2) Add a 32kHz crystal to the timer1 pins, this will create a second clock source that still functions in sleep mode (I haven't looked into the details so you'll have to check this).
3) Use the watchdog timer for waking up at regular intervals. Problem is that the watchdog timer has a large spread of 50% between different chips, so is not very accurate.
4) Choose a newer PIC processor which doesn't shut down all timers.
5) ??? |
|
|
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
Powered by phpBB © 2001, 2005 phpBB Group
|