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

Timer 1 is not going at right clk speed?

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



Joined: 13 Apr 2011
Posts: 403

View user's profile Send private message

Timer 1 is not going at right clk speed?
PostPosted: Thu Jul 21, 2022 4:39 pm     Reply with quote

I'm making a silly program to test the time that the library takes to write 64 bytes and I'm getting weird values from Timer 1. I don't understand why.

Code:

    WriteTime=0;
    sprintf(xLineBuffer,"FBAEF1A425B6A7B345208C9D4CA8AC8E48A4ZZ48B1834DBEBE9D4EA8AD8E46A4");

    set_timer1(0);
    setup_timer_1(T1_INTERNAL|T1_DIV_BY_8);
   
    write_program_memory(0x3000,xLineBuffer,64);
    WriteTime=get_timer1();//51640?

    set_timer1(0);
    read_program_memory(0x3000,xOutBuffer,64);
    ReadTime=get_Timer1();//59
   
    set_timer1(0);
    write_program_memory(0x3040,xLineBuffer,64);
    WriteTime2=get_timer1();//1439



I'm getting values above 50K and the PIC16F67J50 is running at 48MHz from the internal clock.

The timer 1 should have a clock of 1.5MHz, so that means the block erase and posterior 64 byte write takes 34.3mS

Why?

According the datasheet 39775c the block erase count as ONE write, so around 2.8mS for the block erase plus the 64 bytes that at address 0x3040, that doesn't erase the block, takes around 1mS.

What's happening here?, one is taking too much time and the normal write without the block erase at 0x3040 is taking less time than the 2.8mS expected.
_________________
Electric Blue
Ttelmah



Joined: 11 Mar 2010
Posts: 19195

View user's profile Send private message

PostPosted: Fri Jul 22, 2022 6:46 am     Reply with quote

First thing, move the set_timer1 to after the timer setup. Otherwise the
timer can be running at an undetermined clock rate before this. Invalidates
the value....

Then, how are you reading the results?.
If you are in a debugger, these give unexpected results for the timings
of things like flash memory writes. I met this years ago, and ended up
list pulsing a pin and measuring with an oscilloscope instead. Gave the
right value then.
E_Blue



Joined: 13 Apr 2011
Posts: 403

View user's profile Send private message

PostPosted: Fri Jul 22, 2022 8:00 am     Reply with quote

Quote:
First thing, move the set_timer1 to after the timer setup. Otherwise the
timer can be running at an undetermined clock rate before this. Invalidates
the value....


I did it but I get mostly the same result.

Quote:
Then, how are you reading the results?.


I put a breakpoint a couple of lines after all the test ends and then I read the values using the ICD3.
_________________
Electric Blue
Ttelmah



Joined: 11 Mar 2010
Posts: 19195

View user's profile Send private message

PostPosted: Fri Jul 22, 2022 11:38 am     Reply with quote

Do it by programming without ICD and pulsing a pin. It is a very real
limitation of the ICD systems that the debug executive interferes
with the timing of things like flash memory writes.
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