2009-01-08 06:51 AM
Problems using USB and PWM Input
2011-05-17 03:58 AM
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 ]2011-05-17 03:58 AM
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 ]2011-05-17 03:58 AM
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...2011-05-17 03:58 AM
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 deviceQuote:
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'tQuote:
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 34HzQuote:
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, Sergio2011-05-17 03:58 AM
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