Sonsivri
 
*
Welcome, Guest. Please login or register.
Did you miss your activation email?
December 07, 2016, 03:17:18 15:17


Login with username, password and session length


Pages: [1]
Print
Author Topic: Is the MPlab IDE accurate? some help please  (Read 1282 times)
0 Members and 1 Guest are viewing this topic.
OleRuffo
Junior Member
**
Offline Offline

Posts: 40

Thank You
-Given: 34
-Receive: 9


« on: March 30, 2008, 07:32:47 07:32 »

HI all:
I'm working with the old good CCS compiler and a PIC 18F88 ( not yet in the flesh)
i have configured the oscillator to 4Mhz and i try to use the timer 2 to create an interrupt every 10 ms
so the dummy code is as follows

setup_timer_2(T2_DIV_BY_4,250,10);
that means 1EE6 /4 = 250EE3 , or an increment every 4us, this goes 250 times, then i have an overflow every 1 ms and an interrupt every 10 overflows so i have an interrupt every 10 ms
the code i get to do this is like this

int I,M;
#int_TIMER2
void  TIMER2_isr(void)
{
   setup_timer_2(T2_DIV_BY_4,250,10);
   I++;
   if (I==100)
     {
       M++; //this should happen every second
     }
}


void main()
{

   setup_timer_2(T2_DIV_BY_4,250,10);
   enable_interrupts(INT_TIMER2);
   enable_interrupts(GLOBAL);
//Setup_Oscillator parameter not selected from Intr Oscillator Config tab
   for(;Wink
   {
   if (M==60)
     {
    // the good stuff will be here every minute
     M=0;
     }
   }
  }

BUT.... when i try to simulate this code into the MPlab ide i get very different values
and in the mage3 you will see the place of the breakpoint
I'm really lost in this one because if i read the data sheet and a lil of logic this should happen every second!

Any ideas? thanks in advance for your input

Cheers
PS the images corresponds to the first and second pass over the breakpoint and the 3rd one is the place of the breakpoint itself.

Posted on: March 30, 2008, 07:06:35 AM - Automerged

Ops Sorry i forget to re initialize the variables and i change the names for something else and then they work as they should, seems that I is a reserved word ?? I starts at 100 no mater what i do.
Cheers
Now i get a breakpoint every 1.004085 seconds... real close but i will find out where is the missing cycles ahead
Cheers!

Posted on: March 30, 2008, 07:24:19 AM - Automerged

OK...i was missing the ZERO, so the correct value for the initialization is
setup_timer_2(T2_DIV_BY_4,249,10);
this way, with a crystal of 4 Mhz you will get exactly an interrupt every 10 ms
Hope this helps

Cheers

 
Logged
nvicchi
Newbie
*
Offline Offline

Posts: 14

Thank You
-Given: 0
-Receive: 6


« Reply #1 on: March 30, 2008, 10:08:57 10:08 »

It's good to know that you could succesfully correct your problem (and more important, documented for the rest of us the errors you had made). Anyway, I'd advice you to use Proteus, your debugging experience will be much less painful than with MPLAB.
Also (and this is just my opinion) for the 18F family, I'd use the C18 from Microchip...

Keep coding!
Logged
OleRuffo
Junior Member
**
Offline Offline

Posts: 40

Thank You
-Given: 34
-Receive: 9


« Reply #2 on: March 30, 2008, 06:39:19 18:39 »

Hi nvicchi:
I heard a lot about proteus, i will try to figure out the good one to test it, the site has a lot of different versions and SPX so i get lost to know whats the one that really works and has the debugger for the Microchips, i will try to find out the C18 complete as well to test it, i had worked with the CCS for years with good results but seems that there are some other compilers even more efficient. like the MP C18 tht you stated.
Cheers
Logged
OleRuffo
Junior Member
**
Offline Offline

Posts: 40

Thank You
-Given: 34
-Receive: 9


« Reply #3 on: March 30, 2008, 08:13:58 20:13 »

i Miss type the device name, is a PIC 16F88, i i fear that the C18 is not the good one for me  Undecided, at least for this very exercise,  anyway i will test the Latest proteus and the flowchart, i bet both will be around the site!  Grin
Now i have the C18 3.16 ready for the next one Grin
Cheers
Logged
Pages: [1]
Print
Jump to:  


DISCLAIMER
WE DONT HOST ANY ILLEGAL FILES ON THE SERVER
USE CONTACT US TO REPORT ILLEGAL FILES
ADMINISTRATORS CANNOT BE HELD RESPONSIBLE FOR USERS POSTS AND LINKS

... Copyright 2003-2999 Sonsivri.to ...
Powered by SMF 1.1.18 | SMF © 2006-2009, Simple Machines LLC | HarzeM Dilber MC