SparkFun Forums 

Where electronics enthusiasts find answers.

Everything ARM and LPC
By sns22
#168276
Hi.

I am not able to understand the functionality of some PWM registers to be used in capture mode.

I have been trying to interface the PWM based max6672 sensor with the PWM capture pin. I want to read the both the low time and high time of the PWM pulse. I am recieving an interrupt when the PWm input is received. But some how I am not able to calculate the rise and fall time correctly. I need this info to calculate the temperature of the sensor.

PCLKSEL0_bit.PCLK_PWM0 = 1; Can this be also used to set the pclk divisor for the capture input or is it only for PWM funactionality.

I want to use this PCAP0.0 pin as a counter. In the datasheet we have to set the
PWM0CTCR_bit.CM = 0;
PWM0CTCR_bit.CIS = 1; to enable the rising edge counter mode one needs to set this pin.

And if the counter mode is enabled the pins @CCR as must be 000 as set. ref UM10237 datasheet pg 643

PWM0CCR_bit.CAP0RE = 0; //capture of rising edge
PWM0CCR_bit.CAP0FE = 0; //disable falling edge capture
PWM0CCR_bit.CAP0INT = 0; //enable interrupt rising edge

But when I do this setting i am not receiving an interrupt from the sensor.

But if I set the PCAP0.0 pin as a timer
PWM0CTCR_bit.CM = 0;
PWM0CTCR_bit.CIS = 0; and CCR for rising edge 0x5 and falling edge 0x6

PWM0CCR_bit.CAP0RE = 1; //capture of rising edge
PWM0CCR_bit.CAP0FE = 0; //disable falling edge capture
PWM0CCR_bit.CAP0INT = 1; //enable interrupt rising edge 0x5
later I change in the interrupt to 0x6 for falling edge I am able to detect the interrupt but the counter doesnt have the correct values.

Is there something wrong in my understanding of the code?Can someone clear this for me?

below are interrupt and main code
Code: Select all
void Capture0IntrHandler(void)
{
  
  if ((PWM0IR == 0x10)){
    if((PWM0CCR_bit.CAP0RE  == 1)){  //low to high transition    rising edge
      register uint32_t pwm0cr0 = PWM0CR0;
      period = pwm0cr0 - rising_edg;
      rising_edg = pwm0cr0;
      PWM0CCR = 0x6;
      PWM0_Done =0;
    }else{
      register uint32_t pwm0cr01 = PWM0CR0;
      duty = pwm0cr01 - rising_edg;  
      falling_edg = pwm0cr01;
      //PWM0CTCR = 0x1;      
       PWM0CCR = 0x5;
       PWM0_Done =1;
    }
    }
  PWM0IR=0xFF; //Reset the interrupt*/ 
  VICADDRESS = 0;
}
Code: Select all
void init_timer(void)   	// Timer 0 used as a counter
{  
  // PWM PCAP0.0 Pin: P1.12
 //  pclk = cclk/2 = 30MHz (cclk=ARM7 core clock)

    unsigned int IRQ_priority= 0x1;   // '0' = highest, '0xF' = lowest IRQ priority
     
    //PCONP_bit.PCTIM0 =  1;
    PCONP_bit.PCPWM0 |=0; 
    PCLKSEL0_bit.PCLK_PWM0 = 2; //pclk is set to  2 = pclk/2 = 36 MHz or 30MHz
    PINSEL2   = 0x03000000;         //PWM PCAP0.0 Pin: P1.12                            //1 = pclk = 60 MHz or 72MHz
    //PCLKSEL0_bit.PCLK_TIMER0 = 2; //pclk is set to  pclk/2 = 36 MHz or 30MHz
  
    //RISING EDGE CAPTURE
    
    PWM0TCR_bit.CR = 0; //disable PWM counter reset
    PWM0TCR_bit.CR = 1; //Reset PWM counter 
    PWM0TCR_bit.CR = 0; //disable PWM counter reset
    
    PWM0CCR_bit.CAP0RE  = 1;   //capture of rising edge
    PWM0CCR_bit.CAP0FE  = 0;   //disable falling edge capture 
    PWM0CCR_bit.CAP0INT = 1; //enable interrupt rising edge
    
    PWM0CTCR_bit.CM = 0;        //PWM0 is set in timer mode 
    PWM0CTCR_bit.CIS = 0;
    
    //36Mhz
    PWM0PCR =35;              //no external interrupt   
    PWM0PR = 17;           //resolution of 1 us for a 60MHz cclk = pclk
    PWM0IR = 0xFF;         //reset the interrupts
   
  VIC_SetVectoredIRQ(Capture0IntrHandler, IRQ_priority, VIC_PWM01);  // setup PWM IRQ
  PWM0TCR_bit.CE =1; //enable the PWM Capture timer 
}
Regards
Sns