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

Ice 2000 emulator masking interrupts, real circuit does not

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



Joined: 12 Sep 2003
Posts: 43

View user's profile Send private message

Ice 2000 emulator masking interrupts, real circuit does not
PostPosted: Mon Jun 25, 2007 6:25 pm     Reply with quote

To all the experts of this forum (and from the years lurking around and participating in threads, I know there are quite a lot), I would like your input and suggestions on the following problem I face today.

I have two identical circuits, loaded with generous components (i2c eeproms, duarts, RTC, many serial devices, in fact, the pic is fully loaded). These boards operate the lovely PIC18F6722 chip. One has the actual chip, the other board has the in-circuit emulator ICE2000, with processor module PCM18XS0.

I've been developping for almost a year on this platform, and I've had my share of problems. There was the 2nd i2c chip errata, there was the compiler v4 craziness, there was other things but over time, I have found solutions (or people helped me) and now the products are quite complete, except for one missing feature: watchdog timer.

When I enable the watchdog timer, it works as expected on the real circuit. i.e.: all the "restart_wdt()" I carefully placed in the code take care of restarting the timer and my system never resets.

On the ICE2000 emulator board, after about 2 minutes of runtime, all interrupts are suddently masked. PIE1, PIE2 and PIE3 are all zero'd out. For months, I've just assumed my program had bugs, was poorly written, but today I decided to prove it.

I ended up with the following program:
Code:

#zero_ram           //Efface toute la RAM au démarrage.

#include <18F6722.h>
#device adc=8
#pragma case

#FUSES WDT                    //Watchdog!
#FUSES WDT128                   //Watch Dog Timer uses 1:128 Postscale
#FUSES H4
#FUSES PROTECT                  //Code protected from reads
#FUSES IESO                     //Internal External Switch Over mode enabled
#FUSES BROWNOUT                 //Reset when brownout detected
#FUSES BORV45                   //Brownout reset at 4.5V
#FUSES NOPUT                    //No Power Up Timer
#FUSES NOCPD                    //No EE protection
#FUSES STVREN                   //Stack full/underflow will cause reset
#FUSES NODEBUG                  //No Debug mode for ICD
#FUSES NOLVP                  //No low Voltage Programming on B3(PIC16) or B5(PIC18)
#FUSES NOWRT                    //Program memory not write protected
#FUSES NOCPB                    //No Boot Block code protection
#FUSES NOEBTRB                  //Boot block not protected from table reads
#FUSES NOEBTR                   //Memory not protected from table reads
#FUSES NOWRTD                   //Data EEPROM not write protected
#FUSES NOWRTC                   //configuration not registers write protected
#FUSES NOWRTB                   //Boot block not write protected
#FUSES FCMEN                    //Fail-safe clock monitor enabled
#FUSES LPT1OSC                  //Timer1 configured for low-power operation
#FUSES NOMCLR                 //Master Clear pin disabled
#FUSES NOXINST                  //Extended set extension and Indexed Addressing coinopMode disabled (Legacy mode)
#FUSES BBSIZ1K                  //1K words Boot Block size

#use fast_io(a)
#use fast_io(b)
#use fast_io(c)
#use fast_io(d)
#use fast_io(e)
#use fast_io(f)
#use fast_io(g)

#define PIN_MDB_TX          PIN_G1
#define PIN_MDB_RX          PIN_G2
#define PIN_LED_CPU_OPTO    PIN_D7

#define PORT_A_TRIS 0b11111111
#define PORT_B_TRIS 0b00001111
#define PORT_D_TRIS 0b01101111
#define PORT_E_TRIS 0b01100000

int16 int_led;
int1  LedFlashState;

#use delay(clock=32000000)

#int_timer1
void timer_interrupt (void) {
  set_timer1(0xE0EF);

  if(int_led > 0) {
    int_led++;
    if(int_led > 50) { // Interrupt aux 50ms; Flasher un LED
      int_led = 1;

      output_bit(PIN_LED_CPU_OPTO, LedFlashState);
      LedFlashState ^= 1;
    }
   }

  if (get_timer1() < 0xE0EF) set_timer1(0xFF00); // Si débordement repars l'interrupt
}

