caramoan tour package

caramoan tour package

Author Topic: countdown timer that can be set anytime using PIC  (Read 2805 times)

Offline marcelino

  • Moderator
  • Solar Power Satellite
  • *****
  • Posts: 6016
  • Pogi/Ganda Points: 258
  • ...keep moving forward! - Robinson's
Re: countdown timer that can be set anytime using PIC
« Reply #20 on: November 20, 2008, 08:32:44 PM »
You forgot to initialize start_up_delay?

i just declare it sir as: (globally)
unsigned long start_up_delay = 1200; //5 mins

i used a prescaler of 1:8, so 250ms each cycle.

"Don't take life seriously. After all, no one has ever come out of it alive. -Bugs Bunny"

Philippine Electronics Forum

Re: countdown timer that can be set anytime using PIC
« Reply #20 on: November 20, 2008, 08:32:44 PM »

Offline marcelino

  • Moderator
  • Solar Power Satellite
  • *****
  • Posts: 6016
  • Pogi/Ganda Points: 258
  • ...keep moving forward! - Robinson's
Re: countdown timer that can be set anytime using PIC
« Reply #21 on: November 21, 2008, 12:48:02 PM »


thats the simulation.

originally, nasimulate ko using ung code sa taas. nakita ko na working na yun.
with the additional of delay during start up... medyo nalilito na ako ng behavior na pagPoll ng T0IF.
sa una kong code, (disabled ang minutes counter - para masimulate interm of minutes) ang counter (hours) ay nagdedecrement each 60seconds,

pero nung ginawa ko nang ganito,

Quote
#include <pic.h>

__CONFIG(XT & WDTDIS & PWRTDIS & UNPROTECT);

#include "seven_seg.h"

#define increment   RA0
#define decrement   RA1
#define   relay       RA2   
#define   start      RA3
#define delay      RA4            

unsigned int hours;
unsigned int minutes;
unsigned int seconds;
unsigned int quarterseconds;
unsigned long start_up_delay;

void init_7SEGMENT(void)
{
   TRISA = 0x03;
   PORTA = 0b10000;
   TRISB &= ~0x7F;      
   PORTB &= ~0x7F;
}   
void main(void)
{
   PSA = 0; /* prescale assigned to timer0 */
   PS2 = 0; PS1 = 1; PS0 = 0; /* 1:8 prescale */
   T0CS = 0;   /* enable timer0 */

   init_7SEGMENT();
   
   delay = 0;   
   start_up_delay = 60;              //60=15seconds (just to simulate)
   do
   {
      if(T0IF)
      {
         T0IF=0;
         start_up_delay--;
      }
   }while((start_up_delay!=0);

   
   if(start_up_delay!=0)
   {
   delay = 1;
   start = 1;   
   
   hours = 4;
   minutes = 0;
   seconds = 0;
   quarterseconds = 0;
   }

   while(1)
   {
      cases_7segment(hours);
      if (T0IF)
      {
         T0IF = 0;
         quarterseconds++;
         if (quarterseconds>=4)
         {
            seconds++;
            if (seconds>=60)
            {
               seconds=0;
               //minutes++;
               //if (minutes>=60)
               //{
               //   minutes=0;
                  if (hours>0)
                  {
                     hours--;
                  }
               //}
            }
         }

         if (hours>0)
         {
            relay = 0;
         }
      
         if (hours==0)
         {
            relay = 1;
         }
   
         if (increment && hours<9)
         {
            hours++;
            minutes = 0;
            seconds = 0;
         }
   
         if (decrement && hours>0)
         {
            hours--;
            minutes = 0;
            seconds = 0;
         }
      }
   }
}

every 15 seconds na tuloy bumababa yung counter "hours".

pa explain naman kung bakit ganun? hanggang ngayon di ko pa maintindihan ang pagpopoll ng timer...
"Don't take life seriously. After all, no one has ever come out of it alive. -Bugs Bunny"

Philippine Electronics Forum

Re: countdown timer that can be set anytime using PIC
« Reply #21 on: November 21, 2008, 12:48:02 PM »

Offline zer0w1ng

  • Technical People
  • Gas Turbine
  • *****
  • Posts: 2179
  • Pogi/Ganda Points: 305
  • Gender: Male
  • Enter any 11-digit prime number to continue...
    • The Cebuano Geek
Re: countdown timer that can be set anytime using PIC
« Reply #22 on: November 21, 2008, 01:18:09 PM »
The bug is that quarterseconds was not reset to 0 after the seconds was incremented
It should be:
Code: [Select]
    ...
    quarterseconds++;
    if (quarterseconds>=4)
    {
        quartersecond=0;    /* Additional line, reset to 0 */
        seconds++;
        if (seconds>=60)
    ...
The Cebuano Geek

Philippine Electronics Forum

Re: countdown timer that can be set anytime using PIC
« Reply #22 on: November 21, 2008, 01:18:09 PM »

Offline marcelino

  • Moderator
  • Solar Power Satellite
  • *****
  • Posts: 6016
  • Pogi/Ganda Points: 258
  • ...keep moving forward! - Robinson's
Re: countdown timer that can be set anytime using PIC
« Reply #23 on: November 21, 2008, 01:30:53 PM »
The bug is that quarterseconds was not reset to 0 after the seconds was incremented
It should be:
Code: [Select]
    ...
    quarterseconds++;
    if (quarterseconds>=4)
    {
        quartersecond=0;    /* Additional line, reset to 0 */
        seconds++;
        if (seconds>=60)
    ...

wow... nagwowork na po... hehehe ;D salamat.

hirap paggayan ang bug, di ko nakikita.
"Don't take life seriously. After all, no one has ever come out of it alive. -Bugs Bunny"

Philippine Electronics Forum

Re: countdown timer that can be set anytime using PIC
« Reply #23 on: November 21, 2008, 01:30:53 PM »

 

Privacy Policy

Contact Us: elabph@yahoo.com