Continue to Site

Welcome to our site!

Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

  • Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

Analog inputs

Status
Not open for further replies.

YAN-1

New Member
Hello. I am trying to use the comparator module of the 16F876A. I want to compare a certain signal with 1.88V, so I set the voltage reference module to 1.88V. However, I am not sure how to configure the TRISA and ADCON registers. I need one comparator only and I will also need another analog input for ADC of another signal. Please guide me. Thanks a lot.

Nichola V. Abdo
 
YAN-1 said:
Hello. I am trying to use the comparator module of the 16F876A.
Nichola V. Abdo

The 876 doesn't have any comparators. Just use an ADC channel and compare it to the voltage you want.

Mike.
 
Well... turns out the voltage I need to compare with is not 1.88V; it's 0.188V! It's the voltage drop across a current-sensing resistor used in the driving circuitry of a stepper motor. But the new problem now is that the voltage reference module does not provide a voltage lower than 0.21V. If I use the 0.21V reference, I'll be allowing 2.1 amps to pass in the windings. The current ratings of the windings is 2 amps. Will that damage the motor? Awaiting your help.
 
YAN-1 said:
Well... turns out the voltage I need to compare with is not 1.88V; it's 0.188V! It's the voltage drop across a current-sensing resistor used in the driving circuitry of a stepper motor. But the new problem now is that the voltage reference module does not provide a voltage lower than 0.21V. If I use the 0.21V reference, I'll be allowing 2.1 amps to pass in the windings. The current ratings of the windings is 2 amps. Will that damage the motor? Awaiting your help.

You could increase your current sense resistor to .12ohms and therefore get a voltage of 0.24v for 2A flowing. Or, you could use a lower VDD - 4V will get you down to 0.16V.

Mike.
P.S. sorry for quoting the non A spec - must update my datasheet.
 
That's ok. Thank you. The problem is that I only have 0.1 ohm resistors. Don't ask me why :lol:
 
What about generating your own Vref with a resistor divider between VDD and GND. Set your comparator mode to 001, put your resistor divider on AN3 and your current sense voltage on AN0.

Mike.
 
YAN-1 said:
If I use the 0.21V reference, I'll be allowing 2.1 amps to pass in the windings. The current ratings of the windings is 2 amps. Will that damage the motor? Awaiting your help.

If you use the comparator for overcurrent protection, you could of course set it at slightly above the current rating. The motor can briefly sustain that overcurrent condition before your circuit detects that condition and shuts down.

However, if the comparator is used to set the current level of the windings (i.e. control the current level) then you are operating the motor at slightly above the the current rating. The motor might not be able to sustain that for continuous use. I.E., the motor could run too hot and shorten its life.
 
What about generating your own Vref with a resistor divider between VDD and GND. Set your comparator mode to 001, put your resistor divider on AN3 and your current sense voltage on AN0.

Mike.

Well, this could work but I wanted to avoid potentiometers to minimize current consumption and hence power. I think i'll use that after all.

If you use the comparator for overcurrent protection, you could of course set it at slightly above the current rating. The motor can briefly sustain that overcurrent condition before your circuit detects that condition and shuts down.

However, if the comparator is used to set the current level of the windings (i.e. control the current level) then you are operating the motor at slightly above the the current rating. The motor might not be able to sustain that for continuous use. I.E., the motor could run too hot and shorten its life.
Well I'm using it because I'm driving the motor at 4 times its rated voltage so I need to chop the current as soon as it hits the maximum value. I don't think that chopping the current when it reaches above just above the rated value over and over would be preferable for long runs.

Thanks everyone. Can anyone please tell me how I should configure the TRISA and ADCON registers to use one comparator and one ADC channel?
 
YAN-1 said:
Well I'm using it because I'm driving the motor at 4 times its rated voltage so I need to chop the current as soon as it hits the maximum value. I don't think that chopping the current when it reaches above just above the rated value over and over would be preferable for long runs.

Are you using resistors to feed the stepper with the higher voltages?, this is a standard technique used to increase power and speed (with out having to mess around trying to do over current protection!). If you google for '+stepper +motor +tutorial' you will find plenty of info about it.
 
Well I know that. I read about it. I need some method of knowing when the current reaches the ratings so that I can turn off the MOSFETs. I'm gonna use the comparator to do that by compairing the resistor drop voltage to the one representing the maximum current. The ADC channel I'm talking about is for another purpose. It's from a sliding potentiometer that moves with the linear stepper motor so that I can tell its position. Could these things be done more easily?
 
YAN-1 said:
Well I know that. I read about it. I need some method of knowing when the current reaches the ratings so that I can turn off the MOSFETs.

