UART PWM Interference

75 views
Skip to first unread message

ojc...@gmail.com

unread,
Aug 31, 2017, 10:19:18 AM8/31/17
to BeagleBoard
I'm generating a high rate of errors 10-20% when sending messages out via xbee connected to UART but only when I use PWM at the same time. I'm using UART2 and I've tested this behavior using all of the other available PWM pins. Below is a piece of simplified code that has a high error rate. When I comment out the section that turns the PWM signal on, the UART/xbee sends messages pretty much faultlessly.

What is the fix to eliminate the high error rate?


import Adafruit_BBIO.UART as UART
import Adafruit_BBIO.PWM as PWM
import serial
from time import sleep

duty = 5.
pwm_freq = 60
polarity = 1
pin = "P9_16"

UART.setup("UART2")
PWM.start(pin, 100. - duty, pwm_freq, polarity)

ser = serial.Serial(port = "/dev/ttyO2", baudrate = 9600)
ser.close()

for i in range(30):

message = "hello world"
ser.open()
if ser.isOpen():
ser.write(message)
else:
print('message unsent - serial port could not be opened')
ser.close()
sleep(0.1)


PWM.stop(pin)
PWM.cleanup()

Kernel 8.1.13
Debian Wheezy 7.11

Przemek Klosowski

unread,
Aug 31, 2017, 12:02:15 PM8/31/17
to beagl...@googlegroups.com
On Thu, Aug 31, 2017 at 8:55 AM, <ojc...@gmail.com> wrote:
I'm generating a high rate of errors 10-20% when sending messages out via xbee connected to UART but only when I use PWM at the same time. I'm using UART2 and I've tested this behavior using all of the other available PWM pins. Below is a piece of simplified code that has a high error rate. When I comment out the section that turns the PWM signal on, the UART/xbee sends messages pretty much faultlessly.

What is the fix to eliminate the high error rate?

Whate are the errors? is it failures to ser.open() or failures in ser.write()? I don't think you should be opening and closing the serial port every time you want to write to it---is there a reason to do it that I fail to see?

Dennis Lee Bieber

unread,
Aug 31, 2017, 1:07:11 PM8/31/17
to beagl...@googlegroups.com
On Thu, 31 Aug 2017 05:55:11 -0700 (PDT),
ojc...@gmail.com declaimed the following:

>I'm generating a high rate of errors 10-20% when sending messages out via xbee connected to UART but only when I use PWM at the same time. I'm using UART2 and I've tested this behavior using all of the other available PWM pins. Below is a piece of simplified code that has a high error rate. When I comment out the section that turns the PWM signal on, the UART/xbee sends messages pretty much faultlessly.
>
What type of error? The "unable to open" message in your code (and why
are you constantly opening/closing the serial port?). Garbage characters on
the receiver side?

How close is the xBee antenna to whatever wiring is linked to the PWM
line? Possible cross-talk affecting the transmitted signal. Power-draw for
attached equipment maybe causing xBee drop-outs?

Too many variables possible...
--
Wulfraed Dennis Lee Bieber AF6VN
wlf...@ix.netcom.com HTTP://wlfraed.home.netcom.com/

ojc...@gmail.com

unread,
Aug 31, 2017, 3:10:05 PM8/31/17
to BeagleBoard
What are the errors? : When receiving the message (xbee connected to PC in API mode) it is commonly scrambled by random characters - often one or two characters per message often.

