cancel
Showing results for 
Search instead for 
Did you mean: 

PSoC 4 MCU

JoWi_3984961
New Contributor II

Is there any difference between zero and one

when it comes to setting the  buffered compare register

of the PSoC 4 Timer Counter Pulse Width Modulator (TCPWM) PSoC® Creator™ Component?

f(0) = f(1) ??

From the data sheet we have:

Note PSoC 4000 devices write the 16 bit compare buffer register with the decremented compare value in the Up counting mode (except 0x0u), and the incremented compare value in the Down counting mode (except 0xFFFFu).

So let's say we are up counting.  We want zero.

So, we must write a zero.

Ok, now we are tired of zero.  We want ONE.  So, we write the "decremented" version of ONE, which is zero, again.

What changed?

(The other case, counting down, is similar, but perhaps worse?)

I see the philosophy of one versus zero has changed on PSOC 4.  Where is this headed?

.

0 Likes
1 Solution
BragadeeshV
Moderator
Moderator

Hi JohnWinters​,

The hardware IP if PSoC 4000 is different from the other PSoC 4 devices. To match for this, the following implementation is done in the firmware:

void Timer_WriteCompareBuf(uint32 compareBuf)

{

    #if (Timer_CY_TCPWM_4000)

        uint32 currentMode;

    #endif /* (Timer_CY_TCPWM_4000) */

    #if (Timer_CY_TCPWM_4000)

        currentMode = ((Timer_CONTROL_REG & Timer_UPDOWN_MASK) >> Timer_UPDOWN_SHIFT);

        if (((uint32)Timer__COUNT_DOWN == currentMode) && (0xFFFFu != compareBuf))

        {

            compareBuf++;

        }

        else if (((uint32)Timer__COUNT_UP == currentMode) && (0u != compareBuf))

        {

            compareBuf --;

        }

        else

        {

        }

    #endif /* (Timer_CY_TCPWM_4000) */

  

    Timer_COMP_CAP_BUF_REG = (compareBuf & Timer_16BIT_MASK);

}

In up counting mode, if you write any value other than 0, it is decremented. This means, if you write 1, it becomes 0. So, if you want 1, write 2.  If you want 0, write 1.

Regards,

Bragadeesh

Regards,
Bragadeesh

View solution in original post

0 Likes
6 Replies
JoWi_3984961
New Contributor II

Is two safe?  Is it the same as one?  Or one and zero? Is two really one?  Or is one really zero?  Is it all just a big off by one thing?

BragadeeshV
Moderator
Moderator

Hi JohnWinters​,

The hardware IP if PSoC 4000 is different from the other PSoC 4 devices. To match for this, the following implementation is done in the firmware:

void Timer_WriteCompareBuf(uint32 compareBuf)

{

    #if (Timer_CY_TCPWM_4000)

        uint32 currentMode;

    #endif /* (Timer_CY_TCPWM_4000) */

    #if (Timer_CY_TCPWM_4000)

        currentMode = ((Timer_CONTROL_REG & Timer_UPDOWN_MASK) >> Timer_UPDOWN_SHIFT);

        if (((uint32)Timer__COUNT_DOWN == currentMode) && (0xFFFFu != compareBuf))

        {

            compareBuf++;

        }

        else if (((uint32)Timer__COUNT_UP == currentMode) && (0u != compareBuf))

        {

            compareBuf --;

        }

        else

        {

        }

    #endif /* (Timer_CY_TCPWM_4000) */

  

    Timer_COMP_CAP_BUF_REG = (compareBuf & Timer_16BIT_MASK);

}

In up counting mode, if you write any value other than 0, it is decremented. This means, if you write 1, it becomes 0. So, if you want 1, write 2.  If you want 0, write 1.

Regards,

Bragadeesh

Regards,
Bragadeesh

View solution in original post

0 Likes