LabVIEW Interface for Arduino Discussions

cancel
Showing results for 
Search instead for 
Did you mean: 

PWM with Arduino Mega 2560 causes Analog In voltage jitter

Hi I am doing a Mechatronics Degree project where I need to use PWM for PID control of a heater whilst taking temperature readings, etc.

I was given a NI-USB-6008 which I understand is a non-starter for hardware PWM, but I have an Arduino Mega 2560 which I have downloaded the Arduino library from NI and have been trying it out.

I don't have use of a oscilloscope at home so I'm just using the waveform chart in Labview and the PWM looks messy. I understand that the Mega has 8-bit PWM so a value between 0-255 is required for the duty cycle. I am using a dial with 0-100 with 2.56 multiplication to get the 0-255 range. Is this correct use or is that the reason for the messy waveform output.

Also if I increase the duty cycle the temp reading I am taking from analog input 0 seems to become more unstable and jitters all over the place? Is this a limitation of the arduino or a problem with my code?

I have even resorted to using shift registers to sum the temperature voltages and get the average value.

Any recommendations would be appreciated.

-Steve

0 Kudos
Message 1 of 5
(5,888 Views)

If you try to "read" the PWM via an analog read function in LabVIEW you will get a very bad representation of the waveform because the sampling frequency when doing this is very small (relatively).  To accurately see the PWM waveform, you would need to be samping at at least twice the PWM frequecny which I highly doubt you are anywhere close to that becuase the frequency of your loop is large.  If you want to check the PWM signal, I highly suggest taking the Arduino to school and using an oscilloscope.

What are you using to measure the temperature?  You would have to make sure that the range and resolution of it's output is within the parameters of the Arduino's ADC.  The Arduino Mega2560 only has a 10-bit resolution over the 0 to 5V meaning it can only a change in voltage of about 5 mV.

0 Kudos
Message 2 of 5
(4,061 Views)

Thanks for your answer, the main thing that is bothering me is that running PWM alongside the analog input port reading the output of an LM35 is somehow causing that temperature reading to jitter about more so than normally and even with having a half second delay between the while loop execution. I am wondering if this behaviour is normal or if I have a dodgy arduino instead?

-Steve

0 Kudos
Message 3 of 5
(4,061 Views)

So, I'm assuming that you have tried to just read the temperature sensore without any PWM being used on the Arduino.  Is this the case?  I.e.  Does the temperature sensor work exactly as expected when you do not do anything else (including PWM)?

0 Kudos
Message 4 of 5
(4,061 Views)

Yes I have read the temperature without PWM being used and the temp does fluctuate itself a little. Putting a delay into the loop reduces this, but if I use PWM at the same time these jitters are magnified significantly.

I was wondering if these jitter errors are due to the arduino being polled for readings so quickly?

0 Kudos
Message 5 of 5
(4,061 Views)