Using a Memory Copy block to read/write a single bit gives an error, and workaround not working?

25 views (last 30 days)
Hi, I am trying to read data from and write data to an ePWM register. I can read the whole register, but when I try to read half (EPwm2Regs.TBPHS.half.TBPHS) or just a single bit (e.g., EPwm2Regs.TBCTL.bit.PHSDIR), I get a compiling error:
error: taking the address of a bit field is not allowed
As a workaround, I can read a whole register (EPwm2Regs.TBCTL), and then extract a single bit (PHSDIR = bit 13).
However, if I try to write to a single bit or half, I also get the same error.
I tried to use a similar approach: reading the whole register, changing a particular bit and then writing a new value to the same register, but this does not work.
1) Do I need to do anything else to enable writing using the Memory Copy block?
2) Is it possible to write to only one bit or half register? In Texas Instruments help files this seems to work
My setup for writing a phase offset looks like this
Memory copy destination (&EPwm2Regs.TBPHS)
Application
I am trying to write to the upper part of the TBPHS register a new value, but it seems the memory copy block cannot overwrite the existing value. I used a similar approach to write to a single bit, but it didn't work either.
ePWM2 block settings
  1 Comment
Walter Roberson
Walter Roberson on 17 Oct 2023
From what I have seen, these days very few devices have hardware bit-addressing -- and the few that do only seem to have it for a small range of addresses (that is, they might have special peripheral I/O commands that allow setting individual bits for I/O registers... but not for general memory)
The TMS320C28x does not appear to have any bit-addressing capabilities

Sign in to comment.

Answers (1)

Antonin
Antonin on 17 Oct 2023
Edited: Antonin on 17 Oct 2023
Hi Mike,
A workaround is to use the .all notation to have access to the whole register, you can then use bit manipulations to access the bit you want. Getting the address of .all will work
So in the Memory Copy block to access EPwm2Regs.TBCTL.bit.PHSDIR use the source code symbol with &EPwm2Regs.TBCTL.all and use a mask and shift to access the bit you want. The same trick applies for both read and write operations.
I hope it helps,
Antonin.

Products


Release

R2018a

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!