[sdiy] help...no make8() function in Arduino...converting PIC to AVR
dan snazelle
subjectivity at hotmail.com
Wed Apr 11 18:06:11 CEST 2012
On Apr 11, 2012, at 11:53 AM, Ove Ridé wrote:
> On 11 April 2012 17:25, dan snazelle <subjectivity at hotmail.com> wrote:
>> can someone help me ?
>>
>> i am trying to convert some PIC code to AVR
>>
>> it is going fine except for 2 things
>>
>> there is no make8() function and there is no _mul()
>>
>>
>> so code lines like this:
>>
>>
>> tmp1 = _mul (acc1, val1);
>
> Do you have a definition of what the function is supposed to do
> exactly? It might help if you could tell me the types of the three
> variables.
> I suspect it's either just an accelerated form of multiplication, or
> multiplication of two bytes which returns the higher byte of the
> answer. Again, some context would be useful.
> You can always try defining a macro so you don't have to edit the code
> in a million places. Something like
>
> #define _mul(x,y) ((x)*(y))
>
> or
>
> #define _mul(x,y) ((x)*(y)>>8)
>
> Yes, the excessive parentheses are needed in order to guarantee
> correct behavior!
>
>> tmpbyte1 = make8(tmp1, 1);
>
> make8 is apparently a macro/function to pick out a byte from a bigger
> data type. Something like the following should suffice:
>
> #define make8(val, offset) ( ( (val)>>((offset)*8) ) & 0xFF)
>
> Again, yes, it sucks in terms of readability to have all those
> parentheses there, but the C preprocessor just does string
> substitution and for example something like 2*make8(1+x,2) would break
> because of operator precedence, without the parentheses.
>
> But C for PIC8's sucks, and you should probably look into completely
> reorganizing the code if you plan on permanently switching to AVR. AVR
> has much better C support and you don't need as much of these
> architecture specific tricks.
>
> --
> /Ove
>
> Blog: <http://blog.gg8.se/>
>
> "Here is Evergreen City. Evergreen is the color of green forever."
>
OK
from what I can tell
make8 is called whenever there is a
static int16 being asked to be converted into a
static int8
now on AVR an int8 would be a byte I think and an int16 would be an int
the other part of the make8(x,x); is the 2nd variable, usually a 1
so
tmpbyte1 = make8(tmp1, 1);
is asking for tmp1 to be somehow mixed with 1 and turned into a byte
for _mul,
tmp2 = _mul (acc2, tmpamt);
it is asking for a result (tmp2) which is in int16 format (so int on an AVR)
the two parameters inside the parentheses are both int8's (bytes)
_mul(int8, int8)
so MAYBE _mul is trying to multiply two bytes into an int???
thanks
More information about the Synth-diy
mailing list