Loading ...
Sorry, an error occurred while loading the content.
 

Need help activating COP

Expand Messages
  • Stephan
    Hi all, I am trying to get the COP to work on an ADAPT11C24DX without much success. I can t seem to program CONFIG properly. sometimes I get it to change to
    Message 1 of 3 , Oct 31, 2011
      Hi all,
      I am trying to get the COP to work on an ADAPT11C24DX without much success. I can't seem to program CONFIG properly. sometimes I get it to change to CONFIG = 0x0F, but I don't explicitly set it to that value. Is this just an erase? Missing is an interrupt that increments "ticks" every 1/16 of a second.

      The timer seems to be fine, as i get LED flashes that correspond to the length I set them to.

      Here is my code.

      Thanks in advance

      void __premain ()
      {
      // THe MCU Clock "E" is the Crystal / 4
      // 8 MHz crystal for the Adapt11C24DX prototyping board

      TMSK2 = PR1; // counter clock = E/8 = (8MHz xtal/4)/8 = 250 kHz
      BPROT = 0x0F; // disable CONFIG protection
      OPTION = CSEL+IRQE+DLY+CME+CR1+CR0;

      // end of time critical registers

      PACTL = PEDGE;

      TCTL1 = 0x00; // nothing connected to output pins

      TMSK1 = OC1I; // TOC2 interrupt active

      // SETUP VALUES FOR SPI INTERFACE
      PORTD = 0x2F;
      DDRD = 0x38;
      SPCR = SPE+MSTR+SPR0; // Protoboard @ 8MHz

      //-------------------------------------------------------------------
      int main(void)
      {
      volatile unsigned int timeout;

      // initialize and start the timer
      TOC1 = TCNT + ONESIXTEENTH; // set next interrupt in 1/16Sec
      ticks = 0x0000; // of the clock
      TFLG1 = TFLG1 | OC1F; // set the flag to clear it
      TMSK1 = OC1I; // TOC1 interrupt active
      asm("cli"); // enable interrupts

      // Indicate current status of the CONFIG register
      DDRC = 0xFF; // Set Port C as output for testing
      PORTC = CONFIG; // Display current status of CONFIG

      if( CONFIG == (NOSEC + NOCOP) )
      {
      // flash LED 5 times, 1 sec per action
      TEMP = 0;
      do {
      LED_DARK;
      TEMP += Sec01;
      while( ticks < TEMP );
      LED_LITE;
      TEMP += Sec01;
      while( ticks < TEMP );
      } while( TEMP < Sec10 );

      LED_DARK;
      PORTC = 0xFF; // indicate abouit to change CONFIG
      /*
      According to the data sheet,
      To Change the value in the CONFIG register, complete this
      proceedure.
      1. Erase the CONFIG register
      2. Program the new value into the CONFIG address
      3. Initiate RESET
      */
      // These necessary steps already taken in the premain()
      // BPROT.PTCON CONFIG protection disabled in premain()
      OPTION = OPTION | CSEL;

      // ERASE
      TCNT = 1; // TCNT updates at 250KHz = 1/4uS
      timeout = 2750; // delay 10mS 1/250KHz = 4uS, 11mS/4uS = 2750
      PPROG = BYTE | ERASE | EELAT; // prime for writing
      CONFIG = NOSEC; // write anything to erase CONFIG
      PPROG = BYTE | ERASE | EELAT | EEPGM; // ERASE!
      while( TCNT < timeout ); // delay 11 mS
      PPROG = BYTE | ERASE | EELAT; // Turn off voltage

      // WRITE
      TCNT = 1;
      PPROG = EELAT; // prime for writing
      CONFIG = NOSEC; // clear NOCOP to enable COP
      PPROG = EELAT | EEPGM; // WRITE!
      while( TCNT < timeout ); // delay 11 mS
      PPROG = EELAT; // Turn off voltage
      PPROG = 0x00; // reset

      BPROT = 0x1F; // enable protection
      OPTION = OPTION & (~CSEL); //put it back where it was
      LED_LITE;
      PORTC = 0x00;
      ticks = 0;
      while( ticks < Sec03 );
      _start();
      }

      else
      {
      // flash rapidly as a sign of success
      while(1)
      {
      COPRST = 0x55; // arm the COP timer clearing mechanism
      COPRST = 0xAA; // clear the COP timer
      TCNT = 0;
      ticks = 0;
      LED_LITE;
      while( ticks < 0x0004 );
      LED_DARK;
      while( ticks < 0x0008 );
      }
      }

      return 0;
      }
    • Ben Morse
      Stephan, Here is some documentation about the COP Timer on a Mosaic PDQ Board. This board uses the MC9S12A512/DP512 chip. I don t know if it will help you,
      Message 2 of 3 , Nov 1, 2011
        Stephan,
        Here is some documentation about the COP Timer on a Mosaic PDQ Board.  This board uses the MC9S12A512/DP512 chip.  I don't know if it will help you, but it may be worth a read:


        -Ben with Mosaic Industries


        On Mon, Oct 31, 2011 at 2:07 PM, Stephan <stephan_laska@...> wrote:
         

        Hi all,
        I am trying to get the COP to work on an ADAPT11C24DX without much success. I can't seem to program CONFIG properly. sometimes I get it to change to CONFIG = 0x0F, but I don't explicitly set it to that value. Is this just an erase? Missing is an interrupt that increments "ticks" every 1/16 of a second.

        The timer seems to be fine, as i get LED flashes that correspond to the length I set them to.

        Here is my code.

        Thanks in advance

        void __premain ()
        {
        // THe MCU Clock "E" is the Crystal / 4
        // 8 MHz crystal for the Adapt11C24DX prototyping board

        TMSK2 = PR1; // counter clock = E/8 = (8MHz xtal/4)/8 = 250 kHz
        BPROT = 0x0F; // disable CONFIG protection
        OPTION = CSEL+IRQE+DLY+CME+CR1+CR0;

        // end of time critical registers

        PACTL = PEDGE;

        TCTL1 = 0x00; // nothing connected to output pins

        TMSK1 = OC1I; // TOC2 interrupt active

        // SETUP VALUES FOR SPI INTERFACE
        PORTD = 0x2F;
        DDRD = 0x38;
        SPCR = SPE+MSTR+SPR0; // Protoboard @ 8MHz

        //----------------------------------------------------------
        int main(void)
        {
        volatile unsigned int timeout;

        // initialize and start the timer
        TOC1 = TCNT + ONESIXTEENTH; // set next interrupt in 1/16Sec
        ticks = 0x0000; // of the clock
        TFLG1 = TFLG1 | OC1F; // set the flag to clear it
        TMSK1 = OC1I; // TOC1 interrupt active
        asm("cli"); // enable interrupts

        // Indicate current status of the CONFIG register
        DDRC = 0xFF; // Set Port C as output for testing
        PORTC = CONFIG; // Display current status of CONFIG

        if( CONFIG == (NOSEC + NOCOP) )
        {
        // flash LED 5 times, 1 sec per action
        TEMP = 0;
        do {
        LED_DARK;
        TEMP += Sec01;
        while( ticks < TEMP );
        LED_LITE;
        TEMP += Sec01;
        while( ticks < TEMP );
        } while( TEMP < Sec10 );

        LED_DARK;
        PORTC = 0xFF; // indicate abouit to change CONFIG
        /*
        According to the data sheet,
        To Change the value in the CONFIG register, complete this
        proceedure.
        1. Erase the CONFIG register
        2. Program the new value into the CONFIG address
        3. Initiate RESET
        */
        // These necessary steps already taken in the premain()
        // BPROT.PTCON CONFIG protection disabled in premain()
        OPTION = OPTION | CSEL;

        // ERASE
        TCNT = 1; // TCNT updates at 250KHz = 1/4uS
        timeout = 2750; // delay 10mS 1/250KHz = 4uS, 11mS/4uS = 2750
        PPROG = BYTE | ERASE | EELAT; // prime for writing
        CONFIG = NOSEC; // write anything to erase CONFIG
        PPROG = BYTE | ERASE | EELAT | EEPGM; // ERASE!
        while( TCNT < timeout ); // delay 11 mS
        PPROG = BYTE | ERASE | EELAT; // Turn off voltage

        // WRITE
        TCNT = 1;
        PPROG = EELAT; // prime for writing
        CONFIG = NOSEC; // clear NOCOP to enable COP
        PPROG = EELAT | EEPGM; // WRITE!
        while( TCNT < timeout ); // delay 11 mS
        PPROG = EELAT; // Turn off voltage
        PPROG = 0x00; // reset

        BPROT = 0x1F; // enable protection
        OPTION = OPTION & (~CSEL); //put it back where it was
        LED_LITE;
        PORTC = 0x00;
        ticks = 0;
        while( ticks < Sec03 );
        _start();
        }

        else
        {
        // flash rapidly as a sign of success
        while(1)
        {
        COPRST = 0x55; // arm the COP timer clearing mechanism
        COPRST = 0xAA; // clear the COP timer
        TCNT = 0;
        ticks = 0;
        LED_LITE;
        while( ticks < 0x0004 );
        LED_DARK;
        while( ticks < 0x0008 );
        }
        }

        return 0;
        }


      • Stephan Laska
        Thanks for the reply Ben, I have found some of my problem. The code TCNT = 1; // TCNT updates at 250KHz = 1/4uS timeout = 2750; // delay 10mS
        Message 3 of 3 , Nov 2, 2011
          Thanks for the reply Ben,

          I have found some of my problem.

          The code
          TCNT = 1; // TCNT updates at 250KHz = 1/4uS
          timeout = 2750; // delay 10mS 1/250KHz = 4uS, 11mS/4uS = 2750
          ......
          while( TCNT < timeout ); // delay 11 mS
           
          wasn't working as expected.
          I changed this to

          void ten_mS_delay( void )
          {
            TOC4 = TCNT + 2500;   // set to overflow in 10mS
            TFLG1 = TFLG1 | OC4F; // the manual says set the flag to clear it
            while( (TFLG1 & OC4F) != OC4F ); // wait for bit to be set
          }

          and this gave me the 10mS needed to properly write to the EEPROM

          Regards,
          Stephan

          From: Ben Morse <bjmorse@...>
          To: gnu-m68hc11@yahoogroups.com
          Sent: Wednesday, November 2, 2011 12:50 AM
          Subject: Re: Need help activating COP

           
          Stephan,
          Here is some documentation about the COP Timer on a Mosaic PDQ Board.  This board uses the MC9S12A512/DP512 chip.  I don't know if it will help you, but it may be worth a read:

          http://mosaic-industries.com/embedded-systems/10-sbcs/pdqboard/users-guide/120_failure#the-cop-watchdog-timer-and-clock-monitor

          -Ben with Mosaic Industries


          On Mon, Oct 31, 2011 at 2:07 PM, Stephan <stephan_laska@...> wrote:
           
          Hi all,
          I am trying to get the COP to work on an ADAPT11C24DX without much success. I can't seem to program CONFIG properly. sometimes I get it to change to CONFIG = 0x0F, but I don't explicitly set it to that value. Is this just an erase? Missing is an interrupt that increments "ticks" every 1/16 of a second.

          The timer seems to be fine, as i get LED flashes that correspond to the length I set them to.

          Here is my code.

          Thanks in advance

          void __premain ()
          {
          // THe MCU Clock "E" is the Crystal / 4
          // 8 MHz crystal for the Adapt11C24DX prototyping board

          TMSK2 = PR1; // counter clock = E/8 = (8MHz xtal/4)/8 = 250 kHz
          BPROT = 0x0F; // disable CONFIG protection
          OPTION = CSEL+IRQE+DLY+CME+CR1+CR0;

          // end of time critical registers

          PACTL = PEDGE;

          TCTL1 = 0x00; // nothing connected to output pins

          TMSK1 = OC1I; // TOC2 interrupt active

          // SETUP VALUES FOR SPI INTERFACE
          PORTD = 0x2F;
          DDRD = 0x38;
          SPCR = SPE+MSTR+SPR0; // Protoboard @ 8MHz

          //----------------------------------------------------------
          int main(void)
          {
          volatile unsigned int timeout;

          // initialize and start the timer
          TOC1 = TCNT + ONESIXTEENTH; // set next interrupt in 1/16Sec
          ticks = 0x0000; // of the clock
          TFLG1 = TFLG1 | OC1F; // set the flag to clear it
          TMSK1 = OC1I; // TOC1 interrupt active
          asm("cli"); // enable interrupts

          // Indicate current status of the CONFIG register
          DDRC = 0xFF; // Set Port C as output for testing
          PORTC = CONFIG; // Display current status of CONFIG

          if( CONFIG == (NOSEC + NOCOP) )
          {
          // flash LED 5 times, 1 sec per action
          TEMP = 0;
          do {
          LED_DARK;
          TEMP += Sec01;
          while( ticks < TEMP );
          LED_LITE;
          TEMP += Sec01;
          while( ticks < TEMP );
          } while( TEMP < Sec10 );

          LED_DARK;
          PORTC = 0xFF; // indicate abouit to change CONFIG
          /*
          According to the data sheet,
          To Change the value in the CONFIG register, complete this
          proceedure.
          1. Erase the CONFIG register
          2. Program the new value into the CONFIG address
          3. Initiate RESET
          */
          // These necessary steps already taken in the premain()
          // BPROT.PTCON CONFIG protection disabled in premain()
          OPTION = OPTION | CSEL;

          // ERASE
          TCNT = 1; // TCNT updates at 250KHz = 1/4uS
          timeout = 2750; // delay 10mS 1/250KHz = 4uS, 11mS/4uS = 2750
          PPROG = BYTE | ERASE | EELAT; // prime for writing
          CONFIG = NOSEC; // write anything to erase CONFIG
          PPROG = BYTE | ERASE | EELAT | EEPGM; // ERASE!
          while( TCNT < timeout ); // delay 11 mS
          PPROG = BYTE | ERASE | EELAT; // Turn off voltage

          // WRITE
          TCNT = 1;
          PPROG = EELAT; // prime for writing
          CONFIG = NOSEC; // clear NOCOP to enable COP
          PPROG = EELAT | EEPGM; // WRITE!
          while( TCNT < timeout ); // delay 11 mS
          PPROG = EELAT; // Turn off voltage
          PPROG = 0x00; // reset

          BPROT = 0x1F; // enable protection
          OPTION = OPTION & (~CSEL); //put it back where it was
          LED_LITE;
          PORTC = 0x00;
          ticks = 0;
          while( ticks < Sec03 );
          _start();
          }

          else
          {
          // flash rapidly as a sign of success
          while(1)
          {
          COPRST = 0x55; // arm the COP timer clearing mechanism
          COPRST = 0xAA; // clear the COP timer
          TCNT = 0;
          ticks = 0;
          LED_LITE;
          while( ticks < 0x0004 );
          LED_DARK;
          while( ticks < 0x0008 );
          }
          }

          return 0;
          }




        Your message has been successfully submitted and would be delivered to recipients shortly.