Problem with Timer45 PIC32MX

Discussion in 'Embedded Systems and Microcontrollers' started by cesroc, Dec 20, 2012.

  1. cesroc

    Thread Starter New Member

    Dec 20, 2012
    Hello, I'm new in this forum and I hope someone can help me.
    I'm using a PIC32MX to measure a PWM. I'm working with a function generator that gives me 450KHz wave. My period is 2.2us and I work with 20%. It means my pulse has a high edge around 444ns and my low edge around 1.77us.
    I have an interrupt, change notification, and I use a timer45 mode 32bits to measure the time in high and low edge when my change notification happens. Every 100ms I send the time measured via CAN.
    When I check my message with PCAN-Explorer I see 500ns and not 444ns for high and 1.2us and not 1.77us for low. My questions are: am I doing something wrong with the timer45? How should it be the timer45 configuration? How can I have more accuracy? Can I measure this fast with PIC32MX?

    I'm using 10MHz oscilator and my timer45 configuration is:

    Code ( (Unknown Language)):
    2. #define T45_CONFIG     ( T4_ON | T4_IDLE_CON | T4_GATE_OFF | T4_PS_1_1 | T4_32BIT_MODE_ON | T4_SOURCE_INT )  
    3.   #define T45_INT_CONFIG ( T45_INT_ON | T45_INT_PRIOR_1 | T45_INT_SUB_PRIOR_0 )  
    4.   #define T45_PERIOD     0xFFFFFFFF
    Thanks in advance
    I hope someone can help me
  2. JohnInTX


    Jun 26, 2012
    Its hard to tell from what you've provided but for measuring times like this, I would suggest using a capture function with the timer. After the IRQ-on-change, it takes time to service the IRQ and read the timer. All the while, the timer is running past the value it had at the IRQ, adding to the error.