ADuCRF101 1kHz interrupt

Hello, sorry for asking a very basic question. Can someone give me a piece of sample code in C language of generating 1 kHz interrupt in ADuCRF101? The part is operating off 16MHz system clock frequency. I need to trigger an off-chip event at 1 kHz. I guess I might use the GP timer freely runs counting, when overflow, it should trigger an interrupt to trigger the external event... Unfortunately I'm not familiar with embedded C coding. So it'll be great if someone can provide a sample code. thanks in advance.

  • 0
    •  Analog Employees 
    on Nov 3, 2011 6:29 PM

    The ADuCRF101 can generate periodic digital wave form, using the PWM or as you suggested, using a timer overflow.

    Is the interrupt of the other component edge triggered or level triggered, active high or low, failing edge or rising edge?

  • The operation of 1kHz interrupt is to toggle the previous P4.2 logic status (high to low, low to high).This is to generate some pulse output.

  • 0
    •  Analog Employees 
    on Nov 7, 2011 4:43 PM

    There are 2 options to toggle P4.2 at 1kHz.

    Using a general purpose timer, for example timer 0. the pin P4.2 is toggled in the timer interrupt handler.

    /* timer option, positive width = negative width, controlled in T0LD and T0CON */
      GP4CON = GP4CON_CON2_GPIO;                 // P4.2 configured as GPIO
      GP4OEN = GP4OEN_OEN2;                           // P4.2 configured as output
      T0LD = 0x1F;                                                  // period of 1ms
      T0CON = 0x1A;                                               // clock = UCLK
      ISER0 = 0x1000;                                             // enable timer 0 interrupt

    void GP_Tmr0_Int_Handler ()
    {
      GP4TGL = GPTGL_TGL2;                                // toggle P4.2
      T0CLRI = 1;                                                    // clear timer 0 interrupt
    }

    A neater option is to use the PWM, where P4.2 is configured in mode 2, or as PWM output. P4.2 is the high side of pair 1.

    /* PWM option */
      GP4CON = GP4CON_CON2_PWM2;               // high side of pair 1
      PWM1LEN = 0x1F4;                                       // control the period: rising edge of low side
      PWM1COM0 = 0x1F4;                                    // controls time between rising edge of low side and rising edge of high side
      PWM1COM1 = 0xFA;                                     // controls time between rising edge of low side and failing edge of high side 
      PWMCON0 = 0x105;                                      // start PWM in normal mode. PWM clock is UCLK/32

    This method does not involved cortex intervention once the PWM is configured.