8-bit micro ba ang gamit mo?
about processing time, madami din techniques. like 8-bit micros can handle efficiently 8-bit data like unsigned char rather than float and double data types.
1. Use do {} while (--var); instead of for() . This translates to decfsz
6. Avoid multiplications and divisions. These add large codes also. Use shifts and add or successive subtraction. Or simplify the equation.
... ;Dpaano ito gawin sa CCS C? kelangan ko laging mag-multiply saka mag-divide ng int variables..
Post your equation here, I will help you simplify and code it.
input=read_adc();..input=input*(-1) / 4 + 64 ;
for example meron akong int variable na "input", yung present value nya is galing sa result ng ADC..yung range nya is {0.. 255}, pero gusto ko syang i-round off sa range na {64.. 0}..Code: [Select]input=read_adc();..input=input*(-1) / 4 + 64 ;para syang ganito: y = -0.25x + 64paano ba sya isi-simplify?
y = x >> 2;y -= 64;y = -y;
For the 1st line is shift right 2 times or divide by 4.The second line is like y = y - 64. This is just a C shortcut.The third line is to negate the value.
y = x >> 2;y = -y;y -= 64;
Same result.But the last line must be y+=64 on your code.
y = x >> 2;y = -y;y += 64;
ok.. just like this:Code: [Select]y = x >> 2;y = -y;y += 64; pwede 2 examples pa? hehe.. plan ko kasi gawin syang parang auto range..(1)what if ang range ng input ko is {0.. 127}, pero same pa rin range ng result {64.. 0}bale ang equation nya is y = -0.5X + 64..(2) what if ang range ng input ko is {0.. 511}, result is {64.. 0}equation is y = -0.125x + 64
mga ilang percent kaya ang savings nito sa processing time compared dun sa magdi-divide ka directly? saka iniisip ko, 3 lines ito compared dun sa dati na single line lang..
...But the resulting ASM code is same and sometimes even lesser the 3 lines I posted because it won't use temporary variables...
so, expected na mas mabilis sya kasi di na sya gagamit ng extra variables? by what percent kaya yung decrease sa processing time compared sa dati?
4. Sometimes built-in library has large code. If this happens create your own like using printf. printf uses large code in the lib. Printf has formatting include that you may not use at all.5. Make your code into a function if used many times. Avoid cut-and-paste...