Arduino PWM signal to Xbee A/D

Thread Starter

nahidJM

Joined May 7, 2015
9
hi there
I am trying to get analog output from Arduino and from what I know Arduino doesn't offer D/A converter. But PWM pins are provided as a D/A converter. But the pulses are of course not an analog voltage. So I tried to use a simple RC filter after the PWM signal and the output of the filter is connected to the A/D pin of xbee. According to theory the filter has to make the pulses as smooth as possible with certain value of the ripple. Even though I have decreased the value of the ripple, as soon as I connected the output of the filter to the Xbee, something strange happens!!! The A/D pin of Xbee starts reading multiple values. The voltage fluctuates randomly. Of course the voltage that I want is one of those multiple values, but because of my application, I cannot have multiples output voltages for same input. I really don't know the reason behind this and this is why I can't really solve the problem. I would appreciate any insight on this issue. Thanks.

1.I attached the schematic of what I'm planning to do.

2.The frequency of the PWM depends on the pin ofcourse but we can consider 31250 Hz.

3.I have considered R=15K and C=1uF

4. I have attached the output of the filter on O.Scope. Even though the PWm is passed through the filter but as soon as we connect it to Xbee, we get multiple values since the Xbee is sampling the signal. and the signal still seems to be a pulse.!!!
 

Attachments

MikeML

Joined Oct 2, 2009
5,444
Where are the bypass capacitors?

What is the input impedance of the A/D input pin on the XBee?

The normal PWM rate of an Arduino is 500Hz, not 31KHz.
 

Thread Starter

nahidJM

Joined May 7, 2015
9
Where are the bypass capacitors?

What is the input impedance of the A/D input pin on the XBee?

The normal PWM rate of an Arduino is 500Hz, not 31KHz.
Well it seems I might have gotten the wrong information. You are right the frequency of PWM is 500Hz. The input impedance of the A/M pin of Xbee is 10k.
And what do you mean by bypass capacitors? I mean why do I need bypass capacitors?

I appreciate your response very much. Thanks.
 

MikeML

Joined Oct 2, 2009
5,444
You need a 100nF to 10uF capacitor tied (with short wires) between the 5V rail and the gnd rail right on the white board, preferably close to where the Xbee module gets its power... This is for local energy storage, so as the Xbee clocks, the energy is stored right at its pins; not several cm distant from inside the Arduino. This is standard in any high-speed digital circuits.

What is the settling time requirement for the filter that smooths the pwm? Say the PWM is running at 10% duty cycle (0.5V) for a long time, and then it switches to 90% duty cycle. How long can you wait for the voltage to settle to 4.5V?
 

Thread Starter

nahidJM

Joined May 7, 2015
9
You need a 100nF to 10uF capacitor tied (with short wires) between the 5V rail and the gnd rail right on the white board, preferably close to where the Xbee module gets its power... This is for local energy storage, so as the Xbee clocks, the energy is stored right at its pins; not several cm distant from inside the Arduino. This is standard in any high-speed digital circuits.

What is the settling time requirement for the filter that smooths the pwm? Say the PWM is running at 10% duty cycle (0.5V) for a long time, and then it switches to 90% duty cycle. How long can you wait for the voltage to settle to 4.5V?
I will try to add the bypass capacitors and see if it makes any difference.

Regarding the settling time for the filter, I'm not sure what do you mean by "how long I can wait". The thing is that my sensor will not change stages from 1-% duty cycle to 90% suddenly since the system is almost stable. And since I'm using Xbee, I'll not be transmitting too often. I might transmit once every 20 minutes. so even if the state changes to 90%, there is enough time for the filter to make the signal smooth. I hope I've understood your question right.
 

MikeML

Joined Oct 2, 2009
5,444
Ok, so settling time is not an issue.
What is the range of expected PWM duty cycles min to max?
What is the resolution (smallest change) of the XBee A/D?
What is the voltage range of the Xbee A/D?
 

Thread Starter

nahidJM

Joined May 7, 2015
9
Ok, so settling time is not an issue.
What is the range of expected PWM duty cycles min to max?
What is the resolution (smallest change) of the XBee A/D?
What is the voltage range of the Xbee A/D?

Range of the duty cycle of PWM is 0% to 25%( since the output of the arduino is 0 to 64bit)

the resolution of A/D is 10 bit (1023) resolution

the voltage range is 0 to 1.2

The PWM pin on Arduino has a 0 to 5v which means duty cycle of 0 to 100%. but because the Xbee handles 1.2V, so I reduced the resolution of PWM to 64 bit to output a voltage of maximum 1.2V.
 

MikeML

Joined Oct 2, 2009
5,444
Try this:

