Help with USB Serial on an 18F4550

An area to discuss 8-bit PIC specific problems and examples

Moderator: Benj

Post Reply
TSMroz
Posts: 15
Joined: Wed Apr 19, 2017 2:54 pm
Been thanked: 2 times
Contact:

Help with USB Serial on an 18F4550

Post by TSMroz »

Hi, I realize that USB Slave is currently not working in V7, but is the USB serial component stable? Here's what I'm trying to do in a separate simple test case:

I've basically replicated the LED blink program in a loop (turn <any> port bit on, add a delay, turn same port bit back off, add another delay). My delays are both 100 uS. The program works as expected and my pulse widths are correct.

Now, if I add the USB_Serial component to my project, everything still works fine. But, if I drag and drop the "USB_Serial::Initialise" macro to the top of my program (yes, outside the loop) and run it, both my negative and positive pulse widths are no longer stable. They randomly vary between ~106 (expected) up to 122 or so. If I disable the Initialise, the signal goes back to being stable again. Likewise, if leave in the Initialise, but simply remove the USB cable, they also go back to being stable.

I've tried both 4Mhz and 16Mhz oscillators with no change. Problem is, I need both USB connectivity and the stable GPIO pulse widths for my project. The PW variances are causing random misreads on my other port bits due to the mistiming. Maybe there's something I'm overlooking.


Thanks

kersing
Valued Contributor
Valued Contributor
Posts: 2045
Joined: Wed Aug 27, 2008 10:31 pm
Location: Netherlands
Has thanked: 553 times
Been thanked: 1081 times
Contact:

Re: Help with USB Serial on an 18F4550

Post by kersing »

The USB components all use interrupts to service the USB protocol. Those interrupts will cause the observed timing variations but can not be avoided without violating USB timing requirements (making the device drop of the USB bus). For exact timing you will need to use hardware PWM.
“Integrity is doing the right thing, even when no one is watching.”

― C.S. Lewis

TSMroz
Posts: 15
Joined: Wed Apr 19, 2017 2:54 pm
Been thanked: 2 times
Contact:

Re: Help with USB Serial on an 18F4550

Post by TSMroz »

Thank you, appreciate the response. I was wondering if it was something along those lines and unavoidable. I haven't learned the hardware PWM side yet.. So with that I can create single control pulses in the sub-millisecond ranges? Great if so. I'm more concerned with the timing of my entire port B bus readings that I need to perform, but will tackle that after I figure out the PWM stuff. Thanks again!

Oh, I figure there's probably another way of using the timers or an interrupt or both to create accurate pulses as well? I'm still trying to figure that out as well. My single port bit pulse width actually needs to be a single 34 uS pulse, when called, to toggle another part of my circuit. That's the most critical one. The others don't really need to be as exact.

User avatar
Benj
Matrix Staff
Posts: 15312
Joined: Mon Oct 16, 2006 10:48 am
Location: Matrix TS Ltd
Has thanked: 4803 times
Been thanked: 4314 times
Contact:

Re: Help with USB Serial on an 18F4550

Post by Benj »

I realize that USB Slave is currently not working in V7
We are currently working on the USB side of things and hope to have things back up and running well soon.

And yes while we are doing this we are also looking into USB device support for the PIC32 and STm32 devices.

TSMroz
Posts: 15
Joined: Wed Apr 19, 2017 2:54 pm
Been thanked: 2 times
Contact:

Re: Help with USB Serial on an 18F4550

Post by TSMroz »

Great news. Thanks again!

Post Reply