2

Author Topic: Axon's ADC -- strange negative values?  (Read 758 times)

0 Members and 1 Guest are viewing this topic.

Offline mstachoTopic starter

  • Supreme Robot
  • *****
  • Posts: 363
  • Helpful? 10
Axon's ADC -- strange negative values?
« on: December 06, 2011, 02:27:21 PM »
Howdy all,

So here's something I can't explain:  I'm using Webbotlib, and I have to read sensors on my ADCs.  I choose ADCs 0 through 7, but I read ADCs 0 through 3 in a function "readSensors1" and ADCs 4 through 7 in a function "readSensors2".  When the entire code is just:

//do a bit of housekeeping
readSensors1();
readSensors2();

it works fine.

However, when I add 4 quadrature encoders (including the interrupt pins) readSensors2() just won't work.  I cannot explain why. 

Here's the other rub:

When I just straight-up copy the code for readSensors1() into readSensors2(), it STILL doesn't work.  If I remove the call to readSensors1() (but keep the function in the code), it...STILL doesn't work. 

Is it possible that the interrupts are fighting it?  Can that even be possible, given that I change code, remove function calls etc? 

is it possible that the function is put into memory space that shouldn't be accessed?  Can I change this?

The code only takes up about 30% of the Axon's flash and about 20% of the RAM, so it's not like I'm overloading it.  Also, I've had the Axon run with 7 encoders on interrupts and it worked fine.

Any thoughts?

MIKE
Current project: tactile sensing systems for multifingered robot hands

Offline Admin

  • Administrator
  • Supreme Robot
  • *****
  • Posts: 11,658
  • Helpful? 169
    • Society of Robots
Re: Axon's ADC -- strange negative values?
« Reply #1 on: December 07, 2011, 10:53:48 AM »
hmmmmm your subject line says 'negative values', but your description mentions nothing about that :P

My guess is that you have a bug somewhere.

Can you post more of your code and a description of the pins being used?

Offline mstachoTopic starter

  • Supreme Robot
  • *****
  • Posts: 363
  • Helpful? 10
Re: Axon's ADC -- strange negative values?
« Reply #2 on: December 07, 2011, 11:08:47 AM »
Oops, you're right, sorry.  What I mean to say is that when the sensor reading code fails, it produces a negative value from the ADC (ie: it gives me -14000 or something, which is...odd...)

Pins I'm using:  ADC's 0 - 5, and 12 and 13 (used to be 0 - 7, but I thought it might be a burned out ADC so I switched).  Digital outputs E5 - E7 for addressing (these are the pins S2, S0, and S1).  Encoder interrupts are on pins K0 through K3 (which ARE analog inputs as well, ADC8 through ADC11).

Please note that both "readSensor1()" and "readSensor2()" functions actually work when there are no encoders (ie: if I gut the code and only leave the sensor reading and the printf statements, they both work fine).

The relevant code is here:

IN "readSensor1()", this code works fine.  It outputs "0" both times the rprintf function is called, which is exactly what I expect when I have no load on the sensor.

Code: [Select]
pin_low (S2); //this is the major part

//read the top row
pin_high(S0);
pin_high(S1);
                rprintf("%d \n",forceAr[0])
forceAr[0] = a2dConvert8bit(ADC_NUMBER_TO_CHANNEL(0));
forceAr[0] = a2dConvert8bit(ADC_NUMBER_TO_CHANNEL(0));
                rprintf("%d \n",forceAr[0])

IN "readSensor2()", this produces things that don't make sense.  It produces "0" before the a2dConvert8Bit, but produces that weird negative after.
Code: [Select]
                pin_high (S2);

//read the top row
pin_high(S0);
pin_high(S1);
                rprintf("%d \n",forceAr[16])
forceAr[16] = a2dConvert8bit(ADC_NUMBER_TO_CHANNEL(12));
forceAr[16] = a2dConvert8bit(ADC_NUMBER_TO_CHANNEL(12));
                rprintf("%d \n",forceAr[16])

So...any thoughts?  Today or tomorrow I'm going to re-write the code, just in case I DID end up missing something (this is code stitched together from two separate projects).

**EDIT: I keep forgetting how those
Code: [Select]
tags work :-P

MIKE
« Last Edit: December 07, 2011, 11:10:24 AM by mstacho »
Current project: tactile sensing systems for multifingered robot hands

Offline Admin

  • Administrator
  • Supreme Robot
  • *****
  • Posts: 11,658
  • Helpful? 169
    • Society of Robots
Re: Axon's ADC -- strange negative values?
« Reply #3 on: December 07, 2011, 11:31:04 AM »
Found at least one of your errors . . .

%d expects an 'int', 'int8_t' or an 'int16_t'
%u expects an 'uint8_t' or an 'uint16_t'

