Welcome, Guest. Please login or register.

Author Topic: Programming question! :)  (Read 3306 times)

Description:

0 Members and 1 Guest are viewing this topic.

Offline Thorham

  • Hero Member
  • *****
  • Join Date: Oct 2009
  • Posts: 1149
    • Show all replies
Re: Programming question! :)
« on: April 16, 2012, 03:51:15 PM »
How long is that list exactly? If it's not too large you can use a table, which would certainly be the fastest way.
 

Offline Thorham

  • Hero Member
  • *****
  • Join Date: Oct 2009
  • Posts: 1149
    • Show all replies
Re: Programming question! :)
« Reply #1 on: April 16, 2012, 04:24:18 PM »
Quote from: bloodline;688789
The problem is that the threshold boundaries are not linear (and for the purpose of this task can't be calculated...
What are those values exactly?

Quote from: bloodline;688789
I'm probably going to have a loop that compares against an array of threshold values. I was just hoping it could be done in a nice simple table for maximum performance :)
If you can have an array of threshold values, then you might still have your table. How big is the largest value?
 

Offline Thorham

  • Hero Member
  • *****
  • Join Date: Oct 2009
  • Posts: 1149
    • Show all replies
Re: Programming question! :)
« Reply #2 on: April 16, 2012, 05:30:31 PM »
Quote from: bloodline;688794
The values are rotational time values and I need to set an index dependant on a specific time. They scale somewhat geometrically, but not exactly, and I don't have enough CPU time to calculate that anyway :-/
I was going to say that you don't have to calculate anything if you know the thresholds beforehand, and can just use a table, but ...

Quote from: bloodline;688794
The largest value is 60,000 (a lookup table is totally out of the question) :)
... if a 60000 entry long array is out of the question, then what's the target system (memory constraints)? Is such a table too large? Or is the problem that the thresholds are floating point? If it's floating point, and you don't need more than three decimals of precision (which 60,000 leads me to believe), then a table may still possible (fixed point).

Please provide us with some more information here, because you've left out crucial details.
 

Offline Thorham

  • Hero Member
  • *****
  • Join Date: Oct 2009
  • Posts: 1149
    • Show all replies
Re: Programming question! :)
« Reply #3 on: April 16, 2012, 06:12:44 PM »
Quote from: bloodline;688813
The target system is an ATMega328 :) and Sam Crow has poked my brain and given me exactly the solution I was trying to think of... Funny how I could see it in 68k Asm (that haven't used for 15 years), but not in C
Ah, that clears it up then. On a system with such a small amount of memory, a table is indeed out of the question :)
 

Offline Thorham

  • Hero Member
  • *****
  • Join Date: Oct 2009
  • Posts: 1149
    • Show all replies
Re: Programming question! :)
« Reply #4 on: April 19, 2012, 03:15:00 PM »
Quote from: bloodline;689507
On an 8bit microcontroller, you really want to avoid multiplication and division (unless you can use a power of 2... ie left or right shifts). I really did try to do this mathematically first, but realised that I simply don't have the CPU time :)
Out of interest, how often is this code  executed per second (seems quite often seeing how that controller does 1 mips per Mhz (according to the specs I looked up at least))? Also, for the challenge, would it be a problem to post the whole threshold array here? Maybe there's a nice trick possible ;)