go_away

Author Topic: Ping))) on Axon  (Read 3149 times)

0 Members and 1 Guest are viewing this topic.

Offline TomasTopic starter

  • Full Member
  • ***
  • Posts: 111
  • Helpful? 0
Ping))) on Axon
« on: January 22, 2009, 06:48:35 AM »
Hi. I was just testing the sonar out on my axon unit, and I had a little problem.

I run the code

int sonar_Ping(void)
   {
   #define PINGPIN    3          // assign a pin to the Ping Sensor
   #define DDR        DDRA
   #define PORT       PORTA
   #define PIN        PINA

   PORT_ON(DDR, PINGPIN);   // Switch PingPin to OUPUT
   // ------Trigger Pulse--------------
   PORT_OFF(PORT, PINGPIN);   // Bring PingPin low before starting trigger pulse
   delay_us(2);        //  Wait for 2 microseconds
   PORT_ON(PORT, PINGPIN);    // Bring PingPin High for 5us according to spec sheet.
   delay_us(5);       // Wait for 5 microseconds
   PORT_OFF(PORT, PINGPIN);; //  Bring PingPin Low and standby
   //--------End Trigger Pulse---------------------
   FLIP_PORT(DDR, PINGPIN);   // Switch PingPin to INPUT
   loop_until_bit_is_set(PIN, PINGPIN);     // Loop until the the PingPin goes high  (macro found in sfr_def.h)
   //clears timer, reset overflow counter
   reset_timer_0();       //reset timer 0
   loop_until_bit_is_clear(PIN, PINGPIN);     // Loop until the the PingPin goes low  (macro found in sfr_def.h)
   //read timer0's overflow counter
   //255 is count before overflow, dependent on clock
   
   return (timer0GetOverflowCount()*255+TCNT0) * 2.068965517;//elapsed time x conversion
   }


And here is my control()

void control(void)
   {
   int i=0;
   int range=0;
   
   while(i<2000)
      {
      range=sonar_Ping();
      rprintf("Range: %d",range);
      delay_ms(2000);
      i++;
      }
   }


So the problem is, that this just runs once. The ping((( sonar starts its green light, and on the terminal I get
System Warming Up.................Initialization Complete
Range: x

And thats it. It does not run again. I am 99% sure that its the Sonar_Ping(); that is causing the problem (when its already active, it doesnt want to go again). Anyone know a solution?

Btw, this is a slightly modified 1.01 version of the axon source code. Couldnt get any of the later versions running.
« Last Edit: January 22, 2009, 06:49:40 AM by Tomas »

Offline yerbie

  • Full Member
  • ***
  • Posts: 62
  • Helpful? 3
Re: Ping))) on Axon
« Reply #1 on: January 22, 2009, 07:20:16 AM »
hmm, I'm also using the PING))) and the sonar_Ping() code works fine for me.  Why don't you put some other rprintfs around there and see if it continues to prints to screen or does it get stuck inside of the sonar_Ping()  method.

Offline TomasTopic starter

  • Full Member
  • ***
  • Posts: 111
  • Helpful? 0
Re: Ping))) on Axon
« Reply #2 on: January 22, 2009, 08:24:04 AM »
It seems like its stopping at

   rprintf("6 ");
   loop_until_bit_is_set(PINE, PingPin);    // Loop until the the PingPin goes high  (macro found in sfr_def.h)
   rprintf("7 ");

It went through the whole thing one time, then it stopped at 6

Heres the print

test 1 2 3 4 5 6 7 8 9  Range: 30test 1 2 3 4 5 6

Any clue?

edit; I've changed the pin to pin E5, still the same error.
« Last Edit: January 22, 2009, 08:25:17 AM by Tomas »

Offline yerbie

  • Full Member
  • ***
  • Posts: 62
  • Helpful? 3
Re: Ping))) on Axon
« Reply #3 on: January 22, 2009, 08:58:44 AM »
looks like it's stuck waiting for that pin to go high again.  Maybe it's not waiting long enough between low to high.  try changing delay_us(2) -> delay_us(5).

make sure its plugged into pin A3.

Offline TomasTopic starter

  • Full Member
  • ***
  • Posts: 111
  • Helpful? 0
Re: Ping))) on Axon
« Reply #4 on: January 22, 2009, 09:27:26 AM »
Allright, heres the code with the changes