In this code, you are storing an unsigned 8 bit int, but your printing it out as a signed 8 bit int. This could result in negative numbers.
Code: [Select]
forceAr[0] = a2dConvert8bit(ADC_NUMBER_TO_CHANNEL(0));
                rprintf("%d \n",forceAr[0])

Don't feel bad, it's a very common mistake and even I do it on occasion :P

Offline mstachoTopic starter

  • Supreme Robot
  • *****
  • Posts: 363
  • Helpful? 10
Re: Axon's ADC -- strange negative values?
« Reply #4 on: December 07, 2011, 11:37:48 AM »
Haha hm...perhaps that is the error in this code for printing, but it wouldn't explain the rest of the behaviour of the code.  See, this then sends the ints back to a C# program that parses them.  For sensor 1, it reads absolutely perfectly and all the values are correct (although I'll definitely make sure I'm using the right %* in the future).

However, since this code works 100% correctly without the encoders, I'm starting to get a sinking feeling that something on my computer is screwed up.  Consider this:

I re-started this code, copying the quadrature encoder making lines from an old version that worked fine with just the encoders.  These are my encoder lines, where f1m1ENCInt etc are pins that I've mapped to.

Code: [Select]
//Make the encoder
QUADRATURE quad1 = MAKE_GENERIC_QUADRATURE(f1m1ENCInt,f1m1ENCP,false,1368,false); //the bottom motor of finger 1
QUADRATURE quad2 = MAKE_GENERIC_QUADRATURE(f1m2ENCInt,f1m2ENCP,false,1368,false); //the top motor of figner 1
QUADRATURE quad3 = MAKE_GENERIC_QUADRATURE(f2m1ENCInt,f2m1ENCP,false,1368,false); //the bottom motor of Finger 2
QUADRATURE quad4 = MAKE_GENERIC_QUADRATURE(f2m2ENCInt,f2m2ENCP,false,1368,false); //the top motor of finger 2

Now...this exact code compiled fine before, but now I'm getting this error:

../myAxon2.c:92: error: expected '=', ',', ';', 'asm' or '__attribute__' before 'quad1'

Since this computer has been giving me a bit of trouble with other programming languages, is it possible that it's just some weird bug that isn't part of my code?

MIKE
Current project: tactile sensing systems for multifingered robot hands

Offline mstachoTopic starter

  • Supreme Robot
  • *****
  • Posts: 363
  • Helpful? 10
Re: Axon's ADC -- strange negative values?
« Reply #5 on: December 07, 2011, 11:40:09 AM »
Oops, no that was just me being an idiot.  I forgot to include something.   :-\  Still doesn't explain why the code sometimes works and sometimes doesn't, though :-P

MIKE
Current project: tactile sensing systems for multifingered robot hands

Offline Webbot

  • Expert Roboticist
  • Supreme Robot
  • *****
  • Posts: 2,132
  • Helpful? 108
Re: Axon's ADC -- strange negative values?
« Reply #6 on: December 07, 2011, 01:44:28 PM »
Still doesn't explain why the code sometimes works and sometimes doesn't, though :-P

In your main code where you do:
Code: [Select]
readSensors1();
readSensors2();

Try doing:
Code: [Select]
readSensors2();
readSensors1();

This may(?) say that the individual routines are working and its the order that is important.
Also: when you are flisking s0,s1,s2 etc (don't know what they do but am assuming its controlling the output that is read by the adcs) then does the system have enough time to settle between reads.

I THINK YOUR PROBLEM MAY BE:-

Also I see that readSensors2 is using: 'forceAr[16] = ....'
So I'm assuming that you have declared foreceAr as:
Code: [Select]
forceAr[x]where x is 17 or bigger. If its 16 then thats where your bug is: declaring forceAr[16] would give you 16 slots which are numbered from 0 to 15 - so putting something into forceAr[16] would be corrupting something and causing merry hell.




admin edit: fixed a typo caused by code matching a BBC
« Last Edit: December 07, 2011, 08:14:04 PM by Admin »
Webbot Home: http://webbot.org.uk/
WebbotLib online docs: http://webbot.org.uk/WebbotLibDocs
If your in the neighbourhood: http://www.hovinghamspa.co.uk

Offline mstachoTopic starter

  • Supreme Robot
  • *****
  • Posts: 363
  • Helpful? 10
Re: Axon's ADC -- strange negative values?
« Reply #7 on: December 07, 2011, 02:36:36 PM »
Aye, I was concerned about timing as well, so I did switch them and still readSensors2() didn't work.  I gave up at that point, and just re-wrote the code.  Now it's just one big "readSensors()" function and things are on different pins and it works fine.   ;D I'm going to just not question it.  If the code works, it's easier to avoid thinking about the problems haha.

Thanks for the help!  I'm going to guess there was some hidden bug I couldn't find in the code and it was my fault.  Since it works now it doesn't make much sense that it could have been an Axon or Webbotlib problem.

MIKE
Current project: tactile sensing systems for multifingered robot hands

 


Get Your Ad Here

data_list