CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to CCS Technical Support

urgent help on user programmable countdown timer....please..

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
anuragtiwari



Joined: 01 Aug 2013
Posts: 8

View user's profile Send private message

urgent help on user programmable countdown timer....please..
PostPosted: Thu Aug 01, 2013 2:26 pm     Reply with quote

hello experts ......
I am a newbie so..please don't mind if the question is awkward..
Actually i need to design a countdown timer that has three buttons ...
start/stop, clear and increment_minutes.

The time required is in multiples of minute ...
My problem is that i am not able to hack into the timer interrupt service routine using buttons from main().
My code is.....

Code:
#include <16f684.h>  //1 minute preprogrammed delay
#use delay(clock=4M)
#fuses NOMCLR,INTRC
#define  LED1  PIN_C0
#define START_STOP (input(PIN_A3))
#define INCREMENTS 30
unsigned int16 timer1_counter=0;
int1 timer1_flag;
int1  _LED1 = 0;
unsigned int16 set_timer(void);


#INT_TIMER1
void timer1_isr(void)
{ timer1_counter++;
  if(timer1_counter>=144)  // trips in 1 minute
  {timer1_counter=0;
   timer1_flag=TRUE;
    _LED1 ^= 1;
      output_bit(LED1,_LED1);
  }
}
  void main()
  { unsigned int16 seconds_counter;
    int minutes;
    int seconds;
    setup_oscillator(OSC_4MHZ);
    output_c(0x00);
    setup_timer_1(T1_INTERNAL|T1_DIV_BY_8);
    set_timer1(3643);
    while(!START_STOP==0);

    enable_interrupts(INT_TIMER1);
    enable_interrupts(GLOBAL);
    while(true)
    {
     
      if(timer1_flag)               // at this point of the code i need to provide
                                          // the buttons to increment the cont time of
                                          // timer..
                                          // e.g. if(input(PIN_A5)==1)
                                          // timer1_counter>=288;
                                          //its not working at all..i have tried this..
      { timer1_flag = 0;         
  }
  while(TRUE);
}
  }
Gabriel



Joined: 03 Aug 2009
Posts: 1067
Location: Panama

View user's profile Send private message

PostPosted: Thu Aug 01, 2013 4:54 pm     Reply with quote

Just an Idea:

you could use this:

http://www.ccsinfo.com/forum/viewtopic.php?t=26177&highlight=zero+drift

and then use your Buttons to alter the time registers independently on your main loop.

have it poll your buttons and clear, increment, decrease etc... all or individual time registers..

G.
_________________
CCS PCM 5.078 & CCS PCH 5.093
anuragtiwari



Joined: 01 Aug 2013
Posts: 8

View user's profile Send private message

PostPosted: Thu Aug 01, 2013 9:07 pm     Reply with quote

the link to the code that you provided doesn't have a button interface to increment or decrement the timer values... please help me out....
dyeatman



Joined: 06 Sep 2003
Posts: 1934
Location: Norman, OK

View user's profile Send private message

PostPosted: Thu Aug 01, 2013 9:11 pm     Reply with quote

How soon is your project due?
_________________
Google and Forum Search are some of your best tools!!!!
anuragtiwari



Joined: 01 Aug 2013
Posts: 8

View user's profile Send private message

PostPosted: Fri Aug 02, 2013 1:30 am     Reply with quote

@dyeatman
sir...
please help me regarding the countdown timer project ...its urgently required by this monday....please......
asmboy



Joined: 20 Nov 2007
Posts: 2128
Location: albany ny

View user's profile Send private message AIM Address

PostPosted: Fri Aug 02, 2013 6:30 am     Reply with quote

Code:

 set_timer1(3643);


you only do this ONCE in your MAIN setup ,
yet take no action based on the timer rollover?


What is the purpose of that line of code ??
also
Code:

unsigned int16 set_timer(void);
Gabriel



Joined: 03 Aug 2009
Posts: 1067
Location: Panama

View user's profile Send private message

PostPosted: Fri Aug 02, 2013 7:26 am     Reply with quote

