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 support@ccsinfo.com

16F721 and Timer1 problem

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



Joined: 05 Sep 2013
Posts: 14

View user's profile Send private message

16F721 and Timer1 problem
PostPosted: Mon Jan 26, 2015 7:52 am     Reply with quote

Hi everybody,

I use an 16F721 for an application. I use the PWM output ( work good ) , watchdog timer ans i want to use the timer1 to generate a time base. The problem is the timer1's interrupt don't work. I'm not sure the timer1 run too.

main code:
Code:
  setup_adc_ports(sAN3);
   setup_adc(ADC_CLOCK_INTERNAL);
   setup_timer_1(T1_INTERNAL|T1_DIV_BY_8);      //131 ms overflow
   setup_timer_2(T2_DIV_BY_16,249,1);      //1,0 ms overflow, 1,0 ms interrupt

   setup_ccp1(CCP_PWM);
   set_pwm1_duty((int16)898);

   T1GE = 0; mode gate disable
   T1ON = 1; timer1 run

But there is nothing happen on timer1.

If someone can help me?

Thanks by advance
Ttelmah



Joined: 11 Mar 2010
Posts: 19372

View user's profile Send private message

PostPosted: Mon Jan 26, 2015 8:24 am     Reply with quote

What do you expect to 'happen'?. The timer will just sit their counting. No flashing light, or trumpet!.

If you want it to 'do' something, then add a routine like:
Code:

#INT_TIMER1
void T1_tick(void)
{
    output_toggle(PIN_A1);
}

//and enable INT_TIMER1, and INT_GLOBAL in the main

This will then toggle the pin every time the timer resets to zero.

Get rid of your bit fiddles with the gate etc., not wanted/needed.
Ttelmah



Joined: 11 Mar 2010
Posts: 19372

View user's profile Send private message

PostPosted: Mon Jan 26, 2015 9:40 am     Reply with quote

Just FYI, I just put together a test application based on this:
Code:

#include <16F721.h>
#FUSES INTRC_IO,NOWDT,NOMCLR
#device ADC=10
#use delay(internal=16000000)

#INT_TIMER1
void T1_tick(void)
{
    output_toggle(PIN_A1);
}

void main()
{
   setup_adc_ports(sAN3);
   setup_adc(ADC_CLOCK_DIV_16); //Internal is not recommended above 1MHz
   setup_timer_1(T1_INTERNAL|T1_DIV_BY_8);      //131 ms overflow
   setup_timer_2(T2_DIV_BY_16,249,1);      //1,0 ms overflow, 1,0 ms interrupt

   setup_ccp1(CCP_PWM);
   set_pwm1_duty((int16)898);
   enable_interrupts(INT_TIMER1);
   enable_interrupts(GLOBAL);
   
   while(TRUE)
   {
      //TODO: User Code
   }
}


and it merrily toggles the pin every 131mSec.

Note also the change to the ADC clock (read the data sheet...). Note 4 under the 'ADC CLOCK PERIOD' table.
ELINAP



Joined: 05 Sep 2013
Posts: 14

View user's profile Send private message

PostPosted: Tue Jan 27, 2015 7:49 am     Reply with quote

Very Happy
Problem solved.
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