Question about PWM interrupts

30 Jan 2012

Hi all!

While playing a bit with the VGA generator code posted somewhere in this site, found this pwm problem. Please, can someone tell me why I don´t get pwm interrupts 4 and 6 using this code? I´m using mbed, lpcxpresso compiler (a tuned gcc) and fastlib.

Thanks in advance!

pwm setting code:

    ...
    fl_power_pwm1(FL_ON);
    fl_select_clock_pwm1(FL_CLOCK_DIV1);
    fl_pinsel(2, 1, FL_FUNC_ALT1, FL_FLOATING, FL_FLOATING);    // PWM1.2, no pullup/down
    fl_pwm_set_prescale(4);                         // 100/25 = 4
    fl_pwm_config_match(0, FL_ON, FL_ON, FL_OFF);   // interrupt, reset, !stop
    fl_pwm_set_match(0, 800);                       // 800 dot clocks
    fl_pwm_set_match(2, 704);                       // go low at 704/high again at 800
    fl_pwm_config_match(2, FL_OFF, FL_OFF, FL_OFF); // interrupt, reset, !stop
    fl_pwm_set_match(4, 48);                        // start visible line
    fl_pwm_config_match(4, FL_ON, FL_OFF, FL_OFF);  // interrupt, reset, !stop
    fl_pwm_set_match(6, 688);                       // end visible line 688-48=640
    fl_pwm_config_match(6, FL_ON, FL_OFF, FL_OFF);  // interrupt, reset, !stop
    fl_pwm_config_edges(2, FL_SINGLE_EDGE);
    fl_pwm_config_edges(4, FL_SINGLE_EDGE);
    fl_pwm_config_edges(6, FL_SINGLE_EDGE);
    fl_pwm_output_enable(2, FL_ENABLE);             // 
    fl_pwm_latch_match_all();
    fl_nvic_interrupt_set_enable(FL_NVIC_INT_PWM);  // enable PWM interrupts
    fl_pwm_timer_counter_enable(FL_ENABLE);
    fl_pwm_enable(FL_ENABLE);
    ...

//Interrupt handler

void PWM1_IRQHandler(void) {
    uint32_t regval=*FL_PWM1IR;
    if (regval & (1 << 0)) {                  //
           printf("got this one");
           *FL_PWM1IR=(regval & (1 << 0));
           }
    else if (regval & (1 << 8)) {             //start visible line
           printf("but no this");
           *FL_PWM1IR=(regval & (1 << 8));
           }
    else if (regval & (1 << 10)) {            //end visible line
           printf("but no this");
           *FL_PWM1IR=(regval & (1 << 10));
           }
}

        
30 Jan 2012

Did you tell the nvic about your IRQ handler callback?

30 Jan 2012

Rene Greiner wrote:

fl_nvic_interrupt_set_enable(FL_NVIC_INT_PWM); enable PWM interrupts

Yes I did in this sentence (please see the code):

fl_nvic_interrupt_set_enable(FL_NVIC_INT_PWM); enable PWM interrupts

Anyway, I rewrote the whole snippet using plain cmsis and it started working as planned. Maybe the fl library does not work as well with gcc? Thanks for your time.

31 Jan 2012

To bad you didn't understand my question. I meant something like fl_nvic_interrupt_software_trigger((uint)&PWM1_IRQ_Handler);

31 Jan 2012

Rene Greiner wrote:

To bad you didn't understand my question. I meant something like fl_nvic_interrupt_software_trigger((uint)&PWM1_IRQ_Handler);

Yes sorry, I´m pretty new at this chip, English is not my language, neither C is. As mentioned above the code worked once I rewrote the problematic snippet in cmsis without fl library. I suspect something in fl does not compiles well in lpcxpresso enviroment. As for fl_nvic_interrupt_software_trigger, to be honest still doesn´t undestand the need of generate a soft irq? Pwm is generating the required irqs. Maybe you meant NVIC_SetVector? I used the standard handler name, no need of that! Regards, GdS