Code: [Select]
int sonar_Ping(void)
{
#define PINGPIN    3          // assign a pin to the Ping Sensor
#define DDR        DDRA
#define PORT       PORTA
#define PIN        PINA

rprintf("1 ");
PORT_ON(DDR, PINGPIN);   // Switch PingPin to OUPUT
// ------Trigger Pulse--------------
rprintf("2 ");
PORT_OFF(PORT, PINGPIN);   // Bring PingPin low before starting trigger pulse
delay_us(5);        //  Wait for 2 microseconds
rprintf("3 ");
PORT_ON(PORT, PINGPIN);    // Bring PingPin High for 5us according to spec sheet.
delay_us(5);       // Wait for 5 microseconds
rprintf("4 ");
PORT_OFF(PORT, PINGPIN);; //  Bring PingPin Low and standby
//--------End Trigger Pulse---------------------
rprintf("5 ");
FLIP_PORT(DDR, PINGPIN);   // Switch PingPin to INPUT
rprintf("6 ");
loop_until_bit_is_set(PIN, PINGPIN);     // Loop until the the PingPin goes high  (macro found in sfr_def.h)
//clears timer, reset overflow counter
rprintf("7 ");
reset_timer_0();       //reset timer 0
rprintf("78 ");
loop_until_bit_is_clear(PIN, PINGPIN);     // Loop until the the PingPin goes low  (macro found in sfr_def.h)
//read timer0's overflow counter
//255 is count before overflow, dependent on clock
rprintf("9 ");

return (timer0GetOverflowCount()*255+TCNT0) * 2.068965517;//elapsed time x conversion
}


Still just shows the output to

Code: [Select]
System Warming Up.................Initialization Complete
 test 1 2 3 4 5 6 7 78 9  Range: 33 test 1 2 3 4 5 6

Offline Admin

  • Administrator
  • Supreme Robot
  • *****
  • Posts: 11,632
  • Helpful? 169
    • Society of Robots
Re: Ping))) on Axon
« Reply #5 on: January 22, 2009, 09:43:48 AM »
Hmmmm strange . . . I have two theories . . . one is your battery is running low . . .

and two, because it freezes on this line:
loop_until_bit_is_set(PIN, PINGPIN);

that perhaps it is a ghost short and sometimes isn't connected?

Offline TomasTopic starter

  • Full Member
  • ***
  • Posts: 111
  • Helpful? 0
Re: Ping))) on Axon
« Reply #6 on: January 22, 2009, 09:52:07 AM »
It does the exact same thing every time I reset it, so I dont know about the shortage. The one distance measurement we get seems totally fine to, giving logical values and such.

A few things though.

1. The light on the ping sonar just keeps on lighting after the first measurement (it doesnt stop, as I thought it were supposed to do, dunno though).

2. I cant really seem to find anything about this sfr_def.h-file which the nonfunctioning function is refering to. Where can I find more information on this header? Is it supposed to be on my computer? Because I searched for it, and found nothing.

Im pretty sure the battery is OK btw. I've used both a powerfull powersupply and 2 different batteries, one of them was just fully charged(quite big batteries to, 7.2 Volts, 2500 MAH). All three gives the same result.

Offline Admin

  • Administrator
  • Supreme Robot
  • *****
  • Posts: 11,632
  • Helpful? 169
    • Society of Robots
Re: Ping))) on Axon
« Reply #7 on: January 22, 2009, 09:55:42 AM »
Try this:

run the code on the Axon
after it freezes, reset the Ping power but not the Axon power

report what happens . . .

(I'm really not sure whats going on, but this will narrow the options)

Offline TomasTopic starter

  • Full Member
  • ***
  • Posts: 111
  • Helpful? 0
Re: Ping))) on Axon
« Reply #8 on: January 22, 2009, 10:17:17 AM »
Good idea Admin. I just did that (I added a delay of 5 seconds allowing me to remove and add the +,- and signal cable to the ping sensor.

When I did this, I got more readings!

Code: [Select]
System Warming Up.................Initialization Complete
 test 1 2 3 4 5 6 7 8 9  Range: 59  test 1 2 3 4 5 6 7 8 9  Range: 57  test 1 2
3 4 5 6 7 8 9  Range: 59

Perhaps the sonar is broken?

Offline Admin

  • Administrator
  • Supreme Robot
  • *****
  • Posts: 11,632
  • Helpful? 169
    • Society of Robots
Re: Ping))) on Axon
« Reply #9 on: January 22, 2009, 10:36:23 AM »
Do you have an oscilloscope to capture pin pulses? There is the possibility that the Ping is broken. Do you own any other mcus to test it on?

Offline TomasTopic starter

  • Full Member
  • ***
  • Posts: 111
  • Helpful? 0
Re: Ping))) on Axon
« Reply #10 on: January 22, 2009, 10:47:34 AM »
I'll check the Ping on the oscilloscope.. :) I have some of other types laying around, maybe I'll test it on one of those (or maybe just buy a new one...)

Offline jpwalters

  • Jr. Member
  • **
  • Posts: 18
  • Helpful? 0
Re: Ping))) on Axon
« Reply #11 on: March 07, 2009, 06:16:18 PM »
Tomas, if you figure out (or have figured out) what the problem is with your sensor, please give us an update.  We are having a very similar problem with our Ping))) sensor on the Axon, and if you find a solution we'd love to hear it.

