PDA

View Full Version : [Question(s)] Axon Programming Questions



WGhost9
07-04-2009, 11:37 AM
I am currently working on getting the Axon controller to talk to a Lynxmotion wireless controller. The trouble is I am having a hard time tracking down function documentation for controlling the Axon pins for all of the functions used in the Axon tutorials. I was wondering if someone online could explain to me the following functions:

1) How do sbi(,) and cbi(,) operate? (What are their input/outputs and how do they affect the controller's pins?)

2) What do the system constants DDRA and PORTA signify and how are they different? What about the constant PINA for?

3) How does _BV() operate?

Thank you very much for all the advice you can offer.

lnxfergy
07-04-2009, 04:21 PM
sbi(REGISTER_NAME, BIT_#) cbi(REGISTER_NAME, BIT_#) = set bit, clear bit.

DDRA = Data direction register A, PortA = output to port A, PinA = input from. Take a look at the data sheet for the atmega you are using. Or, take a look at my AVR tutorial (it's majorly unfinished, but I opened it up to public viewing since this question came up) EDIT: A linky would help here: http://forums.trossenrobotics.com/tutorials/introduction-129/avr-basics-3261/

_BV = bit value.. its just a helper, BV(0) = 0x01, BV(1) = 0x02, BV(2) = 0x04.... BV(x) = 2^x

-Fergs

WGhost9
07-04-2009, 05:12 PM
Well thats very helpful Fergy! that tutorial really explains alot too.

WGhost9
07-04-2009, 07:12 PM
So I am having a very strange error; something is wrong with the timers with my axon controller:

When I try to run the sample codes provided, I am told that the timer0Init() and the timer2Init() are undefined references, so I have commented them out as well as the timer resets. This may have caused the subsequent problem. The problem I am having is that when I execute the code, the axon board freezes on the line:
delay_ms(1);
I have verified this with rprintf() statements that the axon stops here and nowhere else.

I was hoping someone could explain to me why the axon would freeze at this line and why the the timerInits are unrecognized by the code.

Thanks very much.

Adrenalynn
07-04-2009, 07:19 PM
Yeah, that's the funny thing with commenting out code you don't understand.. Turn off the timers and suddenly things that need timers don't work.

I'd kinda call that "expected behavior".

WGhost9
07-04-2009, 07:30 PM
Do you know if the delay_ms() function is related to the timer0init()? I dont think it is. I have been reading up on it and the function seems independant

lnxfergy
07-04-2009, 07:50 PM
Often, the system clock relies on Timer0.... and delay is typically derived from the system clock (that way interrupts don't affect how long your pause for).

This is the same as you would find on the arduino.

-Fergs

Adrenalynn
07-04-2009, 08:32 PM
[Moderator Note: Threads merged. They didn't really need to stand alone. Both were "Axon Programming Questions" as/per original. Thanks! -A]

WGhost9
07-04-2009, 09:55 PM
So then if the timer initialization is nessecary to the delay function, then why is the timer0init unrecognized by the compiler? My headers are:

#include "SoR_Utils.h"
#include "hardware.c"
#include "sensors.c"
#include "control.c"

Am I missing a header?

Adrenalynn
07-04-2009, 10:45 PM
What header is timer0init in?

WGhost9
07-04-2009, 11:47 PM
haha, thats the trouble, I cant find it in any header :P-- which of course would be exactly why its not recongized by the compiler. If only I knew the header I could include it :/

Adrenalynn
07-04-2009, 11:49 PM
http://www.wingrep.com/

lnxfergy
07-05-2009, 10:12 AM
timer640.h

Right out of the documentation on Society of Robots: http://www.societyofrobots.com/axon/axon_function_list.shtml#delays


There are two ways to create a time delay, or a pause, in your code. The first way offers the maximum time resolution possible. This method should be used if you do not require exact timing, but works well enough for servos and general wait commands:
delay_cycles(65500);
The second method involves using a timer interrupt on timer0. Typically this is the 'correct' wait for doing a delay, but could potentially cause conflicts if you are using other timer interrupts or have other time-sensitive algorithms running simultaneously.
delay_us(1000);//delay for 1000us
delay_ms(1000);//delay for 1000ms
delay_cycles uses a long int, so you can't delay more than 2^16 = 65536 (for 0 to 65535). Just do something like this to delay longer:
delay_cycles(65500);
delay_cycles(65500);
delay_cycles(65500);
Refer to timer640.h for more documentation on the timer. Note that the compiler will ignore delay_cycles if you turn on compiler optimization.

WGhost9
07-05-2009, 02:13 PM
Thanks for all the advice; timer640.h indeed includes the timer_inits however it is already #included in the SOR_UTILS and should therefore be defined. I treid including it a second time in my control.c but the functions remain unrecognized.

lnxfergy
07-05-2009, 03:42 PM
Thanks for all the advice; timer640.h indeed includes the timer_inits however it is already #included in the SOR_UTILS and should therefore be defined. I treid including it a second time in my control.c but the functions remain unrecognized.

is the code possibly wrapped in a #ifdef? Might you be missing a definition related to which processor? Are you sure you have a good makefile (where said definitions would typically be)?

-Fergs

WGhost9
07-05-2009, 08:31 PM
Aha-ha! I have found the problem; the version of the timer reset and timer inits in Timer640.h have a '_' removed and added respectively changing their names slightly. Correcting their names in the ps2 code causes them to be recognized succesfully. However, this version of timer_init is no longer a void input but requires an input (defined as uint8 prescalar). I am working on what this input should be, but any suggestions are welcome :). Thanks for the continued support.

WGhost9
07-05-2009, 08:40 PM
Update 2: Getting the timer functions to be recognized does not prevent the Axon from crashing on the line

delay_ms(1);

WGhost9
07-06-2009, 01:42 PM
Well today I go to write some inverse kinematics for my Axon controlled project only to find it lacks basic math functions like square root and inverse sine etc. Currently I am messing around with trying to import math.h from the c library of Microsoft studio but it is proving annoyingly problematic. Rather than reinvent the wheel, I was wondering i anyone here has already written a math.h for the axon and would be so kind as to share it. Thanks very much,

WGhost9

lnxfergy
07-06-2009, 01:47 PM
Well today I go to write some inverse kinematics for my Axon controlled project only to find it lacks basic math functions like square root and inverse sine etc. Currently I am messing around with trying to import math.h from the c library of Microsoft studio but it is proving annoyingly problematic. Rather than reinvent the wheel, I was wondering i anyone here has already written a math.h for the axon and would be so kind as to share it. Thanks very much,

WGhost9

You probably want the math library from AVR-Libc
http://www.nongnu.org/avr-libc/user-manual/group__avr__math.html

-Fergs

Adrenalynn
07-06-2009, 02:22 PM
[Moderator Note: Threads merged. They didn't really need to stand alone. Both were "Axon Programming Questions" as/per original. Thanks! -A]


[Moderator Note: Threads merged. They didn't really need to stand alone. Both were "Axon Programming Questions" by the same user, as/per original. Thanks! -A]

WGhost9
07-06-2009, 05:15 PM
Thanks fergy! that is presicely what I was looking for. Very helpful.