 |
 |
| View previous topic :: View next topic |
| Author |
Message |
TaiChipY
Joined: 11 Mar 2005 Posts: 21
|
|
Posted: Fri Apr 22, 2005 8:57 am |
|
|
First of all thanx for honest answer ! , and sorry for so long replay!
I put all timeouts on the timer2 (added seconds count) and timer1 is now "stand alone". Both timers are working fine and correct but there is allways but :-)).
Becuse the timer 2 is set for switch debouncing i have small problems with "reading" button presses. If i set timer resets of timer2 to 5 the button presses are readed correctly but then i have problems with getting correct second count. If the value is set to 10 i get wright second timeouts but wrong button "read outs". So i try to "correct" this thru miliseconds counter but with no success.
Scenario:
//-----------------------------------
Until no SecondButtonPress
loop welcome / timeout10Seconds
SecondButtonPress
Activate other functions / timeoutMinutes
//----------------------------------------
Now im bit stuck here... I know i can put the timeouts in the main ( without timers ) but then i have this situation:
With counter ( timer2 ) i will be loosing some seconds after timeout
but i can correct this. If i put this in main then how to trigger the right value?.
I know that this is not the best explanation...but the main thing is i have to have right 10 seconds and 10 minutes countdown and sleep/wakeup used in this two parts.
Wakeup goes thru interrupt on change.
| Code: | //-------------------------------------------------
#use delay(clock=8000000)
#fuses HS, NOWDT, PUT, BROWNOUT
//--------------------------------------
#define INTS_PER_SECOND 30 // 30.51
//--------------------------------------------------
int hours=24
int8 int_counter, seconds=0, days=5, minutes=60;
#INT_TIMER1
void clock_isr() {
if(--int_count==0)
{
++seconds;
int_counter = INTS_PER_SECOND;
if(seconds==60){
seconds=0;
minutes--;
}
if(minutes==0){
minutes=60;
hours--;
}
if(hours==0){
days--;
hours=24;
}
}
}
//-------------------------
int8 seconds_t10;
int8 minutes_t10=10;
int8 Miliseconds;
#int_timer2
void timer2_isr(void)
{
if (Miliseconds < 0xFF)
Miliseconds++;
if (Miliseconds==1000)
{
Miliseconds=0;
sek_t10++;
}
if (seconds_t10==60)
{
seconds_t10=0;
minutes_t10--;
}
...
}
main()
{
Miliseconds = 0;
setup_timer_1(T1_INTERNAL|T1_DIV_BY_1);
setup_timer_2(T2_DIV_BY_4,(100),10);
enable_interrupts(INT_TIMER1);
enable_interrupts(INT_TIMER2);
enable_interrupts(GLOBAL);
//while(seconds_t10 < 10){output_high(PIN_B2)};
}
//------------------------------------------------- |
Let's go one part on the time.
I will send you other part of the code regarding the sleep but let's solve this timing, first...
Thank you in advance! TaiChipY |
|
 |
|
|
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
|