Skip to main content
KoenR's user avatar
KoenR's user avatar
KoenR's user avatar
KoenR
  • Member for 9 years, 6 months
  • Last seen more than 4 years ago
  • Netherlands
awarded
awarded
awarded
awarded
awarded
awarded
awarded
awarded
comment
Are static variables in a function bad?
That is exactly what I meant. This function will be called every 5 milliseconds. So that is why I wanted to know which is faster. But next time better to call memoize
comment
Are static variables in a function bad?
Hello Nick, yes you are right, when the function "starts up" it is calledwith Iteration -1. The amount of iterations it takes is depended on the DeltaPosition and the Velocity. Normally this will 500+
comment
Are static variables in a function bad?
@NickGammon timed the calculations. WOW! When using the static variables the calculation took +- 150 micros. Now if use it the formula without the statics it will take an astonishing 0 - 4 microseconds to calculate. Then I realised that the compiler still exists. All my variables were predefined (not changing). Now I runned it like it should, all the iterations with a static variable took 50 micros whereas the one without took 200 micros. In the end, statics are sometimes viable I guess
comment
Are static variables in a function bad?
I know it are some beefy calculations, for now those cannot be replaced. Luckely this function will not be called twice, once every loop. If one of the variables change then the Iteration starts at -1 again. I did remove the pow function, rather complex for a simple square
comment
Are static variables in a function bad?
Hmm that is a huge difference. Unfortunately that is not what I meant. When Iteration == -1, then those variables are calculated. These variables will be used in further iterations. Because I intitialized them as statics they remember their value, now these do not have to be calculated over and over again. But is it worth the memory loss?
comment
Are static variables in a function bad?
That too, but I actually meant the calculations of the statics at iteration == -1. Won't this save? If not, I can make those local
comment
Are static variables in a function bad?
No but my idea was to calculate some variables infront (iteration -1) how could i use those otherwise?
comment
Are static variables in a function bad?
I am still a newbie haha, hmm better replace that pow function...
asked
Loading…
comment
Increase PWM bit resolution
Am I able to use this with a CAN-bus shield which CS is on port 9? If so, is it only changing this line of code: DDRB |= _BV(PB1) | _BV(PB2);
answered
Loading…
accepted