Jump to content

interpolation algorithm


rasteri
 Share

Recommended Posts

what's wrong with a shift?

I didn't say there was anything wrong with a shift.

it's a native operation of the processor, therefore fast and there's a native operator in C?

That's correct.

maybe you could use a byte-address to do what you want?:

<snip>

All that work demonstrates that you've kinda missed my point - I expected the language to take care of this, without my interaction, without writing extra code, without messing around, etc. It doesn't. No problem! I just kinda assumed that it would be 'smarter' than it is.

Link to comment
Share on other sites

All that work demonstrates that you've kinda missed my point - I expected the language to take care of this, without my interaction, without writing extra code, without messing around, etc. It doesn't. No problem! I just kinda assumed that it would be 'smarter' than it is.
I think the target of C is to have a language that is more "human" than asm, but enough close to the machine to generate fast code. therefore too much overhead would not do it any good.
I expected the language to take care of this

how should the language "now" what you want to do if you don't tell it ?

but C++ is very powerfull, you could for example write your own operator, that gives you the msb of

an int as result. you can write operators like objects. I never did this, but I think this is a very powerfull

feature. you can even "overload" operators, e.g. if you want to simply add two strings with "+", you can

overload the "+" operator and write a routine to process the string-addition. all other types will be handled

still in the native manner. check it out..

I hope this input is usefull for you  ;)

Link to comment
Share on other sites

I think the target of C is to have a language that is more "human" than asm, but enough close to

the machine to generate fast code. therefore too much overhead would not do it any good.

That's a good point. It's one of the things I have grown to like about C, is that it stays quite low-level, without needing me to do *all* of the thinking ;)

how should the language "now" what you want to do if you don't tell it ?

Magic, of course ;D Hehehe... well of course there are ways to handle it, but in the end, the way it is done makes sense.

but C++ is very powerfull<snip>

I hope this input is usefull for you  ;)

Yeh, thanks dude. I don't know squat about C++!

Link to comment
Share on other sites

I don't have so much experience with C, but during a period with no regular job, I read a book about the language, and made my notes like a proper student  ;D

so I can refer them now, thats very usefull. also I'am familar with the syntax from writing in PHP and JavaScript. There is still some stuff that confuses me, but what I like about C: it seems to be weird, but in the end it is very consequent.

Link to comment
Share on other sites

I did the interpolation algorithm in C, have a look at the code, should work. It interpolates in 33 steps, step can be 0 to 32.

/////////////////////////////////////////////////////////////////////////////
// Interpolate
/////////////////////////////////////////////////////////////////////////////
unsigned char KNOEPFLI_Interpolate32(unsigned char step, unsigned char value1, unsigned char value2)
{
	unsigned char swap, diff;

	//send out value2 if step is the max value
	if( step == 32 ) {
		return value2;
	};
	//send out value1 if step i 0
	if( step == 0 ) {
		return value1;
	};
	//invert the interpolation if value1 > value2
	if( value1 > value2 ) {
		//swap the values
		swap = value2;
		value2 = value1;
		value1 = swap;
		//--step because we are counting from 0 to 32, not to 31
		--step;
		//invert the step counter
		step = ~step;
		//clear the upper three bits
		step &= 0x1f;
	};

	//get the difference
	diff = value2 - value1;

	//divide it through the total number of steps (>>5) and multiply it with step (gives an integer) then get the high byte, 

	//shift the step counter three to the left to make it 8bit, store it in PRODL
	PRODL = step << 3;

	//store diff in PRODH
	PRODH = diff;  

	//do the multiplication in assembler
	__asm
    movf _PRODL, W
    mulwf _PRODH, 0
	__endasm;

	//add the lower value
	return value1 + PRODH;

}

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
 Share

×
×
  • Create New...