Quote:
you provided doesn't have a button interface to increment or decrement the timer values


........... eventually you will have to code something.

ive provided you to a known-to-work timer code.

thats over 50% of your project.
_________________
CCS PCM 5.078 & CCS PCH 5.093
anuragtiwari



Joined: 01 Aug 2013
Posts: 8

View user's profile Send private message

PostPosted: Fri Aug 02, 2013 10:03 am     Reply with quote

guys , i made some changes in the code but its still hanging up... the output on pin_ A0 flips every 1 minute but PIN_A5 also goes high simultaneously with PIN_A0 .. what to do

Code:
#include <16f684.h>  //1 minute preprogrammed delay
#use delay(clock=4M)
#fuses NOMCLR
#define  LED1  PIN_C0
#define START_STOP (input(PIN_A3))
#define INCREMENTS 1
unsigned int16 timer1_counter=0;
int1 timer1_flag;
int1  _LED1 = 0;
unsigned int16 tick_counter=0;  // to count how many counts of 1 minute tick have occured
int8 p;

#INT_TIMER1
void timer1_isr(void)
{ timer1_counter++;
  if(timer1_counter>=144)  // ticks per 1 minute
  {timer1_counter=0;
   timer1_flag=TRUE;
    _LED1 ^= 1;
      output_bit(LED1,_LED1);
      tick_counter++;     
      if(tick_counter>=p)
      output_high(PIN_C5);
  }
}
   main()
  { unsigned int16 seconds_counter;
    int8 p;
    setup_oscillator(OSC_4MHZ);
    output_c(0x00);
    setup_timer_1(T1_INTERNAL|T1_DIV_BY_8);
    set_timer1(3643);
    while(START_STOP==1);
    enable_interrupts(INT_TIMER1);
    enable_interrupts(GLOBAL);
    while(true)
    {
      if(timer1_flag==1)
      { timer1_flag = 0;         
      }
       if(input(PIN_A1)==0)
      p+=INCREMENTS;
  while(TRUE);
} return p;
  }
alan



Joined: 12 Nov 2012
Posts: 357
Location: South Africa

View user's profile Send private message

PostPosted: Fri Aug 02, 2013 10:14 am     Reply with quote

Your p+= INCREMENTS are outside your timer1_flag test. Thus increments every loop instead of when timer1_flag is set.

Regards
anuragtiwari



Joined: 01 Aug 2013
Posts: 8

View user's profile Send private message

PostPosted: Fri Aug 02, 2013 9:43 pm     Reply with quote

help me guys to interface a button with timer.....
Mike Walne



Joined: 19 Feb 2004
Posts: 1785
Location: Boston Spa UK

View user's profile Send private message

PostPosted: Sun Aug 04, 2013 3:41 am     Reply with quote

Your deadline's tomorrow, but you're not helping either yourself or us.
Quote:
guys , i made some changes in the code but its still hanging up... the output on pin_ A0 flips every 1 minute but PIN_A5 also goes high simultaneously with PIN_A0 .. what to do

In your code you're operating on pins C0 and C5, NOT A0 and A5. Just confusing, shows lack of care and attention to detail.

You provide no explanation of where various constants come from. eg
Code:
if(timer1_counter>=144)  // ticks per 1 minute
.
.
.
.
set_timer1(3643);

Indentaton is all over the place so it's difficult to see where the loops are.
You don't tell us which way round your buttons are connected.
(Is 0 the pressed or released condition?)
Is the start/stop intended to be a toggle or hold down to run?
How do you indicate either the value of variable 'p' or 'minutes to run'?
Where is 'clear' button connected?

What do you think this section of code does?
Code:
 while(START_STOP==1);
    enable_interrupts(INT_TIMER1);
    enable_interrupts(GLOBAL);
    while(true)
    {
      if(timer1_flag==1)
      { timer1_flag = 0;         
      }
       if(input(PIN_A1)==0)
      p+=INCREMENTS;
  while(TRUE);
} return p;

What's supposed to happen when START_STOP==0?

It's difficult to know where to begin, without doing it all for you.

Mike
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
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