Show Posts
Pages: [1] 2 3 4
1  Using Arduino / Programming Questions / Re: DIY Fixed-point Multiplication and Speed on: July 30, 2011, 10:39:55 am
I'm not sure about the status of that particular implementation, but I haven't really found much documentation about it. My code doesn't follow a "standard" method of implementation either. The number of fractional bits, Q, changes constantly based on how the bits are filling up the intermediate 32-bit result (since I only want 16-bit multiplications). I wrote it as such so multiplication between numbers with different number of fractional bits can be done with the same function call.

Unfortunately, I still haven't been able to make any progress with the speed issue.
2  Using Arduino / Programming Questions / Re: DIY Fixed-point Multiplication and Speed on: July 28, 2011, 07:10:00 am
If nobody bothers to make a wheel for themselves once in a while, eventually wheel-making will become an esoteric art. Also, bicycle wheels shouldn't be used on sedans, sedan wheels shouldn't be used on off-roads, off-road wheels shouldn't be used on track cars, track car wheels shouldn't be used on aeroplanes, aeroplane wheels shouldn't be used on bicycles. The concept of a wheel is implemented differently to suit specific needs.

However, I didn't know there's an implementation of fixed-point included in with the IDE. I thank you for that portion of your input.
3  Using Arduino / Programming Questions / Re: DIY Fixed-point Multiplication and Speed on: July 28, 2011, 06:44:38 am
Thanks! I haven't tried any other fixed-point libraries since most of them don't seem to match my applications. I looked at some information about fixed-point here and there but most of the algorithm's just intuitive so there should be lots of room for improvement (a great source for brain workouts).
4  Using Arduino / Programming Questions / DIY Fixed-point Multiplication and Speed on: July 28, 2011, 05:52:10 am
Hello! Today, I decided to push the limits of the 8-bit AVR that is the heart of the Arduino and decided to write a fixed-point arithmetic library. Initial testing suggested that I could make each 16-bit fixed-point multiplication 2 times faster (~4us per mult compared to ~9us) than that of a floating point multiplication. The comparison may seem unfair because the floats are 32-bit, but I doubt I need at 32-bits at this point, hence 16-bit.

Anyway, I wrote the class for signed fixed-point and some functions and also downloaded a pretty fast assembly multiplication routine for integers here: http://mekonik.wordpress.com/2009/03/18/arduino-avr-gcc-multiplication/. I currently use the signed 16-bit x 16-bit to 32-bit routine.

I'm now going to talk about problems with the code, which is attached to this post.

Initially, the results were pretty good. Multiplications with positive and negative results individually took around ~3 to 4us. The algorithm (important part in my code) I wrote to find the 2 most significant bytes are very similar for both. I then added a conditional statement to check if the initial 32-bit result was positive or negative before passing it to the appropriate function. Oddly, it seemed that this single conditional statement costs over 6us to execute! Also, the positive result multiplication (without the conditional statement) starts to perform weirdly and now takes ~15us! The negative result multiplication still takes ~3us but jumps to ~9us if the conditional statement is included.

Unfortunately, I still only know an insignificant amount of assembly so I cannot see what's happening behind the IDE. But there might be two problems which I am unable to detect. The first is possibly in the positive result MSB selection code:
Code:
hp16(int32_t &a, uint8_t &b)
which is extremely similar to the version for negative results.

The second problem is with how the conditional statement:
Code:
iv<0?hn16(iv, iq):hp16(iv, iq)
is being handled.

If anyone is interested in helping me analyse the code, I'll greatly appreciate it! It'll also be great if anyone has suggestions to make it even faster.

By the way, the various performance times can be checked by changing the value of
Code:
#define TYPE
in fp.h.

Bo Xuan
5  Using Arduino / Programming Questions / Re: Functions with Priorities on: May 12, 2011, 03:09:30 am
Yep I'm using the ITG3200. By 1kHz, do you mean read frequency or bandwidth or something else?

ARM is indeed tedious. I took something like 2 days to get the LED blinking with timers as compared to 1 minute with Arduino. I'm using Yagarto with Eclipse though. The BlueBoard LPC1768-H comes with a nice secondary bootloader which I'm currently using since I haven't purchased a JTAG adapter. All the problems others talk about with OpenOCD etc make me quite hesitant about taking that path at this point.

Then again, a 100MHz, 32bit MCU capable of single cycle integer multiplication is simply irresistible.
6  Using Arduino / Programming Questions / Re: Functions with Priorities on: May 12, 2011, 02:48:43 am
Hello Senso, I wrote my own code but some parts are similar to Madgwick's. Mine's pretty decent too I suppose, but I've never tried it on a single atmega328p. The read times for the sensors are too long so I didn't even bother. I use it to control a quadrotor. It's only nearing completion, so I don't know how the frequency of the control loop will affect the stability. Having read some forums, I decided 450Hz would be a relatively safe choice.

I'm building the quadrotor to learn the process (I'm waiting to go to college anyway), so I designed all the hardware and software such that it can be improved in the future. I'm under the impression smaller aircraft will benefit from higher frequency control loops (impression spawned from unknown sources), so everything's designed with that in mind. I might even be changing over to using an ARM processor, which will eliminate all the tedious work with synchronising the two atmegas setup I have right now, plus have a huge performance increase such that I can use more complex algorithms if necessary.

