Skip to main content
synth002
Associate
November 15, 2015
Question

Fixed.

  • November 15, 2015
  • 3 replies
  • 822 views
Posted on November 15, 2015 at 21:35

Fixed.

    This topic has been closed for replies.

    3 replies

    Tesla DeLorean
    Guru
    November 15, 2015
    Posted on November 15, 2015 at 22:59

    Looks like hours of fun, not sure I'm up for digging through register issues with you.

    Your IRQ Handler will need to clear the interrupt, with a TIM1->SR = mask otherwise it will never leave the interrupt state.

    Tips, Buy me a coffee, or three.. PayPal Venmo (See Profile) Up vote any posts that you find helpful, it shows what's working..
    synth002
    synth002Author
    Associate
    November 15, 2015
    Posted on November 15, 2015 at 23:47

    No problem, I'll get it eventually. It was just on the off chance that someone had experience in the area, one of those things that's easy when you know how, I'm sure. 

    Thanks for the tip.

    Tesla DeLorean
    Guru
    November 16, 2015
    Posted on November 16, 2015 at 02:01

    Please don't delete threads, it damages the integrity of the forum.

    From: clive1 Posted: Sunday, November 15, 2015 10:59 PM Subject: Fixed.

    Looks like hours of fun, not sure I'm up for digging through register issues with you.

    Your IRQ Handler will need to clear the interrupt, with a TIM1->SR = mask otherwise it will never leave the interrupt state. From: bush.john Posted: Sunday, November 15, 2015 9:35 PM Subject: Stmf407 pwm input capture problem

    Hello all, first post on this forum, somewhat of a total newbie, as im sure will become clear on reading my code :).

    I'm currently attempting to learn my way around the stm32f407 discovery board. At the moment I'm trying to figure out the PWM capture. In the code below I have tried to put together a very simple program, to capture some information about pulse width of an incoming signal (using the steps defined in the reference manual) and trigger an interrupt when a sample is received, which dumps any count data to output. Of course, the code runs, but no data timing data is received, and I don't have much of an idea why at this point, though I continue to work at it. I would very muchappreciate any advice offered! cheers.

    #include ''stm32f4xx.h''
    #include ''stdio.h''
    #include ''usart.c''
    #define TIM1_EN 0x01
    #define PORTC_CLOCK_EN 2
    #define PIN5 5
    /* 
    Goal of project is to sample the high pulse width of a square wave input,
    the sample will then be ouputted via UART for confirmation
    */
    int placeholder;
    void TIM1_CC_IRQHandler(void)
    {
    placeholder = TIM1->CCR2;
    }
    int main(void)
    {
    /*
    Setup PORTC PIN5 to capture the pulse width of incomming signal using TIM1 PWM input capture.
    On capture, interrupt is triggered and displays contents of TIM1_CCR2 as output via UART
    */
    RCC->AHB1ENR |=(1<<
    PORTC_CLOCK_EN
    ); //Enable PORTC clock
    RCC->APB2ENR |=(TIM1_EN); //Enable TIM1 clock
    GPIOC->AFR[0] |=(1<<
    20
    ); //Assign PORTC Pin5 to TIM1
    TIM1->CR1 |=0x01; //Enable count on TIM1
    TIM1->CCMR1 |=(0x01); //Set CC1S bits to 01 
    TIM1->CCER &=~(0x0A); //Set CC1P and CC1NP bits to 0
    TIM1->CCMR1 |=(1<<
    9
    ); //Set CC2S bits to 10
    TIM1->CCER |=(0x0A0); //Set CC2P and CC2NP bits to 1
    TIM1->SMCR |=(0x54); //Set SMS bits to 100 & TS bits to 101
    TIM1->CCER |=(0x011); //Enable captures
    TIM1->DIER |=(1<<
    1
    ); //Enable capture compare interrupt 1
    NVIC->ISER[0] |=(1<<27); //Enable interrupt for TIM1_CC
    config_UART2(); //Enable USART output 
    placeholder =0;
    while(1)
    {
    printf(''value recieved %d 
     
    '', placeholder);
    }
    }

    Tips, Buy me a coffee, or three.. PayPal Venmo (See Profile) Up vote any posts that you find helpful, it shows what's working..