Voting resources, early voting, and poll worker information - VOTE. ... Adafruit is open and shipping.
0

Anyone working with the new PIC18FxxJxx parts?
Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.

Re: Anyone working with the new PIC18FxxJxx parts?

by oPossum on Thu Sep 09, 2010 11:45 pm

Using ICD to examine peripheral hardware registers will often give misleading values. The software simulator is much better for that stuff.

Make sure global interrupts (GIE) are enabled in addition to the TMR2 interrupt (T2IE).
Clear the TMR2 interrupt flag (T2IF) in the ISR. It is not cleared automatically.
Make sure watchdog is disabled or reset often enough.
Toggle an output in the ISR and watch it on a 'scope to determine if the ISR is called and how often. The ICD is almost useless for debugging anything realtime.

Post your code if you can.
I am the Possum, and I approve of this message. Sent from MacBook Wheel Sorry for my bad German.
oPossum
 
Posts: 636
Joined: Fri Oct 26, 2007 12:42 am
Location: Michigan, USA

Re: Anyone working with the new PIC18FxxJxx parts?

by zener on Fri Sep 10, 2010 2:44 am

Is the simulator part of MPLAB? I did have GIE set as well as PIE. I was resetting the flag in the ISR although I was never getting there (I set a breakpoint which I never got to). Every time I halted, the TMR2 reg would say 0x33 so I assumed it wasn't running. On the other hand it started at 0x00 presumably so did run some. I did consider that maybe I was getting a bad read on that register. Yes, all I was trying to do is toggle an output pin and it wasn't toggling, but I never got to the ISR as I said. Can't post any code till Monday since I'm home. Would like to know more about using the simulator though. Thanks.

zener
 
Posts: 4567
Joined: Sat Feb 21, 2009 2:38 am

Re: Anyone working with the new PIC18FxxJxx parts?

by oPossum on Fri Sep 10, 2010 2:58 am

Debugger menu, select tool, MPLAB SIM

Here is some code that works in the simulator...

Code: Select all | TOGGLE FULL SIZE
#include "p18f26j13.h"

void InterruptHandlerLowPriority();   // Forward declaration of handler
#pragma code low_vector = 0x18      // Put the low priority interrupt handler at 0x0018
void int_low(void)
{                           // Jump to the full handler somewhere else
   _asm goto InterruptHandlerLowPriority _endasm
}
#pragma code

void main(void)
{
   TRISB = 0;                  // All PORTB pins output
   LATB = 0x55;               // Initial PORTB state
   PR2 = 125 - 1;               // TMR2 preset
   T2CONbits.T2OUTPS = 0;         // TMR2 postscale = / 1
   T2CONbits.T2CKPS = 2;         // TMR2 prescale =  / 16
   RCONbits.IPEN = 1;            // Enable high and low priority interrupts
   IPR1bits.TMR2IP = 0;         // Make TMR2 interrupt low priority
   PIE1bits.TMR2IE = 1;         // Enable TMR2 interrupt
   INTCONbits.PEIE = 1;         // Enable peripheral interrupts
   INTCONbits.GIE = 1;            // Enable global interrupts
   T2CONbits.TMR2ON = 1;         // Turn on TMR2

   while(1);
}

volatile unsigned char t2cnt = 0;   // Count of TMR2 interrupts

#pragma interruptlow InterruptHandlerLowPriority
void InterruptHandlerLowPriority(void)
{
   if (PIR1bits.TMR2IF == 1)      // TMR2 interrupt ?
   {
      PIR1bits.TMR2IF = 0;      // Reset interrupt flag
      ++t2cnt;               // Increment interrupt count
      if(t2cnt == 0) {         // If count is zero, toggle all PORTB pins
         LATB ^= 0xFF;         //
      }
   }
}


Double click on a line to set a breakpoint.

Select Debugger menu, StopWatch for a handy cycle counter and timer.

Sorry the forum messed up the tabs.
I am the Possum, and I approve of this message. Sent from MacBook Wheel Sorry for my bad German.
oPossum
 
Posts: 636
Joined: Fri Oct 26, 2007 12:42 am
Location: Michigan, USA

Re: Anyone working with the new PIC18FxxJxx parts?

by zener on Fri Sep 10, 2010 5:31 pm

I loaded MPLAB so I could try out your code. It is acting pretty funky compared to at work. It keeps saying it can't find files like the header file, so I have to manually put it in the header folder. Now it says it cannot find c018i.o, even though I put it in the object folder. Is that the wrong place? Why can't it find anything? I agreed to everything on setup, including the paths it wanted.

zener
 
Posts: 4567
Joined: Sat Feb 21, 2009 2:38 am