Regarding the sensors, I still haven't found the need to use the maximum bandwidth!

Anyway, we seemed to have deviated from the main topic by quite a bit! smiley-lol
7  Using Arduino / Programming Questions / Re: Functions with Priorities on: May 12, 2011, 12:05:03 am
Considering the fact that floating point arithmetic emulation is used most of the time, 40,000 really isn't all that many even though I'm using relatively computationally efficient quaternion attitude estimation algorithms. Of course, I can rewrite my entire code to use fixed point arithmetic, which I have explored, but that will be for next time.

It really only gets intense during the additional calculations required for drift compensation (from integrating gyro signals). This is taking into account how reading each sensor via I2C takes 180+us (if I remember correctly). If I use one MCU, there will be certain points where two sensor reads must be executed within the same 2.5ms period.
8  Using Arduino / Programming Questions / Re: Functions with Priorities on: May 11, 2011, 10:37:28 am
That's definitely true. The 1ms freshness in data is probably not even noticeable. But when deciding between the two methods, it makes more sense to me to choose the one that will provide the smallest lag between sensor readings to motor control, just in case 1ms really does affect the performance and also to give a little more room to breathe with the algorithms. Then again, I was no in hurry to get the project up and running!
9  Using Arduino / Programming Questions / Re: Functions with Priorities on: May 11, 2011, 10:19:10 am
I initially considered using that method. However, running the AHRS algorithms on one MCU then passing the data over to another MCU for motor control will mean the 2nd MCU receives data that is "older" than if both MCUs operate in parallel or if they use distributed algorithms (which is the method I'm using currently). Although it's a lot more difficult to implement, the motor control response can be based on data around 1ms "younger".

Still, I'll be able to stuff more auxiliary functions in if prioritized functions can be accomplished cleanly!
10  Using Arduino / Programming Questions / Re: Functions with Priorities on: May 11, 2011, 05:01:04 am
I originally thought about implementing something like this for my quadrotor project, which uses two atmega328ps communicating with each other over SPI.

Simplified, A will include reading registers off 3 sensors, running rather computationally intensive attitude heading and reference system algorithms, running 4 PID loops and sending the output to other microcontrollers (in the ESCs).

B will include other functions which are important but do not need strict time keeping like checking battery voltages, telemetry, etc.

Currently, the functions in B are manually assigned to run after A and tested such that the time taken for A+B is still short enough for A to be executed at a specific frequency (400Hz currently). The program can potentially be made to be more efficient with a robust priority control algorithm!
11  Using Arduino / Programming Questions / Re: Functions with Priorities on: May 11, 2011, 12:50:59 am
Thanks for replying!

So in general, there's no clean way to accomplish this unless I use a more capable processor (I'm playing with an LPC1768 too). But if it's a somewhat simple program, it can still be done. Interesting!

CrossRoads: This sounds like using an interrupt to set a flag when it's time for A, and check it very frequently throughout the program. I'm not sure how long it takes for a boolean comparison to complete, but if speed is not a factor, sticking the flag checking code in every other line will probably work!  smiley-sweat
12  Using Arduino / Programming Questions / Functions with Priorities on: May 10, 2011, 11:44:41 pm
Hello people!

I would like to write a simple program that takes function priorities into account, and after some consideration and Googling, I can't come up with any feasible methods to make this work. Does anyone have some pointers to share?

The program could include just two functions, one (lets call it "A") with higher priority than the other. A has to perform a task (e.g. multiplication) after every arbitrary time period (e.g. 1ms). At all other times, the other function ("B") can perform whatever it needs to do. So B can be interrupted (English sense of the word) halfway through so A can be performed, and resumes after A is complete.

This can be achieved with interrupts (stick A into the handler), but this approach cannot be expanded for use in a project where A is more than just a simple operation. Moreover, this method will limit the program to having only two different levels of priority (while A is running, no higher priority function can take over).

Any thoughts? Thanks in advance!
13  Using Arduino / Programming Questions / Re: Unexpected: Serial Print Unsigned Char in Binary Format (Quick Question) on: March 22, 2011, 10:04:23 am
Well I'll just start with printing HEX and DEC. Considering it's just 8 bytes for the USART buffer once every few seconds, it's unlikely to be that as well. I'm not sure how I'll test that though.

Thanks for offering to help debug the entire code. The code is actually for an autonomous quadrotor using distributed algorithms of a quaternion attitude estimator and it requires a lot of specific hardware to even run so I'll just try to fix this myself.

Thanks for the replies anyway!
14  Using Arduino / Programming Questions / Re: Unexpected: Serial Print Unsigned Char in Binary Format (Quick Question) on: March 22, 2011, 09:44:40 am
Honestly, I didn't think the problem would be with those two lines, since I've used Serial.print() many many times before. I thought perhaps I would be caused by attempting it on an unsigned char specifically.

My code is over a thousand lines long so I hardly think it'll be helpful to post it here.

Thanks AWOL for the helpful suggestion! Since the problem probably doesn't lie with the two lines, I'll just have to test entire code again.
15  Using Arduino / Programming Questions / Re: ABOUT THE SENSOR, PLZ HELP, THANK YOU on: March 22, 2011, 09:37:19 am

Great read.

Anyway, I'm not sure whether I understand the question correctly (ring when sensor detects object that stays within 35cm for 1 minute?). We still need to know what sensor it is to help.
Pages: [1] 2 3 4