go away spammer

Author Topic: Axon freezing up when trying to get analog input  (Read 3326 times)

0 Members and 1 Guest are viewing this topic.

Offline bsamuelsTopic starter

  • Jr. Member
  • **
  • Posts: 28
  • Helpful? 0
Axon freezing up when trying to get analog input
« on: September 30, 2009, 04:29:21 PM »
Hey, I'm using a sharp IR GP2D12 using the following code:

Code: [Select]
void control(void){
rprintf("starting");
delay_ms(200);
int se=a2dConvert8bit(0);
se=sharp_IR_interpret_GP2D12(se);
rprintf("sensor results: %d \n",se);
delay_ms(2000);
}

When I press the button to run the code, the Axon gets hung up at int se=a2dConvert8bit(0);. After much troubleshooting, this hang up happens whenever the IR sensor is connected to any of the northern ports (0-15) and everything works fine when a servo is connected to one of the said ports.

Halp?

Offline Admin

  • Administrator
  • Supreme Robot
  • *****
  • Posts: 11,703
  • Helpful? 173
    • Society of Robots
Re: Axon freezing up when trying to get analog input
« Reply #1 on: October 01, 2009, 06:57:27 AM »
You can't define a function as a value to an int variable. You are also overwriting your own define. Do this:

Code: [Select]
define se a2dConvert8bit(0)

void control(void){
rprintf("starting");
delay_ms(200);
sensor=sharp_IR_interpret_GP2D12(se);
rprintf("sensor results: %d \n", sensor);
delay_ms(2000);
}

Offline chelmi

  • Supreme Robot
  • *****
  • Posts: 496
  • Helpful? 15
    • Current projects
Re: Axon freezing up when trying to get analog input
« Reply #2 on: October 01, 2009, 07:49:32 AM »
You can't define a function as a value to an int variable. You are also overwriting your own define. Do this:

Code: [Select]
define se a2dConvert8bit(0)

void control(void){
rprintf("starting");
delay_ms(200);
sensor=sharp_IR_interpret_GP2D12(se);
rprintf("sensor results: %d \n", sensor);
delay_ms(2000);
}

I guess you meant #define se a2dConvert8bit(0)?

Anyway I don't see what wrong with his code ;)
Assuming a2dConvert8bit returns an int and sharp_IR_interpret_GP2D12 takes an int as argument and returns an int, the code is perfectly valid.
I don't understand what you mean by "You can't define a function as a value to an int variable." ;)

But I don't know the API, where can I find the declaration of sharp_IR_interpret_GP2D12?

Chelmi.

Offline Admin

  • Administrator
  • Supreme Robot
  • *****
  • Posts: 11,703
  • Helpful? 173
    • Society of Robots
Re: Axon freezing up when trying to get analog input
« Reply #3 on: October 01, 2009, 08:02:43 AM »
chelmi, thanks for calling me out on this . . . it was too early when I replied, brain wasn't turned on yet . . . I was thinking of the WebbotLib API where you put a port number in that SharpIR function and not a sensor value. I've been using WebbotLib a lot lately and got mixed up. Ignore my previous post!


bsamuels, what do you mean by 'gets hung up'?

Quote
everything works fine when a servo is connected to one of the said ports.
Whats your battery voltage, and how many Sharp IRs are you using?

Offline bsamuelsTopic starter

  • Jr. Member
  • **
  • Posts: 28
  • Helpful? 0
Re: Axon freezing up when trying to get analog input
« Reply #4 on: October 01, 2009, 04:15:12 PM »
chelmi, thanks for calling me out on this . . . it was too early when I replied, brain wasn't turned on yet . . . I was thinking of the WebbotLib API where you put a port number in that SharpIR function and not a sensor value. I've been using WebbotLib a lot lately and got mixed up. Ignore my previous post!


bsamuels, what do you mean by 'gets hung up'?

Quote
everything works fine when a servo is connected to one of the said ports.
Whats your battery voltage, and how many Sharp IRs are you using?

I placed rprintf's for telling me where in the code it freezes.

Code: [Select]
void control(void){
rprintf("starting");
delay_ms(200);
rprintf("delay successful");
int se=a2dConvert8bit(0);
rprintf("a2d conversion successful");
se=sharp_IR_interpret_GP2D12(se);
rprintf("sensor results: %d \n",se);
delay_ms(2000);
}

When I press the button, hyperterminal says:
starting
delay successful

After leaving it for several minutes, it did not continue on to displaying "a2d conversion successful". The only way to get it out of this frozen state is by cutting the power.
 
Only one IR device is connected, and the battery is 6v.

Offline Admin

  • Administrator
  • Supreme Robot
  • *****
  • Posts: 11,703
  • Helpful? 173
    • Society of Robots
Re: Axon freezing up when trying to get analog input
« Reply #5 on: October 02, 2009, 08:19:48 AM »
What actual voltage is your battery at, as measured with a voltage meter?

Did you modify any other Axon code, such as the ADC initialization stuff?

Also for this:
int se=a2dConvert8bit(0);

you should declare se as an int outside of your loop.

Offline bsamuelsTopic starter

  • Jr. Member
  • **
  • Posts: 28
  • Helpful? 0
Re: Axon freezing up when trying to get analog input
« Reply #6 on: October 02, 2009, 04:24:27 PM »
What actual voltage is your battery at, as measured with a voltage meter?

Did you modify any other Axon code, such as the ADC initialization stuff?

Also for this:
int se=a2dConvert8bit(0);

you should declare se as an int outside of your loop.

