Author Topic: ping and logicflex  (Read 1622 times)

0 Members and 1 Guest are viewing this topic.

Offline arnil9Topic starter

  • Beginner
  • *
  • Posts: 3
  • Helpful? 0
ping and logicflex
« on: March 23, 2009, 07:15:07 AM »
hello people,

well i read the guide to interfacing the ping sensor to atmega board. well im using the logicflex board and im having a problem with timing. can somebody help me with this. the below link will show you all the specs of the board:

http://www.jkmicro.com/documentation/pdf/lf_man13.pdf

thank you

Offline Soeren

  • Supreme Robot
  • *****
  • Posts: 4,672
  • Helpful? 227
  • Mind Reading: 0.0
Re: ping and logicflex
« Reply #1 on: March 23, 2009, 03:32:20 PM »
Hi,

Nice that you provided the specs of the board!
Now on to the specs of your question... "Having a problem with timing" is a bit vague, please elaborate.
Regards,
Søren

A rather fast and fairly heavy robot with quite large wheels needs what? A lot of power?
Please remember...
Engineering is based on numbers - not adjectives

Offline arnil9Topic starter

  • Beginner
  • *
  • Posts: 3
  • Helpful? 0
Re: ping and logicflex
« Reply #2 on: March 23, 2009, 09:53:58 PM »
ok well im trying to time the delay when u send high pulse and wait and get a low pulse back....the way i saw it done in the tutorial:

step:
1. the ports a defined
2. there is a high pulse sent from the board to the sensor through i/o port
3. there is a 10microsecond delay
4. there is a low pulse sent back
5. the value got is converted to distance

correct me if im not going in the correct direction. well so i was just wondering how i would call a function like delay_us(10) which is there in the tutorial. i have no idea on how to do this. thank you

Offline Soeren

  • Supreme Robot
  • *****
  • Posts: 4,672
  • Helpful? 227
  • Mind Reading: 0.0
Re: ping and logicflex
« Reply #3 on: March 24, 2009, 02:05:59 AM »
Hi,

well so i was just wondering how i would call a function like delay_us(10) which is there in the tutorial.
Well, what you've got is in reality a small DOS based PC, at least from the programming point of view. You can program it in whatever language you can run on a DOS based PC.

What exactly a delay routine is called, will depend on the language you use, but you don't really need a delay routine to time a Ultra Sound (US) ping.

Most programming languages have some mean of timing directly by starting a timer and then reading it (which for some language variants also resets the timer).
Eg in Turbo BASIC (he early version of Power BASIC) you have MTIMER which is a 16 bit timer, so can count (in µs) up to ~20m of sound travel which give you a distance of ~10m to target (since the sound is going to target and then back) and with a much higher resolution than your US hardware can use.

Before you can start programming, you need to decide which programming language you will use.
Then you just make the program, compile it and put it on drive B of your board.
Then you have to make provision for starting the program. I didn't read the manual that close, but I assume there is an AutoExec file that you just write its name in, to start it at power up.


So, which language do you prefer?


Nice board, if the manual holds up. Where did you get it and what did you pay?
Regards,
Søren

A rather fast and fairly heavy robot with quite large wheels needs what? A lot of power?
Please remember...
Engineering is based on numbers - not adjectives

Offline arnil9Topic starter

  • Beginner
  • *
  • Posts: 3
  • Helpful? 0
Re: ping and logicflex
« Reply #4 on: March 24, 2009, 03:32:55 PM »
well i would like to program it in C. and i got the board from a friend of mine.its costs about $250. well as far as what im trying to do is get values here is some code i have wrote up to check for the input from the port. but whenever i run it i get a 0 value. well here it is any way:

#define PORT_A          0x60
   /* address of Port A */

#define PORT_DIR        0x65
   /* address of port direction register */
#define PORT_A_DIR_MASK 0x10
   /* dir bit is bit 4 (00010000) = 0x10 */

main()
{
 unsigned char portA;

 portA = inportb(PORT_DIR);

   /* get current value of direction reg */
 portA |= PORT_A_DIR_MASK; 
   /* set direction bit for input /*
 outportb(PORT_DIR,portA); 
   /* write value to direction reg */
   
 while ( 1 )     /* do it forever */             

   printf("PORT A: %X\n",(int)inportb(PORT_A));
     /*read and print port A value*/

return 0;
}

thank you

Offline Soeren

  • Supreme Robot
  • *****
  • Posts: 4,672
  • Helpful? 227
  • Mind Reading: 0.0
Re: ping and logicflex
« Reply #5 on: March 24, 2009, 04:18:48 PM »
Hi,


For starters, the configuration register (0x65)...
Bit 0 is the port A direction bit
Bit 5 (which you mingle with, although you call it bit 4 in your remark) is the port A interrupt enable (when "1")

Your "while ( 1 )     /* do it forever */" is never closed (with an "end while"), so I assume it is terminated and returning to DOS, if run on the system.

I'm not real certain what you're hoping the code should do, but I think you're getting the registers mixed up.

Your seemingly lack of experience in PC coding holds me from advicing you to use interrupt programming, but your board do have a sweet ability to use interrupts for reporting the US echo (stopping the timing in the INT routine and resetting the counter/timer or whatever method used).
You'd arm the interrupt when the ping has been sent (or concurrently) and the change in input would invoke the interrupt.
You'd probably have to "receive" on either port A or port B and "send" on any other port than that used for input.
Regards,
Søren

A rather fast and fairly heavy robot with quite large wheels needs what? A lot of power?
Please remember...
Engineering is based on numbers - not adjectives