I'm using the full 0 to 255 range of the Arduino PWM value (0% to 99.6% duty cycle). The range of inputs at the Xbee is 0V to 1.153V. The ripple is less than one bit of the Xbee input range. The worst-case settling time after a PWM value change is about 2 sec.

58.gif
 

Thread Starter

nahidJM

Joined May 7, 2015
9
Try this:

I'm using the full 0 to 255 range of the Arduino PWM value (0% to 99.6% duty cycle). The range of inputs at the Xbee is 0V to 1.153V. The ripple is less than one bit of the Xbee input range. The worst-case settling time after a PWM value change is about 2 sec.

View attachment 85371

Thank you very much. I'm out of uF capacitors since it's weekend. I'll get them on Sunday and will try and see if it works.
SO since you've been able to drop the 5V of arduino to 1.2, I don't have to change it in the arduino before i send it out of PWM?
 

Thread Starter

nahidJM

Joined May 7, 2015
9
Just another update. The Xbee has internal pullup resistor of 50K on the A/D pin. I am not familiar with these concepts at all so I don't know if it makes any difference!
 

MikeML

Joined Oct 2, 2009
5,444
Please confirm that the input impedance of the A/D on the Xbee really is 10KΩ. I have not worked directly with Xbee, but lots with Arduino. The input impedance of the Arduino and PIC A/D is actually very high, but must be driven from a source impedance of 10K or less. I wonder if the Xbee is similar.

If you find that the Xbee specifies that the AD pin needs to be driven from a 10K impedance (instead of the input impedance actually being 10K), then add a 10K resistor between the AD input and the Xbee's Vss pin external to the Xbee, and the circuit of post #8 will work.

Do not enable the 50K pull-up when using that Xbee pin for analog input.

ps: I downloaded the data sheet. Page 8 answers the question. Put the 10K resistor across the input as shown. There are many other cautions about using the Xbee AD regarding adding bypass capacitors, and shutting off other activity to get clean AD readings on page 8 of the datasheet.
 
Last edited:

Thread Starter

nahidJM

Joined May 7, 2015
9
Please confirm that the input impedance of the A/D on the Xbee really is 10KΩ. I have not worked directly with Xbee, but lots with Arduino. The input impedance of the Arduino and PIC A/D is actually very high, but must be driven from a source impedance of 10K or less. I wonder if the Xbee is similar.

If you find that the Xbee specifies that the AD pin needs to be driven from a 10K impedance (instead of the input impedance actually being 10K), then add a 10K resistor between the AD input and the Xbee's Vss pin external to the Xbee, and the circuit of post #8 will work.

Do not enable the 50K pull-up when using that Xbee pin for analog input.

ps: I downloaded the data sheet. Page 8 answers the question. Put the 10K resistor across the input as shown. There are many other cautions about using the Xbee AD regarding adding bypass capacitors, and shutting off other activity to get clean AD readings on page 8 of the datasheet.

Thank you very much for the tips :). I'll add the bypass capacitor and will try the circuit in post #8. Will update you with the result

Just another question. what is the reason that I should disable the Pullup resistor on A/D pins? isn't it for protection? because the pullup resistors are enabled by default on all the pins on the Xbee.
 

MikeML

Joined Oct 2, 2009
5,444
...
Just another question. what is the reason that I should disable the Pullup resistor on A/D pins? isn't it for protection? because the pullup resistors are enabled by default on all the pins on the Xbee.
The pull-up is to be used when the pin is configured for digital input. It keeps the pin from "floating" to indeterminate logic levels, especially on unused inputs. Should never be enabled if the pin is used for analog input.

On a digital input that is driven by a true CMOS device, the pin is actively driven low or high. In that case, the pull-up should be disabled.

On a digital input that is driven low by a momentary pushbutton for example, the internal pull-up will pull the input pin high whenever the switch is not pushed.

On an unused pin, the pull-up is enabled to pull the voltage level to Vdd (logic one). This keeps the pin from drifting to a voltage near 1/2Vdd where the CMOS buffer inside the Xbee (or any CMOS chip) is halfway on, drawing supply current, wasting power in battery powered applications.
 

Thread Starter

nahidJM

Joined May 7, 2015
9
The pull-up is to be used when the pin is configured for digital input. It keeps the pin from "floating" to indeterminate logic levels, especially on unused inputs. Should never be enabled if the pin is used for analog input.

On a digital input that is driven by a true CMOS device, the pin is actively driven low or high. In that case, the pull-up should be disabled.

On a digital input that is driven low by a momentary pushbutton for example, the internal pull-up will pull the input pin high whenever the switch is not pushed.

On an unused pin, the pull-up is enabled to pull the voltage level to Vdd (logic one). This keeps the pin from drifting to a voltage near 1/2Vdd where the CMOS buffer inside the Xbee (or any CMOS chip) is halfway on, drawing supply current, wasting power in battery powered applications.