Offline TomasTopic starter

  • Full Member
  • ***
  • Posts: 111
  • Helpful? 0
Re: Ping))) on Axon
« Reply #12 on: March 12, 2009, 06:05:57 AM »
I havent figured it out yet. What kind of problem are you experiencing with it? I would love to get it fixed.

Offline pomprocker

  • Supreme Robot
  • *****
  • Posts: 1,430
  • Helpful? 16
  • Sorry miss, I was giving myself an oil-job.
Re: Ping))) on Axon
« Reply #13 on: March 12, 2009, 10:01:56 AM »
I noticed that I have the same problem when I put my ping on any other pin but adc pin c2.

Offline TomasTopic starter

  • Full Member
  • ***
  • Posts: 111
  • Helpful? 0
Re: Ping))) on Axon
« Reply #14 on: March 13, 2009, 05:40:20 AM »
Wow, I guess I'll have to try that pin then. But isnt the ping digital? Does it work on a analog to digital converter pin then?

Offline pomprocker

  • Supreme Robot
  • *****
  • Posts: 1,430
  • Helpful? 16
  • Sorry miss, I was giving myself an oil-job.
Re: Ping))) on Axon
« Reply #15 on: March 13, 2009, 12:47:28 PM »
when i wrote this code i was using on the sensor side (adc pins) because on the $50 robot those are the regulated power buses

  #define PINGPIN    2          // assign a pin to the Ping Sensor
   #define DDR        DDRC
   #define PORT       PORTC
   #define PIN        PINC

Offline jpwalters

  • Jr. Member
  • **
  • Posts: 18
  • Helpful? 0
Re: Ping))) on Axon
« Reply #16 on: March 13, 2009, 05:58:30 PM »
Hmm, we'll have to give that a shot then and see what happens.  Probably won't get a chance to try it until Tuesday though.  I'll update if we have any progress.

Tomas, we're basically having the same exact issues you are having.  When placed in a loop, it freezes at the "loop until bit is set" macro.

Offline TomasTopic starter

  • Full Member
  • ***
  • Posts: 111
  • Helpful? 0
Re: Ping))) on Axon
« Reply #17 on: March 16, 2009, 05:18:53 AM »
when i wrote this code i was using on the sensor side (adc pins) because on the $50 robot those are the regulated power buses

  #define PINGPIN    2          // assign a pin to the Ping Sensor
   #define DDR        DDRC
   #define PORT       PORTC
   #define PIN        PINC



Im a little confused. If im trying this on the axon, will I use port c2 then? Because that is a digital I\O battery unregulated line. Im not familiar with the 50$ robot, sorry.

Anyway, Im trying to use port c2, and it didnt really make any difference. Still stops after one reading.

Should I try using a ADC (analog I\O?) line instead of a digital I\O? The analog has regulated power. And the ADC ports on axon is numbers and not letters. How do I change the code

  #define PINGPIN    2          // assign a pin to the Ping Sensor
   #define DDR        DDRC
   #define PORT       PORTC
   #define PIN        PINC

to the number version?

Offline TomasTopic starter

  • Full Member
  • ***
  • Posts: 111
  • Helpful? 0
Re: Ping))) on Axon
« Reply #18 on: March 16, 2009, 05:50:30 AM »
Yeah FFS!

   #define PINGPIN    0          // assign a pin to the Ping Sensor
   #define DDR        DDRF
   #define PORT       PORTF
   #define PIN        PINF


this will work on the axon! If you are having problems with the ping sensor, just use ADC pin 0, or "F0". YEAH!

Perhaps update the sensor.c file and sensors at the axon source code?

Offline Admin

  • Administrator
  • Supreme Robot
  • *****
  • Posts: 11,632
  • Helpful? 169
    • Society of Robots
Re: Ping))) on Axon
« Reply #19 on: March 16, 2009, 10:59:47 AM »
You can always use regulated power, but connect the signal pin somewhere else.

Offline TomasTopic starter

  • Full Member
  • ***
  • Posts: 111
  • Helpful? 0
Re: Ping))) on Axon
« Reply #20 on: March 16, 2009, 02:36:42 PM »
Well I tried using digital I\O and regulated power, but it did not improve the matter. But connecting the ping sensor to an adc port made it work :)

Offline jpwalters

  • Jr. Member
  • **
  • Posts: 18
  • Helpful? 0
Re: Ping))) on Axon
« Reply #21 on: March 16, 2009, 03:17:03 PM »
Glad to see you got it working!  We will try doing the same thing tomorrow and see if we have as much luck.  I'll report back what we find out, as that might imply this being a "feature" of using the Ping))) with that particular function on the Axon.

 


Get Your Ad Here