PWM motor control - measure current-consumption with shunt-ADC PIC16F690

Author
EME
Starting Member
  • Total Posts : 31
  • Reward points : 0
  • Joined: 2009/01/15 00:42:50
  • Location: 0
  • Status: offline
2010/12/21 09:50:27 (permalink)
0

PWM motor control - measure current-consumption with shunt-ADC PIC16F690

Hi,
 
I made a PWM-motor control (PIC16F690-IRFD010) and want to measure the current consumption of the motor (BLDC). So I inserted a 1-Ohm-resistor on the low-side between GND and the S-pin from the IRDF010-MOSFET and connected via an MCP601-OpAmp to the AN0-pin of the PIC to sense the voltage across the resistor.
 
In medium-level performance (PR2=255 - duty cycle value=500) of the motor this gives a voltage of ca 2.5V (measured with a voltmeter).
 
But the ADC gives a whole spectrum of results - anyhow not what I would expect (a value of ca 512). So I have the feeling that due to the PWM I just read random values depending on the "position" of the PWM-signal.
 
I thought about an RC-filter to smoothen the signal but first I would like to ask in the forum if anybody has better ideas how to measure the current-uptake of a BLDC-motor (5V - ca 1A) with a resistor (not a MAX4172, etc).
post edited by EME - 2010/12/21 10:16:32
#1