WOW. Thank you very much. I had the pins enable. Will disable the pin and connect the circuit you suggested. Hopefully it'll work. Thank you. Will update you soon :)
 

Thread Starter

nahidJM

Joined May 7, 2015
9
The pull-up is to be used when the pin is configured for digital input. It keeps the pin from "floating" to indeterminate logic levels, especially on unused inputs. Should never be enabled if the pin is used for analog input.

On a digital input that is driven by a true CMOS device, the pin is actively driven low or high. In that case, the pull-up should be disabled.

On a digital input that is driven low by a momentary pushbutton for example, the internal pull-up will pull the input pin high whenever the switch is not pushed.

On an unused pin, the pull-up is enabled to pull the voltage level to Vdd (logic one). This keeps the pin from drifting to a voltage near 1/2Vdd where the CMOS buffer inside the Xbee (or any CMOS chip) is halfway on, drawing supply current, wasting power in battery powered applications.

Dear Mike, I don't know how I thank thank you. I simply connected the circuit in post #8 and everything is working perfectly. I have been stuck in this problem for more than a month. I greatly appreciate your help :)
 

Elad Amit

Joined Nov 15, 2015
3
Try this:

I'm using the full 0 to 255 range of the Arduino PWM value (0% to 99.6% duty cycle). The range of inputs at the Xbee is 0V to 1.153V. The ripple is less than one bit of the Xbee input range. The worst-case settling time after a PWM value change is about 2 sec.

View attachment 85371
I have a very similar problem and was wondering if you would be able to help me out as well
I am connecting an MLX90614 in PWM mode to an xbee and I am getting the same issue with multiple values / values being 1023 or 0
I am currently using a 0.1uF capacitor but it is not appearing to do the trick
Attached is the current setup I have, any help will be more than welcomed :)
 

Attachments

shteii01

Joined Feb 19, 2010
4,644
I actually used PWM to generate "analog" signal to control speed of a motor. The "theory" behind it, that I got from Arduino website, is that "dumb" devices (like a motor) don't "see" pwm pulses, they see the average of those pulses, so if you have really short pulses, the average is analog 1 volt for example, if you have really long pulses, the average is analog 5 volts. But here is the key, the devices that are receiving those pseudo analog signals from pwm source are really dumb. As long as you feed them something that looks like analog, they will be happy to perform.

ADC are not dumb devices. They are also precise devices. We, the users, rely on their precision. If I was you, I would not feed a "pseudo" analog signal to ADC, it is just a waste of ADC. If you got pins for parallel connection, or have I2C pins free, or have serial pins free, get external DAC and output real analog signal to your Xbee.
 

Elad Amit

Joined Nov 15, 2015
3
I actually used PWM to generate "analog" signal to control speed of a motor. The "theory" behind it, that I got from Arduino website, is that "dumb" devices (like a motor) don't "see" pwm pulses, they see the average of those pulses, so if you have really short pulses, the average is analog 1 volt for example, if you have really long pulses, the average is analog 5 volts. But here is the key, the devices that are receiving those pseudo analog signals from pwm source are really dumb. As long as you feed them something that looks like analog, they will be happy to perform.

ADC are not dumb devices. They are also precise devices. We, the users, rely on their precision. If I was you, I would not feed a "pseudo" analog signal to ADC, it is just a waste of ADC. If you got pins for parallel connection, or have I2C pins free, or have serial pins free, get external DAC and output real analog signal to your Xbee.
trying to minimize / simplify the hardware that goes into this board :)
can you be more specific as to what you would connect (which DAC, etc...)
 

shteii01

Joined Feb 19, 2010
4,644
trying to minimize / simplify the hardware that goes into this board :)
can you be more specific as to what you would connect (which DAC, etc...)
I don't have specific DAC suggestion. In my own very limited experience, we used Arduino Due board which does have DAC. So we tried using PWM, but then switched to the onboard DAC.

I don't know if you noticed, but your device has I2C option. If the device is not too far from the uC, and if your uC has support for I2C, then it might be better for you to use I2C. This way you avoide the whole PMW into pseudo analog into ADC conversion scenario.
 

Elad Amit

Joined Nov 15, 2015
3
I don't have specific DAC suggestion. In my own very limited experience, we used Arduino Due board which does have DAC. So we tried using PWM, but then switched to the onboard DAC.

I don't know if you noticed, but your device has I2C option. If the device is not too far from the uC, and if your uC has support for I2C, then it might be better for you to use I2C. This way you avoide the whole PMW into pseudo analog into ADC conversion scenario.
This thing is going on a horse's hoof / leg, which is why I am trying to minimize the setup on the leg itself by using an xbee :)
 
Top