# High side measurement Current Sensor

Status
Not open for further replies.

#### gilardino

##### New Member
I am using servo motor to lift an object to a particular position (ex 90degree). I want to differentiate the weight of 3 objects. So heavier object will draw more current to lift the object. I am planning to use high side current sensor (ZXCT1009) using shunt resistor connected to the servo motor. So when the servo is moving and lifting the object, i want the current sensor to read the output voltage to give to an ADC.

This is the PWM code,

if(a=0,a>30,a++)
{
portd.f7=1;
delay_us(1000);
portd.f7=0;
delay_us(19000);
}

My question is, where should i put the code [adc();]to read the output voltage?
because i only can measure the voltage different, only when the servo is moving to 90 degrees. When it moves, the current will pass through the shunt resistor and the servo. When it stop, the current will be zero.
Thanks.

#### gilardino

##### New Member
Anyone? or do i need to elaborate more???

thank you...

#### Arkham00

##### Member
I think that you should sample the current at the end of the "1" period:

Code:
for( a=0, a<30, a++) {
portd.f7 = 1 ;
delay_us( 1000) ;
portd.f7 = 0 ;
delay_us( 19000) ;
}

#### 3v0

##### Coop Build Coordinator
Forum Supporter
The function adc() has a delay built in to wait for the ADC to do it conversion. If you do it like this you can do the conversion without changing you delay.

Code:
for( a=0, a<30, a++) {
delay_us( 500) ;   // let current stablize
portd.f7 = 1 ;
delay_us( 500) ;
my_analog = adcResult() ; // fake function name
portd.f7 = 0 ;
delay_us( 19000) ;
}

The delay times will need adjusting. You need a scope to see how long it takes the current to settle.

My motors do not turn with 1/20th duty cycle

3v0

#### gilardino

##### New Member
thanks.

i don't understand why the on time 1000us need to be split into 500us before the portd.f7=1. Referring to the code, not the total time only become 19500us because the first 500us is not included inside the duty cycle?Correct me if i am wrong...

And i only know my_analog=adc result is where we calculate the ADC. I do not understand the startADC conversion(). What is the difference?

Thanks...

##### Banned
Is there some kind of gear mechanism that causes a latching action on your arm, because normal servo's still draw quiet a bit of current when at their set position. At 90 degrees if there's feedback from the gear train the current through the servo will be proportional to the weight on the swing arm. In motion the current will sway dramatically.

#### gilardino

##### New Member
yes. I tried it already. It has small current through the servo. But are there are any current differences if the servo swing to 90degrees with carrying different weights? I tried attaching something to servo to make it heavier,but there are no any differences. The value of the small current remains the same.