Dealing with noise generated by sending data over USB

Status
Not open for further replies.

yeahtuna

Well-known member
I'm struggling to get rid of some noise that is creeping into analogRead() measurements in a sensitive analog circuit based on a custom Teensy 3.2 board.

After thorough investigation, I find that the noise is generated when data is sent over the USB.

I determined this by adding a function to the usb_tx method inside usb_dev.c that zero's out an ellapsedMicros timer. I find that the noise always comes between 0 - 1200 microsecond after the call to usb_tx.

1. Is there a hardware solution to my problem? Can I put an extra cap somewhere to minimize the noise?

2. Assuming there's no hardware solution, is there a better place for me to zero my timer than the usb_tx method? 0-1200 is not bad, but if I could get it in the range of 0-300 microseconds, I'd be much happier.

Here's a quick pic of the power section of my board. The regulator is in the top right hand corner. The USB connector is just barely visible in the bottom left. The other regulator is for a DC barrel connector so the device can be powered without USB. The issue is not with my custom board as the noise is also apparent with an off-the-shelf Teensy 3.2.

power.png
 
Not suggesting a solution - but to confirm - what if went out UART for a test? Can you get the same data out fast enough to let it run without triggering USB I/O on available pins - to a second Teensy to ECHO out its USB or UART<>USB adapter? Then with and without USB attached and ext power you could confirm.

The Teensy got VGA support - when USB was used - not sure now of specifics without finding that thread - it was showing screen draw jitter - but that may have been a timing bus contention conflict. It didn't involve going RAW_HID - but wondering if that would change how the data is processed out and effect on the processor.

The large window might vary across 1.2 ms because it might send immediately … or after 1ms wait if not a full buffer? Does it change with send_now? Or padding all sends to 64 bytes?
 
Not suggesting a solution - but to confirm - what if went out UART for a test? Can you get the same data out fast enough to let it run without triggering USB I/O on available pins - to a second Teensy to ECHO out its USB or UART<>USB adapter? Then with and without USB attached and ext power you could confirm.

If I don't send the RAW_HID data, there is no noise (at least no bad spikes that make me want to rip my hair out). I indeed test this by sending out data over a hardware serial port as well.

The large window might vary across 1.2 ms because it might send immediately … or after 1ms wait if not a full buffer? Does it change with send_now? Or padding all sends to 64 bytes?

The variation is absolutely because of waiting for the buffer, so that's why I was wondering if there was a better place to sync my timer that the usb_tx method. Where in the code is that data actually being sent? I will try adding send_now()--good suggestion.


EDIT: Looks like there is no send_now() for RawHID
 
If I don't send the RAW_HID data, there is no noise (at least no bad spikes that make me want to rip my hair out). I indeed test this by sending out data over a hardware serial port as well.



The variation is absolutely because of waiting for the buffer, so that's why I was wondering if there was a better place to sync my timer that the usb_tx method. Where in the code is that data actually being sent? I will try adding send_now()--good suggestion.


EDIT: Looks like there is no send_now() for RawHID

Odd that the RAW_HID is where the problem is - not seeing that in OP I was thinking it might be the other way around … apparently that is the way you wanted to send out the data :(

AFAIK from Paul's notes the Raw_HID runs on a fixed 1 ms timed message. So it uses some different mechanism for timing and dispatch - driven by Host in some fashion?
 
Odd that the RAW_HID is where the problem is - not seeing that in OP I was thinking it might be the other way around … apparently that is the way you wanted to send out the data :(

AFAIK from Paul's notes the Raw_HID runs on a fixed 1 ms timed message. So it uses some different mechanism for timing and dispatch - driven by Host in some fashion?

Raw_HID is producing that noise, and I suspect the Serial port would as well. In my tests, I would only send a message over the serial if noise was detected. And the fact that no Serial messages were sent when I stopped sending Raw_HID packets, tells me there is no noise when the USB is idle. I bet if I periodically sent messages over the Serial, I would see that noise crop up in that situation as well.
 
Status
Not open for further replies.
Back
Top