- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hi,
I am using a control_reg to control two stepper motors. The motors are controlled by two different functions.
Currently I do
Control_Reg_Motors_Write(Control_Reg_Motors_Read() | step_bit);
or
Control_Reg_Motors_Write(Control_Reg_Motors_Read() & ~step_bit);
to set and clear bits.
Isn´t this slow? Would it be better to use a copy of the control register content that is updated in both functions so that it is not needed to read the control_reg?
control_reg_copy |= step_bit;
Control_Reg_Motors_Write(control_reg_copy);
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Your line
control_reg_copy |= step_bit;
is a read-modify-write access as well. The difference in the timing is not much and lies in the range of µs. In the generated controlregister.h file you will see a declaration of the register itself, so you may use your above scheme directly on the control register and not on a shadow copy.
Bob
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Thanks, Bob!
One more question. If I need to update the control register both in an ISR and in the normal code, I think I must
ISR_Disable();
ManipulateControlReg();
ISR_Enable();
to be safe. Is that ok? Is that fast? Is there a better solution?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
" Is there a better solution?" Yes, there is. When not disturbing your concept a CyEnterCriticalSection() and CyExitCriticalSection() would be the most common solution. See "System Reference Guide" from Creator help menu.
Bob
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Again Thanks, Bob, this is exactly what I was looking for.
Turtle
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
You are always welcome, Turtle.
Bob