I should read it some more then!, the wirewound resistors limit the current, so you don't need to sense it, here's a clip from one of the tutorials found by google at https://www.stepperworld.com/.

Code:
A current-limiting resistor in series with the motor can be used to effectively limit current to the motor, at the cost of wasted power.  The resistor used is a special "power resistor" which must dissipate power and heat.  Ideally, the resistor should be a non-inductive type so as not to interfere with the inductance of the motor and control circuit (especially when current-limiting to achieve higher RPMs). 

The value of a current-limiting resistor in series with the motor can be determined from the following equation... 

Vsupply = Vdrop + (i * Rmotor) + (i * Rlimit) 

Vdrop  = voltage drop of Transistors used (1 to 2 volts in a unipolar controller) 
i   = current in circuit 
Rmotor = resistance of single motor coil 
Rlimit  = current limiting power resistor 

The objective is to find Rlimit that satisfies the desired current rating i
 
Well yeah..there are two ways of doing that. I can either add a resistor in series with each winding. The value of the resistor should make sure that even if I apply a large voltage, the current will still be under ratings. This way, I don't need to check for the current since the resistor has a large value in the first place. This method, however, dissipated energy in the form of heat. The other method is to add a small resistor after all the windings before the ground. We apply the large voltage and then monitor the drop across the resistor. When it goes above ratings, I chop off the current. So I need a comparator or ADC. It's called the chopping technique.
 

Attachments

  • chopping.jpg
    chopping.jpg
    15.2 KB · Views: 656
If in doubt, keep it simple! - and look what manufacturers use as well. The series resistor method is simple, cheap, reliable, and FAIL SAVE. A processor based method could burn the motor out due to a bug, or just a simple crash - the resistor method is immune from that.
 
YAN-1 said:
Thanks everyone. Can anyone please tell me how I should configure the TRISA and ADCON registers to use one comparator and one ADC channel?

As a start,
TRISSA should be set as input = 0.
ADCON1 should be 0 to enable 8 analogue inputs.
CMCON should be set to 1. This is for Vref on AN3, signal on AN0 and bit 6 will be set when AN0>AN3. AN4 will not be usable as it is the output from the comparator.

You can set CMIE to enable interrupt on change of the comparators. This, however, will interrupt on any change so your interrupt will have to check CMCON bit 6.

HTH

Mike.
 
YAN-1 said:
The other method is to add a small resistor after all the windings before the ground. We apply the large voltage and then monitor the drop across the resistor. When it goes above ratings, I chop off the current. So I need a comparator or ADC. It's called the chopping technique.

No. You chop off the voltage to reduce the current.

But then you need to sense the falling current and reapply the voltage, just as you have shown in your previous diagram. Therefore you'll need to set two current limits.
 
Nigel Goodwin said:
If in doubt, keep it simple! - and look what manufacturers use as well. The series resistor method is simple, cheap, reliable, and FAIL SAVE. A processor based method could burn the motor out due to a bug, or just a simple crash - the resistor method is immune from that.

That and the PIC's ADC isn't really fast so trying to use it to smoothly respond to a fast-changing signal as required for current sensing will probably end up being not so smooth.

Actually some of the newer PICs' ADCs are considerably faster, but it's still not really a quick response if the controller is trying to do other things.
 
But then you need to sense the falling current and reapply the voltage, just as you have shown in your previous diagram. Therefore you'll need to set two current limits.

Well not really. When the current falls back again, the voltage drops below the ref and another interrupt is invoked to switch the MOSFET back on.

That and the PIC's ADC isn't really fast so trying to use it to smoothly respond to a fast-changing signal as required for current sensing will probably end up being not so smooth.

Actually some of the newer PICs' ADCs are considerably faster, but it's still not really a quick response if the controller is trying to do other things.

Well I would have thought it would be fast enough. The controller will be doing other things but the comparator is set to give interrupts. Hence, it operates alone as a hardware module and does not delay the other functions like the ADC that is done normally in the main loop. And the frequency at which the stepper motor is operated is about 1 ms so I would have thought that would be long enough for the comparator to detect the current rise and turn it off several times before the next step. Am I that wrong?
 
There is a related thread on using the PWM and the A2D of the PIC to control the current level. In your case, you need to control two channels, one for each motor winding. I also suggest you use the built-in comparator only for over-current protection.

Well the motor is a unipolar stepper motor so there are 4 windings. And The purpose of the comparator is not to just protect it from current rise when something wrong happens. The whole driving technique depends on applying a large voltage to improve torque and time response. An application note by Microchip (Stepping Motors Fundamentals) also demonstrates that and says that the comparator module can be used to do that.
 
Status
Not open for further replies.

Latest threads

New Articles From Microcontroller Tips

Back
Top