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

TIMER 1 problem with 18F2480

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



Joined: 22 Mar 2012
Posts: 70
Location: France (Paris)

View user's profile Send private message

TIMER 1 problem with 18F2480
PostPosted: Mon May 28, 2012 2:30 am     Reply with quote

Hi,

This small code run perfectly with PROTEUS but do not RUN on the target board ! The LED start to blink after a long time (some mn).
Looking for some idea on this problem ... Thanks in advance.

Code is :
Code:

#int_timer1
void timer1_isr(void)
{
 set_timer1(0);//reset
// output_high(PIN_B4);// debug > Board test LED ON ok
if (msec++ ==76)// overflow
{
//T++;
//printf("T = %Lu\n\r",T);
output_toggle(PIN_B4);
 msec=0;
}
}
//==================================
void main()
{
setup_timer_1(T1_INTERNAL|T1_DIV_BY_1); // 
enable_interrupts(INT_TIMER1);
enable_interrupts(GLOBAL);
//output_high(PIN_B4);// debug > Board test  LED ON ok
while(1);
}
Ttelmah



Joined: 11 Mar 2010
Posts: 19569

View user's profile Send private message

PostPosted: Mon May 28, 2012 2:57 am     Reply with quote

Probably you are not running the main CPU oscillator you actually think you are. Fuses.
Proteus doesn't 'care' if the fuses give operation at 1Hz, while being told the chip is running at 20MHz. The real hardware does.....

Best Wishes
Cogitum



Joined: 22 Mar 2012
Posts: 70
Location: France (Paris)

View user's profile Send private message

Next .... Tmer 1 Problem 18F2480
PostPosted: Mon May 28, 2012 4:12 am     Reply with quote

HI Ttelmah,

Thank a lot for your quick answer.

With some change for tests like :
Code:

while(TRUE)
{
 //for(;;)
  output_high(PIN_B4);// debug > Board test  LED ON ok
 delay_ms(10);
  output_low(PIN_B4);
 delay_ms(50);}
//while(1);
}


LED is blinking but the TIMER 1 do not RUN if I put output_high (and low)
in remak ......?

Do you thing to a particular fuse ?
Best regards
Ttelmah



Joined: 11 Mar 2010
Posts: 19569

View user's profile Send private message

PostPosted: Mon May 28, 2012 4:48 am     Reply with quote

What _speed_ is the LED flashing?. You should just about be able to see it is flickering (16Hz). If it is slower than this, then the CPU is not being clocked at the speed you are telling the code it is. So, what fuse have you got controlling the oscillator?. What delay statement have you got?.

Best Wishes
Cogitum



Joined: 22 Mar 2012
Posts: 70
Location: France (Paris)

View user's profile Send private message

Problem with TIMER 1 and 18F2480
PostPosted: Mon May 28, 2012 7:39 am     Reply with quote

Hi,

sorry my submit was not published.

Test with the scope with differents values :

delay_ms( 10) = 10 ms positive pulse
delay_ms(50) = 50 ms low pulse

identical with values 1 and 5 ms
Xtal = 20 MHZ > scope tested

my full code for that :
Code:

// TIMER 1 >> 1sec

#include <18F2480.h>
#fuses HS,NOWDT,NOPROTECT,BROWNOUT,PUT,NOLVP
#use delay (clock=20000000)
#use rs232(baud=9600,parity=N,xmit=PIN_C6,rcv=PIN_C7,bits=8)

int16 T,msec;

#int_timer1
void timer1_isr(void)
{
 set_timer1(0);//reset
// output_high(PIN_B4);// debug > Board test LED ON ok
if (msec++ ==76)// overflow
{
//T++;
//printf("T = %Lu\n\r",T);
output_toggle(PIN_B4);
 msec=0;
}
}

//==================================
void main()
{
setup_timer_1(T1_INTERNAL|T1_DIV_BY_1); // 
enable_interrupts(INT_TIMER1);
enable_interrupts(GLOBAL);

while(TRUE)
{
 //for(;;)
  output_high(PIN_B4);// debug > Board test  LED ON ok
 delay_ms(1);
  output_low(PIN_B4);
 delay_ms(5);}
//while(1);
}


>>> Timer 1 do not run Twisted Evil
Regards
Ttelmah



Joined: 11 Mar 2010
Posts: 19569

View user's profile Send private message

PostPosted: Mon May 28, 2012 8:16 am     Reply with quote

Step through things:

What do you mean 'identical with pulses of 1 & 5mSec'. They should be very different...

'Xtal=20MHz scope tested'. No. You should _not_ try to test the oscillator with a scope. The capacitance is such that it invalidates any test. You test the oscillator by timing the width of a pulse, or using a programmed PWM. You could well have an oscillator that runs completely differently when the scope is present.....

Now, the code is about 3* more complex than it wants to be:

Code:

#include <18F2480.h>
#fuses HS,NOWDT,NOPROTECT,BROWNOUT,PUT,NOLVP,NOPBADEN
#use delay (clock=20000000)
#use rs232(baud=9600,parity=N,xmit=PIN_C6,rcv=PIN_C7,bits=8)

int8 msec; //Why waste time using an int16?
#int_timer1
void timer1_isr(void) {
   //set_timer1(0);//reset - No. The interrupt is called _because_ the timer
   //has wrapped to zero....
   if (msec++ >=76) {// overflow
      output_toggle(PIN_B4);
      msec=0;
   }
}

//==================================
void main(void) {

   setup_timer_1(T1_INTERNAL|T1_DIV_BY_1); //
   enable_interrupts(INT_TIMER1);
   enable_interrupts(GLOBAL);
   while(TRUE) {
      delay_us(10);
   }
}


Now:
1) You have a chance of seeing the toggle in the interrupt. Before it would be easy to miss with the pin being set/cleared in the main.
2) Timing - ((5E-8*4)*65536)*78 = 1.022 seconds - remember your count is incremented _after_ you test it, and counts 0 to 77.
3) Testing for ==, what happens if somehow the value gets incremented/decremented elsewhere?. >= avoids this being a problem.
4) Key one. What is port B4, configured as on boot?. Data sheet. What does NOPBADEN do?.

Best Wishes
Cogitum



Joined: 22 Mar 2012
Posts: 70
Location: France (Paris)

View user's profile Send private message

TIMER 1 and 18F2480 solved
PostPosted: Mon May 28, 2012 9:19 am     Reply with quote

Hi Ttelmah,

First : THANK a LOT for yours HELP !!! Very Happy Very Happy Very Happy

When I said "identical", i mean pulses on the scope was :
1) first test 10 and 50 ms
2) second test 1 and 5 ms

Quick test on the xtal was only to have just one idea on the period (20MHZ) I'm rigth with you ..... with add capacitor from the stobe and so on.
(i'm familiar with RF)

Best regard
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