1 of 1 people found this helpful
The existing Counter 3.0 component can be set to:
- Count-Input and Direction (or Clock with UpCnt and DownCnt)
This should do what you want.
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.
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."
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)
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.
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.
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/386151/38126/38126?tid=3…
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)
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.