Measured through a voltmeter, it reads an average of 6.5v.

I have replaced all the code in the pwm folder with my own pwm functions for better usability.

Other than that, I haven't made any modifications.

Offline Admin

  • Administrator
  • Supreme Robot
  • *****
  • Posts: 11,703
  • Helpful? 173
    • Society of Robots
Re: Axon freezing up when trying to get analog input
« Reply #7 on: October 03, 2009, 08:13:27 AM »
Try using 100% default code, and see if it still freezes up. If it doesn't, your code is breaking something.

Offline bsamuelsTopic starter

  • Jr. Member
  • **
  • Posts: 28
  • Helpful? 0
Re: Axon freezing up when trying to get analog input
« Reply #8 on: October 06, 2009, 04:32:14 PM »
ok, now it is using all of the original source code except the control file looks like the following:
Code: [Select]
void control(void){
rprintf("starting");

delay_ms(2000);
}

With the analog sensor disconnected, hyperterminal prints "starting" over and over every 2000 ms

With the analog sensor connected, hyperterminal prints "starting" ONCE, and does not continue (waited 30s)

I think that the port is fried or something.

Offline Admin

  • Administrator
  • Supreme Robot
  • *****
  • Posts: 11,703
  • Helpful? 173
    • Society of Robots
Re: Axon freezing up when trying to get analog input
« Reply #9 on: October 06, 2009, 09:01:02 PM »
I'm pretty sure something is wrong with your sensor. Are you sure you got the wiring on it right?

The reason I ask is some people mistake the wiring on a sharp IR as ground/power/signal, but its actually power/ground/signal . . .

Check the sensor AND the Axon with a multimeter while its plugged in, too.

Offline bsamuelsTopic starter

  • Jr. Member
  • **
  • Posts: 28
  • Helpful? 0
Re: Axon freezing up when trying to get analog input
« Reply #10 on: October 07, 2009, 09:18:20 PM »
I'm pretty sure something is wrong with your sensor. Are you sure you got the wiring on it right?

The reason I ask is some people mistake the wiring on a sharp IR as ground/power/signal, but its actually power/ground/signal . . .

Check the sensor AND the Axon with a multimeter while its plugged in, too.

I don't think it's the wiring because I saw how the wires are to be arranged in the diagram in  the manual and wired it accordingly.

SENSOR (facing forward)
Y  B   R

Y  R   B
BOARD  <-outside edge

As for using the multimeter while it is trying to run, where do you want the current to be tested? on the battery, sensor pins, or what?

Offline airman00

  • Contest Winner
  • Supreme Robot
  • ****
  • Posts: 3,650
  • Helpful? 21
  • narobo.com
    • Narobo.com - Mechatronics and related
Re: Axon freezing up when trying to get analog input
« Reply #11 on: October 08, 2009, 06:51:45 AM »
I had a similar problem a long time ago, and never found a real reason.
It had something to do with the timer. Try commenting out   delay_ms   and commenting out all the timer_init in Axon.c . For delays use delay_us(delay in microseconds), because that doesn't use a timer.
Check out the Roboduino, Arduino-compatible board!


Link: http://curiousinventor.com/kits/roboduino

www.Narobo.com

Offline Admin

  • Administrator
  • Supreme Robot
  • *****
  • Posts: 11,703
  • Helpful? 173
    • Society of Robots
Re: Axon freezing up when trying to get analog input
« Reply #12 on: October 08, 2009, 07:18:45 AM »
As for using the multimeter while it is trying to run, where do you want the current to be tested? on the battery, sensor pins, or what?
Voltage should be measured. Across the sensor pins, and across the Axon pins.

Offline bsamuelsTopic starter

  • Jr. Member
  • **
  • Posts: 28
  • Helpful? 0
Re: Axon freezing up when trying to get analog input
« Reply #13 on: October 09, 2009, 08:39:51 PM »
I had a similar problem a long time ago, and never found a real reason.
It had something to do with the timer. Try commenting out   delay_ms   and commenting out all the timer_init in Axon.c . For delays use delay_us(delay in microseconds), because that doesn't use a timer.

This worked, I thank you good sir.

But on an off note, any reason why my sensor results are scaling inversely with distance from the sensor? If I have an object right in front (10cm) away from its aperture, I get a result like 90, and if I move an object about 70cm away, I get results like 20-30.

Might this be a wiring problem?

Offline Admin

  • Administrator
  • Supreme Robot
  • *****
  • Posts: 11,703
  • Helpful? 173
    • Society of Robots
Re: Axon freezing up when trying to get analog input
« Reply #14 on: October 09, 2009, 09:46:10 PM »
But on an off note, any reason why my sensor results are scaling inversely with distance from the sensor? If I have an object right in front (10cm) away from its aperture, I get a result like 90, and if I move an object about 70cm away, I get results like 20-30.

Might this be a wiring problem?
Nope, thats normal.


Are you using the latest Axon code version?

Offline bsamuelsTopic starter

  • Jr. Member
  • **
  • Posts: 28
  • Helpful? 0
Re: Axon freezing up when trying to get analog input
« Reply #15 on: October 10, 2009, 08:51:29 PM »
But on an off note, any reason why my sensor results are scaling inversely with distance from the sensor? If I have an object right in front (10cm) away from its aperture, I get a result like 90, and if I move an object about 70cm away, I get results like 20-30.

Might this be a wiring problem?
Nope, thats normal.


Are you using the latest Axon code version?

Yessir, but what's the advantage?

 


Get Your Ad Here

data_list