void main() {

  restart_wdt();
  delay_ms(10); //Stabilisation du hardware.

  set_tris_a(PORT_A_TRIS);
  output_a  (0b01000000);
  set_tris_b(PORT_B_TRIS);
  output_b  (0b00000000);
  set_tris_c(0b10011000);
  output_c  (0b01000000);
  set_tris_d(PORT_D_TRIS);
  output_d  (0b00010000);
  set_tris_e(PORT_E_TRIS);
  output_e  (0b10000000);
  set_tris_f(0b00010000);
  output_f  (0b00000000);
  set_tris_g(0b00110100);
  output_g  (0b00000001);

  set_tris_a(PORT_A_TRIS & 0b11101111);
  set_tris_e(PORT_E_TRIS & 0b11101111);

  setup_wdt(WDT_ON);
  setup_timer_0(RTCC_INTERNAL | RTCC_DIV_1); //clock 32mHz, incremente à chaque 4uS, déborde à 262mS
  setup_timer_1(T1_INTERNAL | T1_DIV_BY_1);   //Setup interrupts
  setup_timer_2(T2_DIV_BY_16, 124, 1);       //Set prescale, period for 4Khz
  set_pwm4_duty(63);                         //Set duty cycle 50%
  setup_timer_3(T3_INTERNAL | T3_DIV_BY_8);
  setup_timer_4(T4_DISABLED, 0, 1);
  setup_ccp1(CCP_OFF);
  setup_ccp2(CCP_OFF);
  setup_ccp3(CCP_OFF);
  setup_ccp4(CCP_OFF);
  setup_ccp5(CCP_OFF);
  setup_psp(PSP_DISABLED);
  setup_comparator(NC_NC_NC_NC);
  setup_vref(FALSE);
  setup_low_volt_detect(FALSE);
  setup_adc(ADC_CLOCK_DIV_8);
  setup_adc_ports(AN0_TO_AN9);
  ext_int_edge(H_TO_L);

  delay_ms(100);
  set_tris_a(PORT_A_TRIS);
  set_tris_e(PORT_E_TRIS);

  disable_interrupts(GLOBAL);
  disable_interrupts(INT_RTCC);
  disable_interrupts(INT_TIMER0);
   enable_interrupts(INT_TIMER1);
  disable_interrupts(INT_TIMER2);
  disable_interrupts(INT_TIMER3);
  disable_interrupts(INT_TIMER4);
  disable_interrupts(INT_EXT); //RB0 pour l'interruption du DUART 1
  disable_interrupts(INT_EXT1); //RB1 pour l'interruption du DUART 2
  disable_interrupts(INT_EXT2);
  disable_interrupts(INT_EXT3); //RB3 pour l'entrée multiplexée
  disable_interrupts(INT_RB);
  disable_interrupts(INT_PSP);
  disable_interrupts(INT_AD);
  disable_interrupts(INT_RDA);
   enable_interrupts(INT_RDA2);
  disable_interrupts(INT_TBE);
  disable_interrupts(INT_TBE2);
  disable_interrupts(INT_SSP);
  disable_interrupts(INT_SSP2);
  disable_interrupts(INT_CCP1);
  disable_interrupts(INT_CCP2);
  disable_interrupts(INT_CCP3);
  disable_interrupts(INT_CCP4);
  disable_interrupts(INT_CCP5);
  disable_interrupts(INT_BUSCOL);
  disable_interrupts(INT_BUSCOL2);
  disable_interrupts(INT_LOWVOLT);
  disable_interrupts(INT_COMP);
  disable_interrupts(INT_EEPROM);
  disable_interrupts(INT_OSCF);
   enable_interrupts(GLOBAL);

  int_led = 1; //This will have a LED blink by timer1 so we know when interrupts are killed

  for(;;) {
    restart_wdt();
  }
}


Compiling this for a chip, works fine. Loading it up in ice2000, and it fails after 2 minutes 15 seconds. It's always around 2:15 for some reason.

If anyone has ideas that eventually lead to fixing the problem, I will personally pay a beer to that person! This clearly shows how serious I am about this problem... Wink
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Mon Jun 25, 2007 7:11 pm     Reply with quote

Look in the Help file in MPLAB, in the ICE2000 section.

Look in this section:
Code:
MPLAB ICE 2000 Reference
- Limitations
-- 16-Bit Device Limitations
--- PIC18F6XXX/8XXX
---- PIC18F6722/8722 Limitations

Then look under:
Quote:
General Limitations

Also look at:
Quote:
Software Watchdog Timer can cause lock-up

There are many, many potential problems.
Laurent Chouinard



Joined: 12 Sep 2003
Posts: 43

View user's profile Send private message

PostPosted: Mon Jun 25, 2007 7:22 pm     Reply with quote

Shocked Oh my! This list is almost spelling "Do not buy this emulator" !! This is scary stuff.

So if I understand the limitation correctly, all I would have to do is to replace all calls to restart_wdt() with restart_wdt_fix() and have

Code:

void restart_wdt_fix(void) {
  restart_wdt();
  setup_wdt(WDT_OFF);
  setup_wdt(WDT_ON);
}


I could live with that. all these limitations are reeeeeeally creeping me out though. I thought Microchip's products were solid designs. I thought buying a Microchip emulator would be the best one (althouth it was also the ONLY one for this chip...)

Well, many thanks, PCM Programmer. I'll go right ahead and try that fix.
Laurent Chouinard



Joined: 12 Sep 2003
Posts: 43

View user's profile Send private message

PostPosted: Mon Jun 25, 2007 7:31 pm     Reply with quote

It works :-)
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