CCU4 counting direction

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

cross mob
User10696
Level 4
Level 4
First solution authored
I am using a CCU4 slice to count the number of pulses output from another CCU4 slice.
I want to be able to set the direction of the counter by software, but cannot find a way to do this. The counting direction bit TCST.CDIR is read only. There does not seem to be any bit anywhere to select the direction.
The direction can be controlled by an external event, but the inputs of the events are all other peripherals, there is no software input.

I feel sure there must be a way to control the direction by software.

Does anyone have any ideas?
0 Likes
2 Replies
GreenGrid
Level 3
Level 3
5 replies posted 10 sign-ins 5 sign-ins

I ran into the same issue and spend some time on it since it's a gating item in my design.

The best I could find is to to tie the slice counting 'direction' to a (unused) pin, and then control the pin using software :

Here is my code (works for a CCU8 or CCU4 slice)

XMC_CCU8_SLICE_DirectionConfig() ; // tie the 'direction' function to an event

XMC_CCU8_SLICE_SetInput() ; // tie the event to an input of the slice

XMC_GPIO_Init(); // Configure a pin that connects to that input of the slice

Now control the pin with :

XMC_GPIO_SetOutputLevel();

Its rather ugly, but it works and as far as I can tell this is the only way to change the timer direction using SW in an XMC device.

 

0 Likes
amanning
Level 4
Level 4
50 sign-ins 25 replies posted 10 questions asked

I think you are right, there does not seem to be a way to directly set the direction by SW.  Direction can only be set via an input event. One of the possible inputs for the events is Service Request.

I have not tried this myself, but I think it should work:

Set the direction event input to a CCU4 service request. Map an unused interrupt (either from the same slice or another slice) to this service request. The interrupt can then be set and cleared via the CC4ySWS and CC4ySWR registers.

This is still a very ugly solution but at least you can keep everything within one slice.

0 Likes