system
November 26, 2014, 10:35pm
#1
I'm trying to measure the Rpm of front and rear wheels on a front drive RC car using US1881 Hall effect sensor and 8 magnetic rings arranged in reversed polarities on each wheel and Arduino Mega, traction loss is to be detected when the front wheel has higher rpm than the rear (slip condition).
My problem is that when I move the car slowly on a dry road the two hall effect sensors produce the same readings at first then randomly outputs different readings though in that condition they are supposed to have the same rpm. I have no idea why this happens
Any help would be appreciated.
Thanks
system
November 26, 2014, 11:20pm
#2
You will need to post a circuit diagram and some code between code tags.
KenF
November 26, 2014, 11:27pm
#3
I feel a disturbance in the force. Sorry can't be more specific.
system
November 27, 2014, 12:48am
#4
the hall effect sensors are connected as shown in this diagram http://bildr.org/blog/wp-content/uploads/2011/04/us1881.png , they are connected to arduino via digital pins 20 and 21.
The code used is:
volatile float RisEdgecount2 = 0;
float rpm2 = 0;
volatile float RisEdgecount1 = 0;
float rpm1 = 0;
volatile float time = 0;
float lastseconds = 0;
volatile boolean flag = false ;
void setup(){
pinMode(21, INPUT);
pinMode(20, INPUT);
attachInterrupt(getIntNum(21), count2, RISING);
attachInterrupt(getIntNum(20), count1, RISING);
TCCR1A = 0;
TCCR1B=0x05;//Prescaler= 1024
// enable Timer1 overflow interrupt
TIMSK1 = (1 << TOIE1);
}
void loop(){
if ( flag == true )
{
cli(); // disable global interrupts
rpm1 = RisEdgecount1*(15.00)/time; //for 8 magnets, One Rev. has 4 rising edges
rpm2 = RisEdgecount2*(15.00)/time;
flag = false;
RisEdgecount1 = 0; // Restart the RPM counter
RisEdgecount2 = 0;
time = 0;
lastseconds = TCNT1/16384; //convert Timer counts to seconds
//enable interrupt
sei();
}
}
/* auxiliary function to handle encoder attachment */
int getIntNum(int pin) {
switch(pin) {
case 2:
return 0;
case 3:
return 1;
case 21:
return 2;
case 20:
return 3;
case 19:
return 4;
case 18:
return 5;
default:
return -1;
}
}
void count2 ()
{
if(digitalRead(21)==1 )
{
RisEdgecount2++;
}
}
void count1 ()
{
if(digitalRead(20)==1 )
{
RisEdgecount1++;
}
}
ISR(TIMER1_OVF_vect)
{
flag = true;
time = 4 - lastseconds ; // the timer overflow every 4 seconds
}
then randomly outputs different readings
This could mean many things, like completely random numbers, or differences of 1 or 2 counts. Post some examples!
Presumably you are aware that even the slightest turn of the vehicle requires the wheels on different sides to turn at different rates.
system
November 27, 2014, 1:55am
#6
Are you sure that the sensor can keep up with the speeds you require? I used a similar setup and it had dropouts at high RPMs.
system
November 28, 2014, 11:46am
#7
Yes, it’s 1,2 and sometimes 3 count differences between the two wheels. Find below files with rpm readings samples logged.
0 0
0 0
0 0
0 0
0 0
0 0
0 0
3.75 3.75
3.75 3.75
3.75 3.75
3.75 3.75
3.75 3.75
3.75 3.75
3.75 3.75
3.75 3.75
3.75 3.75
3.75 3.75
3.75 3.75
3.75 3.75
3.75 3.75
3.75 3.75
3.75 3.75
3.75 3.75
3.75 3.75
3.75 3.75
3.75 3.75
3.75 3.75
3.75 3.75
3.75 3.75
3.75 3.75
3.75 3.75
3.75 3.75
3.75 3.75
3.75 3.75
3.75 3.75
3.75 3.75
3.75 3.75
3.75 3.75
3.75 3.75
3.75 3.75
3.75 3.75
3.75 3.75
3.75 3.75
3.75 3.75
3.75 3.75
3.75 3.75
3.75 3.75
3.75 3.75
3.75 3.75
3.75 3.75
3.75 3.75
3.75 3.75
3.75 3.75
3.75 3.75
3.75 3.75
3.75 3.75
3.75 3.75
3.75 3.75
3.75 3.75
3.75 3.75
3.75 3.75
3.75 3.75
3.75 3.75
3.75 3.75
3.75 3.75
3.75 3.75
3.75 3.75
3.75 3.75
3.75 3.75
3.75 3.75
3.75 3.75
3.75 3.75
3.75 3.75
3.75 3.75
3.75 3.75
3.75 3.75
3.75 3.75
3.75 3.75
3.75 3.75
3.75 3.75
3.75 3.75
3.75 3.75
3.75 3.75
3.75 3.75
3.75 3.75
3.75 3.75
3.75 3.75
3.75 3.75
3.75 3.75
3.75 3.75
3.75 3.75
3.75 3.75
3.75 3.75
3.75 3.75
3.75 3.75
3.75 3.75
3.75 3.75
3.75 3.75
3.75 3.75
3.75 3.75
3.75 3.75
3.75 3.75
3.75 3.75
3.75 3.75
3.75 3.75
3.75 3.75
3.75 3.75
3.75 3.75
3.75 3.75
3.75 3.75
3.75 3.75
3.75 3.75
3.75 3.75
3.75 3.75
3.75 3.75
3.75 3.75
3.75 3.75
3.75 3.75
3.75 3.75
3.75 3.75
3.75 3.75
3.75 3.75
3.75 3.75
3.75 3.75
3.75 3.75
3.75 3.75
3.75 3.75
3.75 3.75
3.75 3.75
3.75 3.75
3.75 3.75
3.75 3.75
3.75 3.75
3.75 3.75
3.75 3.75
3.75 3.75
3.75 3.75
3.75 3.75
3.75 3.75
3.75 3.75
3.75 3.75
3.75 3.75
3.75 3.75
3.75 3.75
3.75 3.75
3.75 3.75
3.75 3.75
3.75 3.75
3.75 3.75
3.75 3.75
3.75 3.75
3.75 3.75
3.75 3.75
3.75 3.75
3.75 3.75
3.75 3.75
3.75 3.75
3.75 3.75
3.75 3.75
3.75 3.75
3.75 3.75
3.75 3.75
3.75 3.75
3.75 3.75
3.75 3.75
3.75 3.75
3.75 3.75
3.75 3.75
3.75 3.75
3.75 3.75
3.75 3.75
3.75 3.75
3.75 3.75
3.75 3.75
3.75 3.75
3.75 3.75
3.75 3.75
3.75 3.75
3.75 3.75
3.75 3.75
3.75 3.75
3.75 3.75
3.75 3.75
3.75 3.75
3.75 3.75
3.75 3.75
3.75 3.75
3.75 3.75
3.75 3.75
3.75 3.75
3.75 3.75
3.75 3.75
3.75 3.75
3.75 3.75
3.75 3.75
3.75 3.75
3.75 3.75
3.75 3.75
3.75 3.75
3.75 3.75
3.75 3.75
3.75 3.75
3.75 3.75
3.75 3.75
3.75 3.75
3.75 3.75
3.75 3.75
3.75 3.75
3.75 3.75
3.75 3.75
3.75 3.75
3.75 3.75
3.75 3.75
3.75 3.75
3.75 3.75
3.75 3.75
3.75 3.75
3.75 3.75
3.75 3.75
3.75 3.75
3.75 3.75
3.75 3.75
3.75 3.75
3.75 3.75
3.75 3.75
3.75 3.75
3.75 3.75
3.75 3.75
3.75 3.75
3.75 3.75
3.75 3.75
3.75 3.75
3.75 3.75
3.75 3.75
3.75 3.75
3.75 3.75
3.75 3.75
3.75 3.75
3.75 3.75
3.75 3.75
3.75 3.75
3.75 3.75
3.75 3.75
3.75 3.75
3.75 3.75
3.75 3.75
3.75 3.75
3.75 3.75
3.75 3.75
3.75 3.75
3.75 3.75
3.75 3.75
3.75 3.75
3.75 3.75
3.75 3.75
3.75 3.75
3.75 3.75
3.75 3.75
3.75 3.75
3.75 3.75
3.75 3.75
3.75 3.75
3.75 3.75
3.75 3.75
3.75 3.75
3.75 3.75
3.75 3.75
3.75 3.75
3.75 3.75
3.75 3.75
3.75 3.75
3.75 3.75
3.75 3.75
3.75 3.75
3.75 3.75
3.75 3.75
3.75 3.75
3.75 3.75
3.75 3.75
3.75 3.75
3.75 3.75
3.75 3.75
3.75 3.75
3.75 3.75
3.75 3.75
3.75 3.75
3.75 3.75
3.75 3.75
3.75 3.75
3.75 3.75
3.75 3.75
3.75 3.75
3.75 3.75
3.75 3.75
3.75 3.75
3.75 3.75
3.75 3.75
3.75 3.75
3.75 3.75
3.75 3.75
3.75 3.75
3.75 3.75
3.75 3.75
3.75 3.75
3.75 3.75
3.75 3.75
3.75 3.75
3.75 3.75
3.75 3.75
3.75 3.75
3.75 3.75
3.75 3.75
3.75 3.75
3.75 3.75
3.75 3.75
3.75 3.75
3.75 3.75
3.75 3.75
3.75 3.75
3.75 3.75
3.75 3.75
3.75 3.75
3.75 3.75
3.75 3.75
75 82.5
75 82.5
75 82.5
75 82.5
75 82.5
75 82.5
75 82.5
75 82.5
75 82.5
75 82.5
75 82.5
75 82.5
75 82.5
75 82.5
75 82.5
75 82.5
75 82.5
75 82.5
75 82.5
75 82.5
75 82.5
75 82.5
75 82.5
75 82.5
75 82.5
75 82.5
75 82.5
75 82.5
75 82.5
75 82.5
75 82.5
75 82.5
75 82.5
75 82.5
75 82.5
75 82.5
75 82.5
75 82.5
75 82.5
75 82.5
75 82.5
75 82.5
75 82.5
75 82.5
75 82.5
75 82.5
75 82.5
75 82.5
75 82.5
75 82.5
75 82.5
75 82.5
75 82.5
75 82.5
75 82.5
75 82.5
75 82.5
75 82.5
75 82.5
75 82.5
75 82.5
75 82.5
75 82.5
75 82.5
75 82.5
75 82.5
75 82.5
75 82.5
75 82.5
75 82.5
75 82.5
75 82.5
75 82.5
75 82.5
75 82.5
75 82.5
75 82.5
75 82.5
75 82.5
75 82.5
75 82.5
75 82.5
75 82.5
75 82.5
75 82.5
75 82.5
75 82.5
75 82.5
75 82.5
75 82.5
75 82.5
75 82.5
75 82.5
75 82.5
75 82.5
75 82.5
75 82.5
75 82.5
75 82.5
75 82.5
75 82.5
75 82.5
75 82.5
75 82.5
75 82.5
75 82.5
75 82.5
75 82.5
75 82.5
75 82.5
75 82.5
75 82.5
75 82.5
75 82.5
75 82.5
75 82.5
75 82.5
75 82.5
75 82.5
75 82.5
75 82.5
75 82.5
75 82.5
75 82.5
75 82.5
75 82.5
75 82.5
75 82.5
75 82.5
75 82.5
75 82.5
75 82.5
75 82.5
75 82.5
75 82.5
75 82.5
75 82.5
75 82.5
75 82.5
75 82.5
75 82.5
75 82.5
75 82.5
75 82.5
75 82.5
75 82.5
75 82.5
75 82.5
75 82.5
75 82.5
75 82.5
75 82.5
75 82.5
75 82.5
75 82.5
75 82.5
75 82.5
75 82.5
75 82.5
75 82.5
75 82.5
75 82.5
75 82.5
75 82.5
75 82.5
75 82.5
75 82.5
75 82.5
75 82.5
75 82.5
75 82.5
75 82.5
75 82.5
75 82.5
75 82.5
75 82.5
75 82.5
75 82.5
75 82.5
75 82.5
75 82.5
75 82.5
75 82.5
75 82.5
75 82.5
75 82.5
75 82.5
75 82.5
75 82.5
75 82.5
75 82.5
75 82.5
75 82.5
75 82.5
75 82.5
75 82.5
75 82.5
75 82.5
75 82.5
75 82.5
75 82.5
75 82.5
75 82.5
75 82.5
75 82.5
75 82.5
75 82.5
75 82.5
75 82.5
75 82.5
75 82.5
75 82.5
75 82.5
75 82.5
75 82.5
75 82.5
75 82.5
75 82.5
75 82.5
75 82.5
75 82.5
75 82.5
75 82.5
75 82.5
75 82.5
75 82.5
75 82.5
75 82.5
75 82.5
75 82.5
75 82.5
75 82.5
75 82.5
75 82.5
75 82.5
75 82.5
75 82.5
75 82.5
75 82.5
75 82.5
75 82.5
75 82.5
75 82.5
75 82.5
75 82.5
75 82.5
75 82.5
75 82.5
75 82.5
75 82.5
75 82.5
75 82.5
75 82.5
75 82.5
75 82.5
75 82.5
75 82.5
75 82.5
75 82.5
75 82.5
75 82.5
75 82.5
75 82.5
75 82.5
75 82.5
75 82.5
75 82.5
75 82.5
75 82.5
75 82.5
75 82.5
75 82.5
75 82.5
75 82.5
75 82.5
75 82.5
75 82.5
75 82.5
75 82.5
75 82.5
75 82.5
75 82.5
75 82.5
75 82.5
75 82.5
75 82.5
75 82.5
75 82.5
75 82.5
75 82.5
75 82.5
75 82.5
75 82.5
75 82.5
75 82.5
75 82.5
75 82.5
75 82.5
75 82.5
75 82.5
75 82.5
75 82.5
75 82.5
75 82.5
75 82.5
75 82.5
75 82.5
75 82.5
75 82.5
75 82.5
75 82.5
75 82.5
75 82.5
75 82.5
75 82.5
0 0
0 0
0 0
system
November 28, 2014, 11:47am
#8
another readings sample
0 0
0 0
0 0
0 0
0 0
60 71.25
60 71.25
60 71.25
60 71.25
60 71.25
60 71.25
60 71.25
60 71.25
60 71.25
60 71.25
60 71.25
60 71.25
60 71.25
60 71.25
60 71.25
60 71.25
60 71.25
60 71.25
60 71.25
60 71.25
60 71.25
60 71.25
60 71.25
60 71.25
60 71.25
60 71.25
60 71.25
60 71.25
60 71.25
60 71.25
60 71.25
60 71.25
60 71.25
60 71.25
60 71.25
60 71.25
60 71.25
60 71.25
60 71.25
60 71.25
60 71.25
60 71.25
60 71.25
60 71.25
60 71.25
60 71.25
60 71.25
60 71.25
60 71.25
60 71.25
60 71.25
60 71.25
60 71.25
60 71.25
60 71.25
60 71.25
60 71.25
60 71.25
60 71.25
60 71.25
60 71.25
60 71.25
60 71.25
60 71.25
60 71.25
60 71.25
60 71.25
60 71.25
60 71.25
60 71.25
60 71.25
60 71.25
60 71.25
60 71.25
60 71.25
60 71.25
60 71.25
60 71.25
60 71.25
60 71.25
60 71.25
60 71.25
60 71.25
60 71.25
60 71.25
60 71.25
60 71.25
60 71.25
60 71.25
60 71.25
60 71.25
60 71.25
60 71.25
60 71.25
60 71.25
60 71.25
60 71.25
60 71.25
60 71.25
60 71.25
60 71.25
60 71.25
60 71.25
60 71.25
60 71.25
60 71.25
60 71.25
60 71.25
60 71.25
60 71.25
60 71.25
60 71.25
60 71.25
60 71.25
60 71.25
60 71.25
60 71.25
60 71.25
60 71.25
60 71.25
60 71.25
60 71.25
60 71.25
60 71.25
60 71.25
60 71.25
60 71.25
60 71.25
60 71.25
60 71.25
60 71.25
60 71.25
60 71.25
60 71.25
60 71.25
60 71.25
60 71.25
60 71.25
60 71.25
60 71.25
60 71.25
60 71.25
60 71.25
60 71.25
60 71.25
60 71.25
60 71.25
60 71.25
60 71.25
60 71.25
60 71.25
60 71.25
60 71.25
60 71.25
60 71.25
60 71.25
60 71.25
60 71.25
60 71.25
60 71.25
60 71.25
60 71.25
60 71.25
60 71.25
60 71.25
60 71.25
60 71.25
60 71.25
60 71.25
60 71.25
60 71.25
60 71.25
60 71.25
60 71.25
60 71.25
60 71.25
60 71.25
60 71.25
60 71.25
60 71.25
60 71.25
60 71.25
60 71.25
60 71.25
60 71.25
60 71.25
60 71.25
60 71.25
60 71.25
60 71.25
60 71.25
60 71.25
60 71.25
60 71.25
60 71.25
60 71.25
60 71.25
60 71.25
60 71.25
60 71.25
60 71.25
60 71.25
60 71.25
60 71.25
60 71.25
60 71.25
60 71.25
60 71.25
60 71.25
60 71.25
60 71.25
60 71.25
60 71.25
60 71.25
60 71.25
60 71.25
60 71.25
60 71.25
60 71.25
60 71.25
60 71.25
60 71.25
60 71.25
60 71.25
60 71.25
60 71.25
60 71.25
60 71.25
60 71.25
60 71.25
60 71.25
60 71.25
60 71.25
60 71.25
60 71.25
60 71.25
60 71.25
60 71.25
60 71.25
60 71.25
60 71.25
60 71.25
60 71.25
60 71.25
60 71.25
60 71.25
60 71.25
60 71.25
60 71.25
60 71.25
60 71.25
60 71.25
60 71.25
60 71.25
60 71.25
60 71.25
60 71.25
60 71.25
60 71.25
60 71.25
60 71.25
60 71.25
60 71.25
60 71.25
60 71.25
60 71.25
60 71.25
60 71.25
60 71.25
60 71.25
60 71.25
60 71.25
60 71.25
60 71.25
60 71.25
60 71.25
60 71.25
60 71.25
60 71.25
60 71.25
60 71.25
60 71.25
52.5 56.25
52.5 56.25
52.5 56.25
52.5 56.25
52.5 56.25
52.5 56.25
52.5 56.25
52.5 56.25
52.5 56.25
52.5 56.25
52.5 56.25
52.5 56.25
52.5 56.25
52.5 56.25
52.5 56.25
52.5 56.25
52.5 56.25
52.5 56.25
52.5 56.25
52.5 56.25
52.5 56.25
52.5 56.25
52.5 56.25
52.5 56.25
52.5 56.25
52.5 56.25
52.5 56.25
52.5 56.25
52.5 56.25
52.5 56.25
52.5 56.25
52.5 56.25
52.5 56.25
52.5 56.25
52.5 56.25
52.5 56.25
52.5 56.25
52.5 56.25
52.5 56.25
52.5 56.25
52.5 56.25
52.5 56.25
52.5 56.25
52.5 56.25
52.5 56.25
52.5 56.25
52.5 56.25
52.5 56.25
52.5 56.25
52.5 56.25
52.5 56.25
52.5 56.25
52.5 56.25
52.5 56.25
52.5 56.25
52.5 56.25
52.5 56.25
52.5 56.25
52.5 56.25
52.5 56.25
52.5 56.25
52.5 56.25
52.5 56.25
52.5 56.25
52.5 56.25
52.5 56.25
52.5 56.25
52.5 56.25
52.5 56.25
52.5 56.25
52.5 56.25
52.5 56.25
52.5 56.25
52.5 56.25
52.5 56.25
52.5 56.25
52.5 56.25
52.5 56.25
52.5 56.25
52.5 56.25
52.5 56.25
52.5 56.25
52.5 56.25
52.5 56.25
52.5 56.25
52.5 56.25
52.5 56.25
52.5 56.25
52.5 56.25
52.5 56.25
52.5 56.25
52.5 56.25
52.5 56.25
52.5 56.25
52.5 56.25
52.5 56.25
52.5 56.25
52.5 56.25
52.5 56.25
52.5 56.25
52.5 56.25
52.5 56.25
52.5 56.25
52.5 56.25
52.5 56.25
52.5 56.25
52.5 56.25
52.5 56.25
52.5 56.25
52.5 56.25
52.5 56.25
52.5 56.25
52.5 56.25
52.5 56.25
52.5 56.25
52.5 56.25
52.5 56.25
52.5 56.25
52.5 56.25
52.5 56.25
52.5 56.25
52.5 56.25
52.5 56.25
52.5 56.25
52.5 56.25
52.5 56.25
52.5 56.25
52.5 56.25
52.5 56.25
52.5 56.25
52.5 56.25
52.5 56.25
52.5 56.25
52.5 56.25
52.5 56.25
52.5 56.25
52.5 56.25
52.5 56.25
52.5 56.25
52.5 56.25
52.5 56.25
52.5 56.25
52.5 56.25
52.5 56.25
52.5 56.25
52.5 56.25
52.5 56.25
52.5 56.25
52.5 56.25
52.5 56.25
52.5 56.25
52.5 56.25
52.5 56.25
52.5 56.25
52.5 56.25
52.5 56.25
52.5 56.25
52.5 56.25
52.5 56.25
52.5 56.25
52.5 56.25
52.5 56.25
52.5 56.25
52.5 56.25
52.5 56.25
52.5 56.25
52.5 56.25
52.5 56.25
52.5 56.25
52.5 56.25
52.5 56.25
52.5 56.25
52.5 56.25
52.5 56.25
52.5 56.25
52.5 56.25
52.5 56.25
52.5 56.25
52.5 56.25
52.5 56.25
52.5 56.25
52.5 56.25
52.5 56.25
That output could not have been produced by the program you posted, because that program does not print.
The timing method doesn't make sense to me. Better to use millis().
system
November 28, 2014, 6:09pm
#10
I haven't posted the part of the program that saves to the SD card. I don't think that the timer may have anything to do with the problem of catching wrong counts
Suppose that the counts aren’t wrong.
KenF
November 28, 2014, 8:30pm
#12
Looks like you need a bit of oil on that right wheel.
holmes4
November 28, 2014, 10:51pm
#14
This chunk of code may be part of the problem
cli(); // disable global interrupts
rpm1 = RisEdgecount1*(15.00)/time; //for 8 magnets, One Rev. has 4 rising edges
rpm2 = RisEdgecount2*(15.00)/time;
flag = false;
RisEdgecount1 = 0; // Restart the RPM counter
RisEdgecount2 = 0;
time = 0;
lastseconds = TCNT1/16384; //convert Timer counts to seconds
//enable interrupt
sei();
Multiply and divide are very long winded operation. When doing this type of think you must COPY the vars from the interrupt routine turn interrupt back on and then do your calculation.
Mark
Hi, I suggest you start with just a sketch that ONLY reads, calculates and outputs each input data, nothing else.
It looks like you wrote your sketch all at once, then tried to debug it.
How do I come to this conclusion,
I haven't posted the part of the program that saves to the SD card. I don't think that the timer may have anything to do with the problem of catching wrong counts
You have got the SD part sketched? Yet haven't fixed the first problem.
One step at a time.
Tom.......