Skip to main content
sballano
Associate
January 8, 2009
Question

Problems using USB and PWM Input

  • January 8, 2009
  • 5 replies
  • 1481 views
Posted on January 08, 2009 at 15:51

Problems using USB and PWM Input

    This topic has been closed for replies.

    5 replies

    sballano
    sballanoAuthor
    Associate
    May 17, 2011
    Posted on May 17, 2011 at 12:58

    Hi,

    I'm very new to the STM32, I have an Olimex Header Board (STM32F103RB 64pin). As I'm starting, I'm testing all the ports I will have to use for my project, that includes using a virtual COM port to communicate with the device, 4 PWM Inputs, 4 PWM Outputs, 6 ADC Inputs and some digital I/O.

    All of the above has worked well together, except for the PWM Inputs. When I combine the code of the PWM Input example with the Virtual COM example (the one modified by lanchon, that can be downloaded from this forum) the VCOM port stops working, I don't know the reason. Is there any incompatibility in using the USB port and the TIM2 (or TIM3) as Input Capture together??

    If I don't enable the TIM2 clock, the usb port works as expected, but of course, I can't read the PWM, and if I enable the TIM2 or TIM3 the USB don't work (so I can't communicate with the device to read the values). This is what my linux says in this case:

    usb 2-6: new full speed USB device using ohci_hcd and address 74

    usb 2-6: device descriptor read/64, error -62

    usb 2-6: device descriptor read/64, error -62

    When the USB works ok this is what I get:

    usb 2-6: new full speed USB device using ohci_hcd and address 70

    usb 2-6: configuration #1 chosen from 1 choice

    cdc_acm: This device cannot do calls on its own. It is no modem.

    cdc_acm 2-6:1.0: ttyACM0: USB ACM device

    I'm attaching only the main.c, if all code is needed just ask me.

    Thanks,

    Sergio

    [ This message was edited by: sballano on 05-01-2009 22:25 ]

    [ This message was edited by: sballano on 05-01-2009 22:31 ]

    sballano
    sballanoAuthor
    Associate
    May 17, 2011
    Posted on May 17, 2011 at 12:58

    Quote:

    1) PA1 can be placed into alternate function as Tim2_Ch2. Is this what you're doing to read/decode the PWM input signal?

    Yes, that's what I'm doing, I configured TIM2 CH2 to read a PWM signal.

    Quote:

    2) Have you insured that positive/negative transitions do not exceed STM32 device input specifications?

    well, right now I'm at home and I don't have an oscilloscope here, but I'm using a 0-2.5V 50Hz PWM signal.

    Quote:

    3) Have you a 2nd eval board to try & duplicate your results?

    No, it's my first stm device

    Quote:

    4) Rather than apply pwm - try constant levels of both, ''low & high.'' Do either of these static conditions cause the problem?

    applying HIGH causes the problem, GND don't

    Quote:

    5) Change the rate of the pwm - see if these effect your problem.

    I have tried with 50 and 500Hz, same results, I have the TIM2 = 32 so it should be able to read signals starting at 34Hz

    Quote:

    All above assumes you've read latest errata - looking for Tim2 & USB issues...

    I didn't do it before posting, but I have read it now and does not make any reference with my problem or any TIM2 and USB trouble

    I'm still working to solve the problem and I have advanced a bit, I forgot to fill the TIM2_IRQHandler so I didn't clear the interrupt when it was needed. Now the programs works well even if I put the pwm signal in the pin. But it hangs up when I try to read the DutyCycle and Frequency values... I will try to figure why

    I think this is just what happens when you try to merge a couple of examples without actually understanding them... I will keep working on it :)

    Thanks,

    Sergio

    jj_it
    Associate II
    May 17, 2011
    Posted on May 17, 2011 at 12:58

    1) PA1 can be placed into alternate function as Tim2_Ch2. Is this what you're doing to read/decode the PWM input signal?

    2) Have you insured that positive/negative transitions do not exceed STM32 device input specifications?

    3) Have you a 2nd eval board to try & duplicate your results?

    4) Rather than apply pwm - try constant levels of both, ''low & high.'' Do either of these static conditions cause the problem?

    5) Change the rate of the pwm - see if these effect your problem.

    All above assumes you've read latest errata - looking for Tim2 & USB issues...

    sballano
    sballanoAuthor
    Associate
    May 17, 2011
    Posted on May 17, 2011 at 12:58

    well, this thing is getting weird...

    I found out that if I disconnect the signal I was PWM injecting to the PA.01 the USB works right, it's only when I put the signal when all crashes... any ideas?

    Thanks,

    Sergio

    [ This message was edited by: sballano on 06-01-2009 21:05 ]

    sballano
    sballanoAuthor
    Associate
    May 17, 2011
    Posted on May 17, 2011 at 12:58

    Hi all,

    Finally, I have figured out what the exact problem is, but still I don't know how to solve it, so some help would be appreciated :D

    In the PWM example, the Frequency and the DutyCycle are calculated in the Interrupt Handler function, like this:

    Code:

    void TIM2_IRQHandler(void)

    {

    /* Clear TIM2 Capture compare interrupt pending bit */

    TIM_ClearITPendingBit(TIM2, TIM_IT_CC2);

    /* Get the Input Capture value */

    IC2Value = TIM_GetCapture2(TIM2);

    if (IC2Value != 0)

    {

    /* Duty cycle computation */

    DutyCycle = (TIM_GetCapture1(TIM2) * 100) / IC2Value;

    /* Frequency computation */

    Frequency = 2250000 / IC2Value; //72000000

    }

    else

    {

    DutyCycle = 0;

    Frequency = 0;

    }

    }

    The problem comes only when I try to make a printf of the Frequency or DutyCycle vars. I remind I'm using a vcom modified example (by lanchon) which redirects the output of the printf function through the virtual port com terminal.

    I have tested that I can operate whit the vars, for example I can tell if they are greather than 50, but I can't print their values... any clues why??

    Thanks,

    Sergio