0

I'm working on a project where I want to ramp the pwm duty cycle from 0 to 50%. My period is 16000 counts or 1ms (16MHz default timer count). For some reason, instead of updating the duty cycle each period, it updates it much slower. I wonder if it's because I'm calculating the new duty cycle within the timer interrupt? Here's what I'm using:

void TIM4_IRQHandler()
{
if (TIM_GetITStatus(TIM4, TIM_IT_Update) != RESET)
{
    TIM_ClearITPendingBit(TIM4, TIM_IT_Update);

    if (loop <= 8000) {
        TIM4 -> CCR1 = CCR_i;
        uint16_t y = CCR_i;
        CCR_i = y + 1;
        int x = loop;
        loop = x + 1;
    }
    if (loop == 8001) {
        TIM4 -> CCR1 = 0;
        uint16_t x = CCR_i;
        CCR_i = x + 1;
        int c = loop;
        loop = c + 1;
    }

    if (loop > 8001) {

        int t;
        for(t = 0; t < 10; t++){
            // wait
        }

        GPIO_SetBits(GPIOG, GPIO_Pin_8);
        //Stop2();
        TIM_ITConfig(TIM4, TIM_IT_Update, DISABLE);
        NVIC_DisableIRQ(TIM4_IRQn);
        }
    }
 }
oboist B
  • 1
  • 4

1 Answers1

0

blast, it looks like I was being silly - the timer is doing exactly what I want it to - it just takes 8 seconds with a period of 1ms to ramp to a pulsewidth of 500us adding 62.5ns per period.

oboist B
  • 1
  • 4