| Electronics > Microcontrollers |
| Cheap microcontroller for JavaScript or fast interpreter. |
| << < (7/7) |
| Georgy.Moshkin:
--- Quote from: zapta on January 06, 2025, 05:27:59 am ---Have you tried to ask chatgpt to translate it for you? You can give it as many hint as you need, and then review the code and tweak. --- End quote --- Instead, I ask it to find errors in my translation. It has spotted type casting and signed/unsigned problems several times. Translation from C to JavaScript itself is very easy for me. I do things like this: --- Code: ---// JavaScript: maxIndHistory.splice(0,1); // shift maxIndHistory.push(curSpectrumMaxInd); // store // C: memmove(&maxIndHistory[0], &maxIndHistory[1], sizeof(maxIndHistory)-sizeof(maxIndHistory[0])); // <--- shift maxIndHistory[HISTORY_SIZE-1]=curSpectrumMaxInd; // <--- store --- End code --- Problems often emerge from things like this: --- Code: ---// JavaScript arm_sqrt_q31() "simulation" deviation=Math.round(Math.sqrt((deviation/2)/0x7FFFFFFF)*0x7FFFFFFF); deviation=deviation/32768/16; // /32768 - convert to normal sqrt output /16 to scale into 0.255 range // C: deviation = deviation >> 1; arm_sqrt_q31((q31_t)deviation,(q31_t *) &deviation); deviation = deviation >> 19; // SHR 15+4 /32768 / 16 --- End code --- I need to maintain this stuff. Plus, I have a separate MATLAB-like script to calculate some coefficients. I'm in the process of eliminating this stuff. Will take some time, but it's worth it. |
| Navigation |
| Message Index |
| Previous page |