10 Replies Related Threads

    ppater
    Super Member
    • Total Posts : 1002
    • Reward points : 0
    • Joined: 2006/08/26 10:33:06
    • Location: Ivry, France
    • Status: offline
    Re:PWM motor control - measure current-consumption with shunt-ADC PIC16F690 2010/12/21 11:35:21 (permalink)
    0
    You may synchronize the ADC measurement with the PWM to take the current exactly when the motor is switched, with some initial delay and several consecutive measures to catch the peek value, or some averaging. A good point where to synchronize is in the timer interrupt.

    Best regards,
    Philippe.

    Pic Micro Pascal for All!
    #2
    ppater
    Super Member
    • Total Posts : 1002
    • Reward points : 0
    • Joined: 2006/08/26 10:33:06
    • Location: Ivry, France
    • Status: offline
    Re:PWM motor control - measure current-consumption with shunt-ADC PIC16F690 2010/12/21 11:43:27 (permalink)
    0
    EME

    Hi,
     
    I made a PWM-motor control (PIC16F690-IRFD010) and want to measure the current consumption of the motor (BLDC). So I inserted a 1-Ohm-resistor on the low-side between GND and the S-pin from the IRDF010-MOSFET and connected via an MCP601-OpAmp to the AN0-pin of the PIC to sense the voltage across the resistor.


    You may also post some schematic to explain a bit...
    A one ohm resistor in the source of the mosfet is not a so good idea because the Vgs will decrease when the current will increase, and as the Vgs(th) is not too low the mosfet may de-saturate and heat...
    A smaller resistor (say 0.1 ohm) with an highest gain for the OpAmp would be better.



    Best regards,
    Philippe.

    Pic Micro Pascal for All!
    #3
    EME
    Starting Member
    • Total Posts : 31
    • Reward points : 0
    • Joined: 2009/01/15 00:42:50
    • Location: 0
    • Status: offline
    Re:PWM motor control - measure current-consumption with shunt-ADC PIC16F690 2010/12/21 12:31:39 (permalink)
    0
    Thanks for the reply! I chose the 1R because it was available (I will receive 0.22R resistors in a couple of days). The MOSFET does not heat up - this I tested carefully so for the moment it is OK - also it was easier with the OpAMp to amplify the 40-55 mV resulting from the 1R under standard testing conditions. I read about synchronizing the ADC with the PWM but I am not exactly sure how to do it - I think that the sampling time of the ADC should cover a complete PWM-period to catch the average voltage per period - no matter where the entry point of the ADC-conversion is (would average itself away). I will use the TMR2-interrupt to start the AD-conversion(s) and work myself through this.
     
    I do not have a schematic yet but I will provide it tomorrow (it is quite simple anyhow).
    post edited by EME - 2010/12/21 12:39:15
    #4
    ppater
    Super Member
    • Total Posts : 1002
    • Reward points : 0
    • Joined: 2006/08/26 10:33:06
    • Location: Ivry, France
    • Status: offline
    Re:PWM motor control - measure current-consumption with shunt-ADC PIC16F690 2010/12/21 13:09:02 (permalink)
    0
    EME
    also it was easier with the OpAMp to amplify the 40-55 mV resulting from the 1R under standard testing conditions.

    You was speaking about 1 amp - on 1 ohm it gives 1V. At start-up or upon heavy load conditions, that will be *very* different.
    The mosfet reaction will depend also on the Vdd value (again you don't give enough information).
    Sync method depends also on the PWM frequency (no info).
    Don't forget that the current signal will have a log component form due to the motor inductance, so you need to synchronize else you know what you have already seen by yourself...

    Always give all the informations if you want a precise answer that will save time and messages.




    Best regards,
    Philippe.

    Pic Micro Pascal for All!
    #5
    EME
    Starting Member
    • Total Posts : 31
    • Reward points : 0
    • Joined: 2009/01/15 00:42:50
    • Location: 0
    • Status: offline
    Re:PWM motor control - measure current-consumption with shunt-ADC PIC16F690 2010/12/22 02:05:25 (permalink)
    0
    Hi,
     
    as indicated above, Vdd is +5V. The hardware is not the problem - also the motor (from PICDEM LAB without any specifications) is controlled by the software in the desired way. As soon as I have the required parts I will change the resistor anyhow. So everything is working as desired. Now I want to add a control for the motor performance. My question is how to measure the current-uptake of the motor in the right way by the PIC ADC. Also it is not a problem how to write ADC-code - I need to know the principle how to get the correct value for measuring a PWM-signal with an ADC. Enclosed the schematics as far as it is relevant to my problem. The values of R1 and R1 are chosen so that they give a gain of app 90 which gives under the mentioned conditions not more than 5V after the OpAmp..
     
    Now I measure ca 40-55 mV across the 1R with a duty cycle of 50-100% and PR2=255. The PIC runs on 8MHz (internal osc). So this means that the current would be 40-55mA which seems much too low. I assumed ca 1A for the BLDC-motor from comparing it to other models - but as mentioned there is no specification provided by Microchip for it.
    post edited by EME - 2010/12/22 02:07:17

    Attached Image(s)

    #6
    ppater
    Super Member
    • Total Posts : 1002
    • Reward points : 0
    • Joined: 2006/08/26 10:33:06
    • Location: Ivry, France
    • Status: offline
    Re:PWM motor control - measure current-consumption with shunt-ADC PIC16F690 2010/12/22 04:49:34 (permalink)
    0
    EME
    I assumed ca 1A for the BLDC-motor from comparing it to other models - but as mentioned there is no specification provided by Microchip for it.

    [8D] Microchip is not a motor manufacturer... Or this is a scoop...

    For measuring, let's speak about your code now. Again you don't provide enough information...
    Le's say your TMR2 prescaler is 1, so your period is 128 µs.
    Each time the period finishes you may trigger an interrupt.
    Upon this interrupt, you may wait a bit; the wait time will depend on the mosfet switch delay (very small) and on the motor inductance,
    then measure the current (several times to catch the peak current);  if duty <> 0 the mosfet is switched on just at the interrupt time.
    Without a scope to see the signal form it is difficult to say more...
    Else, if you don't want the peak current, you may want to measure the average current, this is easier: just transform your OpAmp into an integrator, or without any component, you may use a simple averaging of the current measures...



    Best regards,
    Philippe.

    Pic Micro Pascal for All!
    #7
    EME
    Starting Member
    • Total Posts : 31
    • Reward points : 0
    • Joined: 2009/01/15 00:42:50
    • Location: 0
    • Status: offline
    Re:PWM motor control - measure current-consumption with shunt-ADC PIC16F690 2010/12/22 05:26:28 (permalink)
    0
    Hi,
     
    Microchip sells the motor with the PICDEM LAB demo board - but without any specifications. I will look into the integrator and see what happens. The code is flexible bc it takes user inputs for the TMR2 prescaler, PR2 and the duty cycle value. The initial values are: TMR2-prescaler 1:16, PR2: 255, duty cycle value: 500. For me the general principle is important - there are some google-results which talk about measuring the current by the on-chip ADC but they do not tell how and what is to consider (independent from any specific values of the CCP-module). This is exactly what I want to discuss here.
     
    Best regards
    Eme
    #8
    sborden
    Super Member
    • Total Posts : 1932
    • Reward points : 0
    • Joined: 2010/08/05 02:12:53
    • Location: 0
    • Status: offline
    Re:PWM motor control - measure current-consumption with shunt-ADC PIC16F690 2010/12/22 12:41:33 (permalink)
    0
    The other thing you can consider is, since you are in a switching operation, is to get a MOSFET with a higher Rds but lower gate charge, since the actual switching generates the heat in this case.  Then you can eliminate the external resistor altogether.  This is how many DCDC converters work.
    #9
    EME
    Starting Member
    • Total Posts : 31
    • Reward points : 0
    • Joined: 2009/01/15 00:42:50
    • Location: 0
    • Status: offline
    Re:PWM motor control - measure current-consumption with shunt-ADC PIC16F690 2010/12/23 01:54:27 (permalink)
    0
    Thanks for all the hints and ideas! I solved the problem how to measure the current with a double lowpass-filter before the OpAmp which gives a clear DC-voltage.
     
    Best regards
    Eme
        

    Attached Image(s)

    #10
    ppater
    Super Member
    • Total Posts : 1002
    • Reward points : 0
    • Joined: 2006/08/26 10:33:06
    • Location: Ivry, France
    • Status: offline
    Re:PWM motor control - measure current-consumption with shunt-ADC PIC16F690 2010/12/23 03:33:44 (permalink)
    0
    EME
    Thanks for all the hints and ideas! I solved the problem how to measure the current with a double lowpass-filter before the OpAmp which gives a clear DC-voltage.


    IMHO this is a quick-and-dirty fix-up but it is not a so good idea:
    1. A two stages filter with the same cut-off frequency does not give any advantage; maybe you made it because of available component values?
    2. The cut-off frequency is very low, so you cannot see peak / over-current conditions and there's a high reaction time. However it depends of what you want to do with this measurement (you still don't explain it clearly), but if you want to regulate the speed, for example, this is definitely too low. Warning: using a TMR2 prescaler ratio greater than 1 @ 4MHz would make a too low PWM frequency for a motor, maybe this is why you designed such a filer. Again you don't give enough information about the goal of your attempts.
    3. You may achieve the same low pass filtering by software without any additional hw, with peak values detecting at the same time, even by means of simple averaging. Think software: a µC is aimed to replace the electronics where it is possible, it allows to significantly reduce costs...

    Best regards,
    Philippe.

    Pic Micro Pascal for All!
    #11
    Jump to:
    © 2017 APG vNext Commercial Version 4.5