Filtering BEMF noise from ADC using software help please ?

Discussion in 'Embedded Systems and Microcontrollers' started by howdoesthatworkguy, Dec 25, 2007.

  1. howdoesthatworkguy

    Thread Starter Active Member

    Jul 23, 2007
    39
    0
    I use a 12v DC motor. PWM 16khz, I want to know if someone has some code for filtering noise out of the ADC from the BEMF input. I have the code for PDFF/PID which is ok. But becuase of the interference from the motor which gets introduced into the input of the ADC I am looking for some clever softare that can filter this. I do have some clean up filtering hardware before the BEMF is inputed into the ADC. But Since the motor type can change I would like some code to control the rest of the filtering though software. Does anyone know how to do that ?
     
  2. mrmeval

    Distinguished Member

    Jun 30, 2006
    833
    2
    What is doing the PWM? What is doing the ADC? What is the motor? What is the voltages. Post a schematic.... etc.
     
  3. howdoesthatworkguy

    Thread Starter Active Member

    Jul 23, 2007
    39
    0
    The PWM drives the N channels of an Mosfet H-bridge (the H-Bridge users P-Channel highside and N-Channel lowside). This part works with no problem. The Bridge is supplied with approx 16v DC. The motor has currenty a simple resister devider coming off it. From the devider a signal goes to one of the ADC inputs. The ADC is messuring the BEMF. The PIC will shut the H-Bridge down for a slipt second to get BEMF readings. I am limited with space so can't add complex opp amps or other deivces to shape the BEMF output from the motor before it goes into the ADC. I can only use a few discret components, across all FET's are some 20p caps across the source/drain to help limited motor interference, and 1 or 2 filter caps. So what I am hoping is for some type of code to filter out the interference on the BEMF so I can just get a clean BEMF reading without the interference. I know caps across source/drian help to limit the motor contacts arc, and I have put caps in other places to try limited the high frequences that are always around en electric motor.
     
  4. Papabravo

    Expert

    Feb 24, 2006
    10,148
    1,791
    If it can be done at all it probably won't be in the digital domain. In order to do effective digital processing of a signal there must be an analog anti-aliasing filter to limit the high frequency components. In the digital realm you can work with frequency components up to 1/2 the sampling frequency. A wondowed sinc filter might be the ticket assuming you have the horsepower to pull it off.

    The other more difficult approach is to understand the noise source and the coupling mechanism. Then you can either eliminate the source, or interrupt the coupling mechanism. Hanging caps everywhere is unlikely provide an acceptable solution.
     
  5. howdoesthatworkguy

    Thread Starter Active Member

    Jul 23, 2007
    39
    0
    I am using the 16F685. I am not sure if this has the horse power since its doing a number of other things. If I return to a hardware filter, what would you recommend, as I am not to familar with this.
     
  6. Papabravo

    Expert

    Feb 24, 2006
    10,148
    1,791
    In order to do that we need to understand the frequency content of the signal at the motor. There will be components at the PWM frequency of 16 kHz. Now what is the frequency content of the noise on the BEMF signal? Is it harmonically related to the PWM frequency? What would be an appropriate cutoff frequency and transition bandwidth for a low pass filter? The reason I ask is that a transition bandwidth of an octave with a corner at 16 kHz will start to knock the noise down with a simple RC type filter. If that is not sufficient then we need more components to get a steeper rolloff.

    The problem with this approach is that in order to get rid of the noise we have to alter the signal which makes the overall approach of using the BEMF signal suspect. I would go after the noise source and the coupling mechanisms to make it possible for a simple filter to do the job.
     
  7. howdoesthatworkguy

    Thread Starter Active Member

    Jul 23, 2007
    39
    0
    I am getting lost, so I decided to post my circuit so you can inspect it, first to see if I am on the right track. I have not copied this from anywhere, I just tried to figure it out myself, (went though a lot of mosfets before I stopped blowing them up) But I still worry that this current deisgn is not right. I am no expert and did not want to many people looking at my crappy design so did not want to post it before, to easy for people to laugh. I am not good at working out vaules. And I have added a few caps as more of a guess than knowing the real affect. Tell me what you think? I am thinking if I get all the vaules right I will first have a more stable design and limit the noise on the design.
     
  8. beenthere

    Retired Moderator

    Apr 20, 2004
    15,815
    282
    I have attached Microchip's AN905. They seem to find that sampling BEMF in the PWM dead time is very uncomplicated.
     
  9. howdoesthatworkguy

    Thread Starter Active Member

    Jul 23, 2007
    39
    0
    Yea, I agree, though one thing I hate with there app notes is often they push there drivers as the driver of choice, I know they are good at driving fets, but man they cost a s**t load more than a standard digital transistor pack. Also, with the ECCP thing, we kill all power to it to get a reading of the BEMF, I understand the logic of this,but the problem I have is I am stupid when it comes to finding a circuit that can filter all the rubbish like high freq, brush contacts, and crap like that, it all enters the ADC, so even using a deadtime there is all this other rubbish that enters the ADC, and I need to look at a better filter on the hardware and something a little better in software maybe. The IRF7389 as internal diodes, so I guess they should do the trick, I put the caps over the drain sorces to kill the brush contact niose, but it will a guess with other caps. the caps on the gates of the FETs and the 30ohms on the gates were to try stop the ringing the seems to trigger an on state, soemthing about the drian to gate internal capacitance feeding back though to the gate and the internal resitance with inductance creating some type of osolator that rings and turns the gates back on causing a shoot though on the P/N channel, man, I killed so many fets trying to figure that one out, it seems to be ok, but vaules used have been more guess work than sinece.
     
  10. beenthere

    Retired Moderator

    Apr 20, 2004
    15,815
    282
    Well, you're frustrated, but I edited out some of the language.

    It occurs that some of the problem may be the high PWM frequency. 16KHz is perhaps higher than necessary. Can you drop the freq down to 1 or 2 KHZ? It would give you a longer dead time to let the filter settle out and present the ADC a cleaner voltage.

    Your drawing is hard to read, so I can't spot anything in the circuit that might cause a problem.

    Just had a thought - are you using a sample-and-hold for the reading into the ADC? I had a problem with a stable reading into a 16 bit A to D and was able to use an oscilloscope to find a time that I could sample a good reading. Being able to visualize the signals could be very helpful.
     
  11. howdoesthatworkguy

    Thread Starter Active Member

    Jul 23, 2007
    39
    0
    I have attached another copy in png format, hope you can read that one. I can't lower it down to 1 or 2khz because the motor will make a lot more noise. I think I need to have a better hardware filter first, I am sure that is the main problem.
     
  12. beenthere

    Retired Moderator

    Apr 20, 2004
    15,815
    282
    The drawing is still not clear. But I can make out a capacitor off the gate of one FET to ground (the lower right FET). Capacitance at that point will degrade performance. Turning a FET on and off resembles moving charge on and off a capacitor. Adding a paralleled capacitor will lengthen the time it takes to get the FET into and out of conduction. That will cause heating in the device as it stays in the ohmic region for a longer time, and shortens dead time - which may have to do with your noisy BEMF readings.

    The resistor to ground on the driven side of the gate resistor is also probably not necessary. If your gate drive switches from the source potential to 10 volts above it, that is all you need. Adding a conduction path will just slow down turn on times.

    I can't make out the values of the gate resistors. Something on the order of 100 ohms should be about right.
     
  13. scubasteve_911

    Senior Member

    Dec 27, 2007
    1,202
    1
    I'm very confused about this schematic, especially the useage of the input capacitor for the FET along with the capacitor across the FET. Seems like a really bad thing to do. I would add a snubber network across the motor to help with harmful transients though.

    Usually when a FET is driven, there is a push-pull arrangement to both quickly charge and discharge the gate. I suppose the circuit is accomplishing this, but not particularily well.

    Why not just use a simple current sense resistor along with some sort of speed feedback? Current loops are a lot easier to control and speed can be accurate if you have some sort of feedback from a hall-sensor, optical encoder, etc.

    Steve
     
  14. Papabravo

    Expert

    Feb 24, 2006
    10,148
    1,791
    I tried to tell him that hanging caps everywhere without understanding why was going to get him nowhere. Some folks just refuse to back up and reasses.
     
  15. howdoesthatworkguy

    Thread Starter Active Member

    Jul 23, 2007
    39
    0
    Thanks for all the advise, PS, I posted the schematic so people could help me, such as the god I got to many caps floating around everywhere and get advice on what I should remove. So now I have removed the caps from the Gates. What else do you guys reconmend ?
     
  16. Papabravo

    Expert

    Feb 24, 2006
    10,148
    1,791
    I think maybe understanding the physical setup would be helpful. If your circuit is constructed on a breadbooard of some kind then that is going to be strike one. If the conductors to and from the motor are long or undersized that could be a problem. The location of the board and the power supply with respect to the motor could be a problem.

    You need to think carefully about where the heavy currents are flowing and how to keep them away from your analog measurement system. You have to think about the wires being antennas and picking up the 60Hz. from the florescent lights. In short you need to become aware of the environment.

    Second I would look for other examples of successful implementations of what you are doing. In the early 1980's we tried something like this in the development of 5 1/4" Hard drives. We abandoned the approach because we could not extract useful information from the back emf to control the head arm servo. If you are convinced that the technique can work you should look for a successful implementation. Frankly I've neither heard nor seen too many. Doesn't mean they don't exist -- they're just rare.
     
  17. beenthere

    Retired Moderator

    Apr 20, 2004
    15,815
    282
    The technique of using an optical sensor to track motor RPM eliminates the BEMF noise problems and quite possibly gives a more sensitive feedback sense.
     
  18. Papabravo

    Expert

    Feb 24, 2006
    10,148
    1,791
    Is that the same thing as a rotary encoder. I think it is but it has been a while since I worked with one.
     
  19. beenthere

    Retired Moderator

    Apr 20, 2004
    15,815
    282
    It's a poor man's rotary encoder. You place an optointerrupter where the beam can be blocked by blades rotating with the shaft, or see light through holes/slits in a disk. With a compass and some care, you can make nicely spaced 16 slots, and even double one up for an indexer.
     
  20. Papabravo

    Expert

    Feb 24, 2006
    10,148
    1,791
    A proper rotary encoder might have 2,000 to 4,000 lines per revolution producing a quadratue output so you can tell which way the shaft is rotating.
     
Loading...