I'd like to add a sensing reistor to a discrete full bridge that I use to drive a small DC motor with a PIC uC. I want the PIC to read the voltage drop on the resistor and to change the duty-cycle of the PWM signal if too much current is flowing.
I'd like to know:
1) how can I make that voltage suitable for the PIC ADC? Do I need a peak detector?
2) why could an unexpected great current flow into the motor?
3) Other aspects that I should care of?
I'd like to add a sensing reistor to a discrete full bridge that I use to drive a small DC motor with a PIC uC. I want the PIC to read the voltage drop on the resistor and to change the duty-cycle of the PWM signal if too much current is flowing.
I'd like to know:
1) how can I make that voltage suitable for the PIC ADC? Do I need a peak detector?
I would suggest checking for over current for a 'reasonably' long time, short term 'spikes' aren't a problem, and will occur in normal use. It's up to you to decide how long an overload has to occur before you take action.
I don't know if a pic adc + ISR will be fast enough to do this. you are measuring current rise through the motor coil which may be very fast. I'd use a comparator to do the measurement and turn off the drivers. that way it's continuous instead of discrete samples. you will want to disable the comparator during the early part of the cycle to avoid the spikes that nigel is talking about.
take a look at the allegro 3977 for a description of a chip that does this sort of thing. fairly instructive.
by the way, you will not get a smooth square wave. It won't be smooth and it will be rising. somewhere on the web there are a bunch of scope shots of the voltage across an A3977's sense resistor. very noisy.