Re: Anyone working with the new PIC18FxxJxx parts?

by oPossum on Fri Sep 10, 2010 6:01 pm

I installed C18 lite ver 3.36 in the default location (C:\MCC18) and everything just works. MPLAB rev 8.53.
All the headers are present in C:\MCC18\h

Reboot?
I am the Possum, and I approve of this message. Sent from MacBook Wheel Sorry for my bad German.
oPossum
 
Posts: 636
Joined: Fri Oct 26, 2007 12:42 am
Location: Michigan, USA

Re: Anyone working with the new PIC18FxxJxx parts?

by zener on Mon Sep 13, 2010 8:07 pm

oPossum wrote:Using ICD to examine peripheral hardware registers will often give misleading values.

Can you explain any more about this? Why is this? How useful is the tool if you can't trust what it shows? Should I be investing in the 500.00 Real Ice emulator? For example, I am writing a value to OSSCON, and the simulator shows it was done, but when running the actual part the ICD 3 shows that nothing was done... So I don't know if the ICD is lying or there is an actual problem or what.

And a seperate question, when using the simulator, when you rebuild and then run, does the simulator execute a reset to start with or do you have to do that manually?

zener
 
Posts: 4567
Joined: Sat Feb 21, 2009 2:38 am

Re: Anyone working with the new PIC18FxxJxx parts?

by oPossum on Tue Sep 14, 2010 12:48 am

I don't know why it works that way. My experience with ICD2 has been that viewing hardware registers may not show correct values. The ICD is useful for viewing variables (C) or general purpose registers (asm). I think the RealICE would behave the same as the ICD2/3. I always use the software simulator to make sure code works as expected. It is much faster, has more breakpoints, and can freeze the CPU, peripherals, and stimulus. The simulator appears to reset after build, but I usually press the reset button just to be sure.
I am the Possum, and I approve of this message. Sent from MacBook Wheel Sorry for my bad German.
oPossum
 
Posts: 636
Joined: Fri Oct 26, 2007 12:42 am
Location: Michigan, USA

Re: Anyone working with the new PIC18FxxJxx parts?

by zener on Tue Sep 14, 2010 2:52 am

I am surprised you think the Real Ice would do the same thing. I would think the extra 300.00 would be good for something!

Anyway, I believe my previous interrupt problem was caused by a faulty Library. When I use timers.h then it doesn't work. But when I use your code, with each register set individually then it works. I really appreciate all your help.

My new problem is that I cannot combine my ADC reading code and my interrupt code. For the AD I am using ADC.h library. The problem seems to center around the INTCON register and specifically bit 7, the global interrupt enable (GIE). If I set it high then the timer interrupt works (which I have set to high priority). If I set GIE low then the AD routine works (which uses a low priority interrupt.) The really strange thing is that my code seems to work fine when I use the simulator, but doesn't work when I use the actual part with the debugger. Any ideas? Thanks.

zener
 
Posts: 4567
Joined: Sat Feb 21, 2009 2:38 am

Re: Anyone working with the new PIC18FxxJxx parts?

by oPossum on Tue Sep 14, 2010 4:13 am

The RealICE does add value, but it is limited by the debug hardware/firmware in the PIC. The old ICE-2000 and ICE-4000 systems where much more capable and much more expensive - thousands for the base system and hundreds more for the pods, modules, cables and such. That style is of system was in use for 35 years but is no longer practical and everyone is moving away from it. I think the RealICE should be called FakeICE because that's what it is.

I suggest not using the library functions. Just write code to directly access the hardware registers. Don't use an interrupt for ADC completion - just poll the start/complete bit in a loop.

The problem that I have with library code is that it takes time to read the docs, try to use it, understand the quirks, work around the bugs, etc... I can usually read the spec sheet for the chip and write my own code in less time. The peripherals on an 8 bit PIC are much simpler than a PC, so there is really little need for "driver" code for them.
I am the Possum, and I approve of this message. Sent from MacBook Wheel Sorry for my bad German.
oPossum
 
Posts: 636
Joined: Fri Oct 26, 2007 12:42 am
Location: Michigan, USA

Re: Anyone working with the new PIC18FxxJxx parts?

by zener on Wed Sep 15, 2010 1:09 am

I made great progress today. Threw out all the libraries and wrote my own ADC routine (using your timer setup format as a reference). I also get help from a guy at work who is an expert with Freescale assembly. Doesn't transfer directly but he has lots of good ideas for debugging and program structure. I really appreciate your help. I have access to parts so if you ever need a package drop me a PM. And I am sure I will be back for more help soon! Thanks.

zener
 
Posts: 4567
Joined: Sat Feb 21, 2009 2:38 am

Please be positive and constructive with your questions and comments.