Shop OBEX P1 Docs P2 Docs Learn Events
voltage measurement — Parallax Forums

voltage measurement

tehmoordartehmoordar Posts: 52
edited 2005-07-15 17:03 in BASIC Stamp
hi
I am doing this one project and I am controlling the motor speed with help of PWMPAL. I am trying to calculat ewhat torque is there at motor for that purpose I am taking voltage across one sensing resistor that I have placed in series with motord and MOSFET. but the problemis may be due to motors voltage across 1 ohm resistor is not persistent but jumping all over the place like in ripples
My multimeter shows me Voltage to be like 0.25V but if I see on Oscope it is choppy and ramping ( see screen shots)
How can I get a nice clean signal across resistor on Oscope, what kind of filter can help me out
Thanks
·

Comments

  • tehmoordartehmoordar Posts: 52
    edited 2005-07-14 16:15
    Please see the Oscope shot shere
    2048 x 1536 - 1M
    2048 x 1536 - 1M
  • Paul BakerPaul Baker Posts: 6,351
    edited 2005-07-14 19:04
    What is the time division for the graphs you posted? Are you using a static load to make these measurements?

    Something I have noticed is that the second picture's waveform is contained within the first picture. The waveforms are not identical so it is clear the second isn't a zoomed in version of the first picture.· The reason why I have drawn attention to the similarity is that I believe this is an accurate representation of the current drawn by the motor. The coils in the motor are big inductors, so when you switch the motor on or off you are going to get a spike like shown in the second time division of the first picture. As to the ramping effect, is your motor a speed controlled motor? The ramps are consistant, meaning at the start there are frequent fluctuations in the drawn current as the motor is obtaining it's full speed, as it approaches that speed, it elongates the fluctuations. A speed controlled motor would likely have this type of current draw. So it is my opinion you are seeing valid data, motors are notoriously noisey on the supply lines, it's one of the reasons motors are frequently given thier own power supply.

    Now with all that said, you can clean up the signal some at the expense of data accuracy if that is what you desire. The two simplest methods are a low pass filter and a window averaging.

    The low pass filter is a resistor (in series) and capacitor (with the negative terminal tied to ground), the cutoff frequency is dictated by the time constant of the RC circuit (1/RC) the larger the time constant, the lower the cutoff frequency, and the more smoothed output signal you'll see.

    A window average is a software solution which mimics the behavior of the low pass function, the simplest formula (say for 4 data points) would be (V0+ V-1+ V-2+ V-3)/4, V0 is the current measured value, V-1 is the previous measured value and so forth.·The result is a smoothing out of the signal, the more data points used to calculate the current value, the more smoothing that occurs. This equation can be modified depending on your needs, like if you want the current value to me more heavily affected by recent samples you can use the weighted equation (V0+ 0.5V-1+ 0.25V-2+ 0.125V-3)/1.875. If you are interested in the weighted equation, I can give you an algorithm which only requires one word sized variable of storage and is extremely fast (it's window length is equal to the number of bits used to calculate the value, so for a word sized variable, the window uses the last 16 values).

    Post Edited (Paul Baker) : 7/14/2005 7:20:06 PM GMT
  • tehmoordartehmoordar Posts: 52
    edited 2005-07-14 20:19
    hi,
    you are correct the time scale is visible in screen shots it is like 100usec which is quite small , but you idea of using windows is new to me and I am really intrested in implementing that.
    These Dc motors are installed in track robot ATR from roguerobotics.com and Iam controlling them through pwm usin pwmpal.
    how cna I clean that signal with software solution.
    Thanks
  • Paul BakerPaul Baker Posts: 6,351
    edited 2005-07-15 12:49
    Haven't forgot, strange thing has been happening lately, when I attempt to open a pdf file in IE, the program hangs and corrupts the copy of Acrobat, forcing me to reinstall. I disabled the file assocation to prevent IE from attempting to launch Acrobat, and everything was kosher for a few days. Yesterday when I went to open the StampUserManual.pdf I have on my hard drive, the same thing happened (Acrobat was corrupted). So the point of all this is, if you want the algorithm in PBASIC code, it may take a little while. If you want the algorithm in pseudo-code and you convert it to PBASIC yourself, I should be able to post the algorithm sometime today.
  • tehmoordartehmoordar Posts: 52
    edited 2005-07-15 15:07
    Hi,
    I can have a try at it though I am not a good programmer but I will stay in touch if I am unsuccessful
    Thanks
  • Paul BakerPaul Baker Posts: 6,351
    edited 2005-07-15 17:03
    Ok here are the pseduo-code versions of the two algorithms

    The first is the equal weighted smoothing algorithm:
    Define value ArraySize to size of window
    Create an Array of bytes named Values of size ArraySize
    Create a nibble variable named Curidx and initialize to 0
    Create a word variable named Smoothed
     
    DO
      Aquire current value
      Store current value to Values(Curidx)
      Curidx = (Curidx + 1) modulo ArraySize
      Smoothed = 0
      For I = 0 to ArraySize
         Smoothed = Smoothed + Values(I)
      Next
      Smoothed = Smoothed / ArraySize
      Use Smoothed which is a smoothed version of the actual current value
    LOOP
    
    

    The second is the log2 weighted smoothing algorithm:
    Create word variable named Smoothed and intialize to 0
     
    DO
      Aquire current value (CVal)
      Smoothed = (CVal + (Smoothed >> 1)) >> 1
      Use Smoothed which is a smoothed version of the actual current value
    LOOP
    

    The second algorithm is a more accurate representation of the low pass filter, the only difference is the low pass filter is a ln (natural logorithm) weighted smoothing function (ln = log2.71818). Ok for some terms used that you may not know, modulo is an operator which returns the remainder of a division, this has the effect of rolling over the index into the array, so if you decare an array of size 4 (consisting of elemets indexed 0 through 3), when the pointer gets incremeted to 4, the remainer of 4 /·4 is 0, so the pointer wraps back to the beginning element. The·expression (x·>> b) operator means shift the value x to the right b bits, (x >> 1) is the same as (x / 2), but the way microprocessors work the >> is much faster than /.

    If there is anything else you have questions about, ask.
Sign In or Register to comment.