Project help!arduino brushless motor control

Nice.

I do note that you have jettisoned any idea of deceleration.

Also, in your original, you had

void rc_read_values() {
  noInterrupts();
  memcpy(RC_VALUES, (const void *)RC_SHARED, sizeof(RC_SHARED));
  interrupts();
}

which I did not look at closely, but had assumed took care of the other problem with multi-byte variables shared between an ISR and regular code.

Those variables must be volatile, you did that.

But access to them outside the ISR must be protected. Most ppl do something like

  noInterrupts();
  int myCopy = someVolatileInt;
  interrupts();

to make their own local copy of a volatile mulit-byte variable. Here, myCopy gets the value from someVolatileInt with interrupts briefly suspendered. Then they use that copy everywhere they would otherwise the original.

You may have had no trouble, but this is def something that can bite, and can be very difficult to realize what's happening.

caveat programmer

a7

Yeah, my idea of deceleration is to release the throttle and let it coast to a stop. Not sure if that is a good or bad idea yet.

Also, I'm not sure if I follow, but do I need to add the below noInterrupts code to my existing sketch?

I don't know how to explain it any better, so I googled

Arduino protected access noInterrupts 

and maybe this is worth a few minutes

You have to read and write variables that are shared with an ISR with interrrupts temporarily turned off.

You can grab a copy and work with that subsequent without worrying that the ISR will interfere.

a7

I was able to add the interrupt routines into my code. So far the code and the motor response are working as they should. Thanks for all the help!

1 Like

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.