Why am I opening and closing the serial connection? : There was a reference on Google that told me to do that for connections that could last a long time (but now I can't find it). If it's advisable I'll leave it open the whole time. But regardless the high error rate problem seems to be dependent only on whether PWM is running or not.

ojc...@gmail.com

unread,
Aug 31, 2017, 3:22:36 PM8/31/17
to BeagleBoard
Errors : yes garbage characters on the receiver side

Cross-talk : so I have had a servo motor (powered from it's own ubec) plugged in, however I thought that the ubec noise might be interfering, so I tried running the PWM signal without any device attached (no servo ubec running) and no pwm wire plugged into the beaglebone. But still had the same issue.

Przemek Klosowski

unread,
Aug 31, 2017, 5:22:31 PM8/31/17
to beagl...@googlegroups.com
On Thu, Aug 31, 2017 at 3:13 PM, <ojc...@gmail.com> wrote:
Errors : yes garbage characters on the receiver side

Cross-talk : so I have had a servo motor (powered from it's own ubec) plugged in, however I thought that the ubec noise might be interfering, so I tried running the PWM signal without any device attached (no servo ubec running) and no pwm wire plugged into the beaglebone. But still had the same issue.
OK--so now can you test by losing the open/close ,disconnecting the XBee and jumpering TX and RX and writing some simple text out and checking that you receive it back correctly, while running PWM. If you see errors, then maybe beaglebone is sensitive to crosstalk; if you don't then the crosstalk must be in the XBee. BTW, suppying the  servo from a separate power supply might not fully prevent interference--it could be kickback from driving the servo.

--
For more options, visit http://beagleboard.org/discuss
---
You received this message because you are subscribed to the Google Groups "BeagleBoard" group.
To unsubscribe from this group and stop receiving emails from it, send an email to beagleboard+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/beagleboard/eabc977d-e1ea-4c07-abf3-6193fe8c2518%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

ojc...@gmail.com

unread,
Sep 1, 2017, 8:08:00 PM9/1/17
to BeagleBoard
So tested all of that - see table below
The servo power supply is a QM12V5A but as seen below - even when this is not active, there is still a high error rate.
Also, I am not opening and closing the serial port now - it stays open throughout each test. I sent 100 messages for each test. Error rates are an approximate guess.

PWM running      Servo & Servo Power Supply Active     Message Mode              Error Rate
Yes                      Yes                                                        RX-TX on loopback       0% - all good
Yes                      No                                                         RX-TX on loopback       0% - all good
No                       No                                                         RX-TX on loopback       0% - all good
Yes                      Yes                                                        BBB to PC via xbee      10 - 50% - no good
Yes                      No                                                         BBB to PC via xbee      10 - 50% - no good
No                       No                                                         BBB to PC via xbee       0% - all good

I don't really know what to make of it except that the problem seems to be somewhere either in the xbee?
The xbee is connected with a 0.1uF decoupling capacitor between +3.3V and GND close to the xbee (~25mm length from xbee GND pin thru 0.1uF Cap to xbee +3.3V pin)

I see some people recommend a 1uF decoupling capacitor on the xbee - maybe I'll try adding one of those in parallel with the 0.1uF cap.


On Friday, September 1, 2017 at 9:22:31 AM UTC+12, Przemek Klosowski wrote:
On Thu, Aug 31, 2017 at 3:13 PM, <ojc...@gmail.com> wrote:
Errors : yes garbage characters on the receiver side

Cross-talk : so I have had a servo motor (powered from it's own ubec) plugged in, however I thought that the ubec noise might be interfering, so I tried running the PWM signal without any device attached (no servo ubec running) and no pwm wire plugged into the beaglebone. But still had the same issue.
OK--so now can you test by losing the open/close ,disconnecting the XBee and jumpering TX and RX and writing some simple text out and checking that you receive it back correctly, while running PWM. If you see errors, then maybe beaglebone is sensitive to crosstalk; if you don't then the crosstalk must be in the XBee. BTW, suppying the  servo from a separate power supply might not fully prevent interference--it could be kickback from driving the servo.

--
For more options, visit http://beagleboard.org/discuss
---
You received this message because you are subscribed to the Google Groups "BeagleBoard" group.
To unsubscribe from this group and stop receiving emails from it, send an email to beagleboard...@googlegroups.com.

Dennis Lee Bieber

unread,
Sep 2, 2017, 11:40:00 AM9/2/17
to beagl...@googlegroups.com
On Fri, 1 Sep 2017 14:54:20 -0700 (PDT),
ojc...@gmail.com declaimed the following:


>
>PWM running Servo & Servo Power Supply Active Message Mode
> Error Rate
>Yes Yes
> RX-TX on loopback 0% - all good
>Yes No
> RX-TX on loopback 0% - all good
>No No
> RX-TX on loopback 0% - all good
>Yes Yes
> BBB to PC via xbee 10 - 50% - no good
>Yes No
> BBB to PC via xbee 10 - 50% - no good
>No No
> BBB to PC via xbee 0% - all good
>
I'd try to configure a test using hardware serial from BBB to computer
(likely that would need a 3.3V serial-USB adapter connected to RX/TX/GND,
maybe jumpers for RTS/CTS and/or/ DTR/DSR)

If you get garbage with that, the problem may be on the computer end...

>I don't really know what to make of it except that the problem seems to be
>somewhere either in the xbee?

How far away from the xBee connections are the PWM connections?

ojc...@gmail.com

unread,
Sep 2, 2017, 5:11:18 PM9/2/17
to BeagleBoard, ojc...@gmail.com
Just tried adding the 1uF decoupling capacitor in parallel with the existing 0.1uF capacitor - it didn't decrease the high error rate.

Przemek Klosowski

unread,
Sep 3, 2017, 8:35:25 AM9/3/17
to beagl...@googlegroups.com
Could you post a picture or drawing of your physical layout? I think the evidence points to interference from the PWM circuit into the XBee. HOw close physically are they?

To unsubscribe from this group and stop receiving emails from it, send an email to beagleboard+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/beagleboard/a13bf443-af43-4b66-9e7f-6610cb12d95a%40googlegroups.com.

ojc...@gmail.com

unread,
Sep 4, 2017, 9:13:06 AM9/4/17
to BeagleBoard

See the two pictures below - I have tried to simplify things a few times - but nothing seems to change the high error rate, although it might have decreased a bit - a few times it has been ~50% (That was when I was trying to run my Power HD MG1235 servo on a 7.2V UBEC)


The Xbee and PWM are on different sides of the BBB the only thing in common as per the picture below is the GND.


The code below shows the computer side of things to get you an idea of what is going on there - I've posted the contents of xbee_tools.py below - not that I think there's an issue there - just as FYI.




from xbee import XBee
import serial
import cPickle

class xbee_connection:
    def __init__(self, port, baudrate):
        # Start the serial connection
        try:
            self.ser = serial.Serial(port, baudrate)
        except serial.serialutil.SerialException:
            self.ser.close()
            print("Could not start serial connection, ensure that Xbee is connected to COM4 port")

        self.xbee = XBee(self.ser)  # Starting XBee connection
        self.msg = ""               # Initializing message as blank
        self.encoded_msg = ""


    def poll_data(self):

        try:
            raw_data = self.xbee.wait_read_frame()
            #print raw_data['rf_data']
            #self.msg = cPickle.loads(raw_data['rf_data'])
            self.msg = raw_data['rf_data']
            #print(self.msg)
            # Ensuring that these values can be converted into floats
        except KeyboardInterrupt:
            self.ser.close()
        except Exception as e: print(e)

        except:
            pass

        return self.msg

    def disconnect(self):
        self.ser.close()


Dennis Lee Bieber

unread,
Sep 4, 2017, 10:04:19 AM9/4/17
to beagl...@googlegroups.com
On Mon, 4 Sep 2017 04:30:07 -0700 (PDT),
ojc...@gmail.com declaimed the following:

>
>
>See the two pictures below - I have tried to simplify things a few times -
>but nothing seems to change the high error rate, although it might have
>decreased a bit - a few times it has been ~50% (That was when I was trying
>to run my Power HD MG1235 servo on a 7.2V UBEC)
>
You're using USB power for the BBB? Have you tried with a stand-alone
wall-wart supply?

jay

unread,
Sep 4, 2017, 10:06:22 AM9/4/17
to beagl...@googlegroups.com
Our ii78 ii78 8ii
8
8
7m889888888

8io8i8ii8898
8
8
8
888
888o

8888888oi8888ii
I'll I'll 88ooiikiii7 ii78 ii78 iiiiiui8777888
888i8
I7u7ii88and and then I 88ooiikiii7 ii78

8888o
9l99oojui8ilooking 9
looking looking looking looking looking forward 88888887amto to my ookopp

--
For more options, visit http://beagleboard.org/discuss
---
You received this message because you are subscribed to the Google Groups "BeagleBoard" group.
To unsubscribe from this group and stop receiving emails from it, send an email to beagleboard+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/beagleboard/07ggqchj9ikgv02cet2ifpplp4suvtql71%404ax.com.

ojc...@gmail.com

unread,
Sep 4, 2017, 8:12:44 PM9/4/17
to BeagleBoard
Yes, I started off using one of those and then changed to USB power - it didn't have an affect on the error rate.

John Syne

unread,
Sep 5, 2017, 10:18:18 AM9/5/17
to 'Andrey Nechypurenko' via BeagleBoard
Shorten the GND wire between the BBB and the GND common point. The BBB GND plane must be the reference point and in your picture, you now have a second GND reference point with a long wire connecting the two. This creates a GND bounce on your second GND reference point and is probably responsible the the noise you are seeing. 

Regards,
John




ojc...@gmail.com

unread,
Sep 6, 2017, 8:52:19 AM9/6/17
to BeagleBoard
Thank you thank you thank You!
You are right. There are 8 ground terminals on the GPIO - they seem to be there for a reason - when I plug the xbee GND directly into one of those (make the path to the BBB short) I get ~zero errors in communication.
When I create a secondary Ground reference plane from one of the BBB GND pins, things go bad and I get a high error rate.
All is good again.

One interesting point to note - if only the xbee is connected to the BBB (no wire connection to the PWM pin) there are similar errors. As soon as the servo is plugged into the PWM pin / GND the error rate goes to ~nil again.

Thanks
Reply all
Reply to author
Forward
0 new messages