You are here

fast access to control_reg | Cypress Semiconductor

fast access to control_reg

Summary: 5 Replies, Latest post by Bob Marlowe on 23 Nov 2016 04:55 AM PST
Verified Answers: 2
Last post
Log in to post new comments.
Turtle's picture
User
17 posts

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);

user_1377889's picture
User
9583 posts

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

Turtle's picture
User
17 posts

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?

user_1377889's picture
User
9583 posts

" 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

Turtle's picture
User
17 posts

Again Thanks, Bob, this is exactly what I was looking for.

Turtle

user_1377889's picture
User
9583 posts

You are always welcome, Turtle.

 

Bob

Log in to post new comments.