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

24EP256GP202 1ms timer1 running very slow

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



Joined: 17 Jun 2019
Posts: 552
Location: Des Moines, Iowa, USA

View user's profile Send private message Visit poster's website

24EP256GP202 1ms timer1 running very slow
PostPosted: Wed Jul 15, 2020 1:52 pm     Reply with quote

I noticed an odd thing with our system today where a communication timeout was not shutting things down like it should.The code uses timer2 configured for 1ms (1000/s, ms timer) to increment a counter. On every comm activity, the timer is reset. If the timer reaches a timeout value, we shut things down.

But it wasn't happening.

After some investigation, I discovered out timer was going very, VERY slowly. Maybe 100th the speed. (ie counting to 10 took a second, rather than counting to 1000).

Using the PIC timer spreadsheet I made, I verified the values.

I compared with a web calculator for PIC24 I found.

I found a downloadable .exe PIC timer calculator and it also agreed.

But reality disagrees, and that's all that matters. If I've grabbed the right output, we have:

140MHz clock speed

Code:

#define TIME_1_MS               0x222D      // A one millisecond timer period at / 8

setup_timer2 (TMR_INTERNAL | TMR_DIV_BY_8, TIME_1_MS);


Using:

freq = ((clock / 2) / prescale) / period

...to...

period = ((clock /2) / prescale) / frequency

period = ((140000000 / 2) / 8) / 1000

period = 8750

This is what the CCS PIC24 wizard gives me with the 140MHz value. This is what the website gave me. And this is what the .exe from MikroElectronika Timer Calculator gave me.

But in operation, if I just print out the values when they change, I see it count to 10 each second (approximately; I did not do any fine timing).

Does anyone know what I might want to check on my hardware that could impact how timers behave?

TIMER3 and TIMER4 seem to be operating as expected.

Thanks, much. (And I know the value we use is off by one, but that's what was in the code before I inherited so I expect it's close enough.)
_________________
Allen C. Huffman, Sub-Etha Software (est. 1990) http://www.subethasoftware.com
Embedded C, Arduino, MSP430, ESP8266/32, BASIC Stamp and PIC24 programmer.
http://www.whywouldyouwanttodothat.com ?
newguy



Joined: 24 Jun 2004
Posts: 1908

View user's profile Send private message

PostPosted: Wed Jul 15, 2020 6:31 pm     Reply with quote

a) Does that timer have a postscaler?
and b) Dump the list file to see if timer 2 is being set correctly (i.e. timer's register values match what they should be given your settings).
Ttelmah



Joined: 11 Mar 2010
Posts: 19535

View user's profile Send private message

PostPosted: Thu Jul 16, 2020 1:37 am     Reply with quote

Old classic question. _WHAT COMPILER VERSION_....

Two possibilities basically exist:
1) Your code is changing something or doing something that results in this.
2) You have an old compiler version that sets something up wrong.

So, have just tried a really basic test with the ICD, and this:
Code:

#include <mainclock.h>
#define TIME_1_MS               0x222D      // A one millisecond timer period at / 8

unsigned int16 tickctr=0;

#INT_TIMER2
void tick(void)
{
   tickctr++;
}

void main(void)
{
   setup_timer2 (TMR_INTERNAL | TMR_DIV_BY_8, TIME_1_MS);
   clear_interrupt(INT_TIMER2);
   enable_interrupts(INT_TIMER2);
   enable_interrupts(GLOBAL);

   while(TRUE)
   {
      delay_cycles(1); //breakpoint here
      delay_ms(10);
   }
}


Using the current compiler, merrily has 0, 10, 20.. in tickctr each time the
breakpoint is reached. So the interrupt timing is 'spot on'.
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