Is there a way to create a simple up/down counter that rolls over from FFFFFFFF->0?

Tip / Sign in to post questions, reply, level up, and achieve exciting badges. Know more

cross mob
Anonymous
Not applicable

I feel as though I am missing something very obvious. I would really like a 32-bit up/down counter with the count "exposed" as a 32 bit bus that rolls over from 32'hFFFFFFFF -> 32'h00000000 and also from 32'h00000000 ->32'hFFFFFFFF.

The closest thing I can find is the BasicCounter Component, but there is no up-down option for this component.

I have tried coding my own in Verilog and it takes a huge amount of P-terms, so I am trying different work-arounds.

I think I can create a custom UDB component that will exhibit the correct rollover behavior, but I don't think I can "expose" the Accumulator as a digital output. Is this assumption correct?

Is there an easy option on the Counter Component that I am missing or misunderstanding?

0 Likes
9 Replies
HeLi_263931
Level 8
Level 8
100 solutions authored 50 solutions authored 25 solutions authored

The existing Counter 3.0 component can be set to:

  • UDB-based
  • 32-bit
  • Count-Input and Direction (or Clock with UpCnt and DownCnt)

This should do what you want.

Anonymous
Not applicable

My understanding is that if I use the selections you have given, it will always rollover to the Period value, based on Figure 1 on page 6 of the datasheet. It says not to set the period to all 1's or all 0's, which would inhibit the rollover behavior I desire.

Additionally, the count is not exposed as digital outputs.

Am I missing something about the Period value? I think my misunderstanding is stemming from this value.

For example: If I set the Period to 0 (Which the datasheet says not to do), then I rollover from FFFFFFFF->00000000, then count down, it will stay at 00000000 instead of rolling back to FFFFFFFF.

0 Likes
Anonymous
Not applicable

Ah I think I might have found what I am looking for. I can disable all of the reload conditions and it will just wrap normally, without reloading to the period. On page 10 of the datasheet "If there is no reload condition, then the counter wraps around and continues counting without a counter register reload."

0 Likes

Just to clarify: the period defines the maximum value the counter can ever reach. If you set it to 0, the counter can only reach 0, so it will never change.

The period is useful if you need a counter to e.g. up to 1000 - then you can use a 16 bit counter and set the period accordingly. The counter then will wrap around from 9991000 to 0.

(edited to reflect the correction below - the actual period of the counter is always one more than the configured period)

0 Likes
Anonymous
Not applicable

According to the datasheet, your last statement is incorrect given the "Count input and direciton" configuration. Examine Figure 1 on Page 6 of the datasheet. It shows the behavior of the component, which overflows and underflows to the Period, not at the period.

It uses and 8 bit counter with period of 100. It counts up from 0 -> 255 then reloads to 100. Or it counts down from 255->0 then reloads to 100. This is inconsistent with your statement.

The datasheet seems to disagree with itself on this point, but I believe the period register changes function depending on the Clock Mode.

0 Likes

regarding the period - I corrected my post. I always confuse the period value

If you really need a counter with 32 outputs available, the BasicCounter is your only option. If you need up-down capability, you need to implement this by yourself, chaining together 4 UDBs. This viedo might be a good starting point: http://www.cypress.com/video-library/PSoC/how-create-counter-customizing-udb-component-psoc-5lp/3861...

0 Likes
Anonymous
Not applicable

I'm not sure you understood my reply. The Period is not the maximum value the counter can attain while using Count Input and Direction. It reflects a completely different functionality.

0 Likes

If the period is not the maximum value of the counter, then what is it?

(Actually there are two meaning for 'period' when using the PSoC UDB counter: one is the value you configure in the settings dialog of the component. The other meaning is the number of different states / values the counter can have while counting. Both meanings differ by one, so a counter with 10 states countes from 0 up to 9, or from 9 down to 0, and has a maximum value of 9)

0 Likes
Anonymous
Not applicable

When using the counter in "Count Input and Direction" It is the value that the counter reloads to. Again, I invite you to look at Figure 1 on Page 6 of the datasheet. It explains this alternative use of "period" pretty well. Your source of confusion is the same as my source of confusion when I asked the question

If you leave "reload counter at TC" on, it will reload from the max value (FF, FFFF, FFFFFF, FFFFFFFF) to whatever you have in the period register. If you uncheck that option, it will reload to 00.

I think the datasheet does a poor job of reflecting this and is rather unintuitive.

In any case, I have figured out my problem, I just want to make sure the thread doesn't have incomplete or incorrect information.

0 Likes