XMClib POSIF as Quadrature encoder example.

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

cross mob
User2235
Level 3
Level 3
Hi,
I need a Example for the POSIF as Quadrature Encoder based on the XMClib.

Ari.
0 Likes
1 Solution
Not applicable
Hi Daryl,

In your example you connected the index flag to P2.8. We are using Ethernet and hence this port can't be used for the index signal since Ethernet needs it.
We suggest that we use P2.15 instead.

It seems that P2.15 can not be connected to the current timer slice. Can you make a change in your example or can you explain the dependencies so that we can make the change ourselves?
Or can you see another solution to our problem?

Many thanks in advance!
Elin

View solution in original post

0 Likes
24 Replies
Not applicable
Hi Ari,

I am working on an example right now and intend to provide by the end of this week.

Regards,
Daryl
0 Likes
User2235
Level 3
Level 3
Daryl,

Are you finishing the example?

Ari.
0 Likes
Not applicable
Hi Ari,

Yes! It's ready! 🙂 I have attached it in this post.

This example uses a DAVE APP "ACIM_FREQ_CTRL" to drive a motor with an encoder unit for the encoder signals (Phase A, Phase B, Index) to be used in the following example for using the POSIF in Quadrature Decoder interface.

The encoder signal (Phase A, Phase B) is connected to the POSIF configured to Quadrature Decoder interface. The signals decoded from the POSIF can be used to monitor the motor. As the motor used in this project produces an index signal that is 1/4 of the tick period. It cannot be decoded via the POSIF interface (See errata "POSIF_AI.001").The Index signal can be connected directly at the port level to the specific timer for monitoring purpose.

For more details, please refer to the example and the XMC reference manual on the usage of the POSIF module.

Regards,
Daryl
0 Likes
User2235
Level 3
Level 3
Daryl,

Great work. Thank you very much.

Ari.
0 Likes
Not applicable
Hi Daryl,

I don't get any values in the variables for captured values. Do I need to hw connect act pin 8 and com pin 16 to get your example working?
Many thanks in advance!
Elin
0 Likes
Not applicable
Hi Elin,

Yes, the connection is required. Also, to monitor the values without stopping the motor, I used the Segger RTT viewer to view the values. This should be installed when you installed the Segger JLink.
In addition, please make sure that the SEGGER_RTT APP is installed on your system. To install this, select "Help -> Install DAVE APP/Example/Device Library..."
1820.attach

Extracted from the Readme.txt file:
HOW TO TEST:
- Connect the pin extension cards to the COM and ACT side of the XMC4400 CPU Board
- Connect the Power Board to the pin extension card connected to the ACT side
- Connect the Pin/8 (ACT) to Pin/16 (COM)
- Apply 24V to the Power Board
- Download and run the demo in the uC.


OBSERVATIONS:
- Using the debugger, observe the speed per configured period clock. (capturedvalue0 and capturedvalue1).
- Opening the J-Link RTT Viewer, the variables capturedvalue0 and capturedvalue1 is printed to the terminal.

Regards,
Daryl
0 Likes
Not applicable
Thanks Daryl, it works now.
Elin
0 Likes
Not applicable
You're welcome, Elin! 🙂
0 Likes
lock attach
Attachments are accessible only for community members.
Not applicable
Hi,

I found some errors in the POSIF example and have updated it now with a new version attached in this thread.

The error was due to the capture slice not configured to clear the timer on each capture event. This has lead to the captured values looking strange although the motor was moving at a constant speed.

Also, it was easier now to monitor the application using the UCProbe developed for XMC by Micrium. If you have not downloaded the UCProbe, you should download it. It should help you in monitoring this example easier. 🙂
https://www.infineonforums.com/threads/4047-Free-download-of-%C2%B5C-Probe-XMC-developed-by-Micrium

Regards,
Daryl
0 Likes
User2235
Level 3
Level 3
Daryl,
Has Infineon plans to release an example of quadrature decoder based on XMC lib?

Ari.
0 Likes
Not applicable
HI Ari,

This example for the POSIF configuration was based on the XMC Lib.
Only the part for driving the motor was using a DAVE APP.

Regards,
Daryl
0 Likes
Not applicable
Hi Daryl,

In your example you connected the index flag to P2.8. We are using Ethernet and hence this port can't be used for the index signal since Ethernet needs it.
We suggest that we use P2.15 instead.

It seems that P2.15 can not be connected to the current timer slice. Can you make a change in your example or can you explain the dependencies so that we can make the change ourselves?
Or can you see another solution to our problem?

Many thanks in advance!
Elin
0 Likes
User7282
Level 4
Level 4
If you check the XMC4400 Reference Manual in the "Port I/O Function Table" section, you can see that you are using the Input Signal B of the CCU40 module (CCU40.INxB).

As you said, P2.15 cannot assigned to the current module, only to CCU42. Then you have to check if there is any other input that you can use for your current application.

As an example P2.0 can be assigned to the Input Signal C of the Timer Slice 1 of CCU40 (CCU40.IN1C).
0 Likes
Not applicable
Thank you Apereira for your suggestion. P2.0 is to my understanding also used by Ethernet functionality so that is not going to work. Do you have any other suggestion for a solution?

Many thanks in advance!
Elin
0 Likes
User7282
Level 4
Level 4
Hello Elin,

You have a few other pins, you can check them in the reference manual.
As another example, you have pin 2.6, connected to CCU40.IN3C. But please notice that this uses the slice 3 of CCU40.

If you want to keep using slice 0, you will havo to use P1.3 or P2.1 (maybe I am missing some additional pins).
0 Likes
Not applicable
HI Elin,

You are right, P2.15 is connected to CCU42. In this case, please refer to the POSIF0 pin connections and alter the use case as required.

POSIF0.OUT0 - CCU40.IN0E, CCU40.IN1E, CCU40.IN2E
POSIF0.OUT1 - CCU40.IN0F, CCU40.IN1F
POSIF0.OUT2 - CCU40.IN1L, CCU40.IN2F, CCU42.IN0E, CCU42.IN1E, CCU42.IN2E, CCU42.IN3E,
POSIF0.OUT5 - CCU40.IN3F, CCU42.IN0F, CCU42.IN1F, CCU42.IN2F, CCU42.IN3F,

In my example, I demonstrated the use of these outputs from POSIF to track the position, number of revolution, capturing the timing based on elapsed number of ticks (period velocity). As you have suggested, you could reconfigure the CCU40.CC42 and CCU40.CC43 to using CCU42.CC42 and CCU42.CC43 to use P2.15. However, this will mean that you will not be able to use the index signal to P2.8 as the external input for the revolution count.

You have to evaluate if this is acceptable for your application.

Regards,
Daryl
0 Likes
Not applicable
Daryl,

Great work. Thank you very much.

Ari.
0 Likes
Not applicable
Hi,

This is an excellent example! Thank you.

By the way, how do I read the position counter from there? I tried XMC_CCU4_SLICE_GetCaptureRegisterValue(SLICE0_PTR,0U), thinking it would get me the count value in CCU40.CC40 but the result is always 0.

Thanks and regards
Loic
0 Likes
Not applicable
OK, I got it. It is the Timer module that actually does the counting so: XMC_CCU4_SLICE_GetTimerValue(SLICE0_PTR) gives me the position.

Best regards
Loic
0 Likes
Not applicable
Hi,

the example is really helpful in understanding the use of POSIF. However I'm facing difficulties making it work on a XMC4800 microcontroller.
As I have to use POSIF1 instead of POSIF0 I changed the corresponding function calls (e.g. XMC_POSIF_Init(POSIF1, &posif_config); instead of XMC_POSIF_Init(POSIF0, &posif_config); ).
The POSIF still doesn't work because the slices of CCU4 haven't been connected to the correct outputs of POSIF1, they are still connected to POSIF0.

/* Configure CC40 event0 - Count on rising edge of Quadrature Clock (POSIF0.OUT0) */
XMC_CCU4_SLICE_CountConfig(SLICE0_PTR, XMC_CCU4_SLICE_EVENT_0);
XMC_CCU4_SLICE_ConfigureEvent(SLICE0_PTR, XMC_CCU4_SLICE_EVENT_0, &position_event0_config);

/* Configure CC40 event1 - Set up count direction on (POSIF0.OUT1) */
XMC_CCU4_SLICE_DirectionConfig(SLICE0_PTR, XMC_CCU4_SLICE_EVENT_1);
XMC_CCU4_SLICE_ConfigureEvent(SLICE0_PTR, XMC_CCU4_SLICE_EVENT_1, &position_event1_config);

/* Configure CC41 event0 - Count on rising edge of POSIF index signal */
XMC_CCU4_SLICE_CountConfig(SLICE1_PTR, XMC_CCU4_SLICE_EVENT_0);
XMC_CCU4_SLICE_ConfigureEvent(SLICE1_PTR, XMC_CCU4_SLICE_EVENT_0, &revolution_event0_config);

/* Configure CC41 event1 - Set up count direction on (POSIF0.OUT1) */
XMC_CCU4_SLICE_DirectionConfig(SLICE1_PTR, XMC_CCU4_SLICE_EVENT_1);
XMC_CCU4_SLICE_ConfigureEvent(SLICE1_PTR, XMC_CCU4_SLICE_EVENT_1, &revolution_event1_config);

/* Configure CC42 event0 - Count on rising edge of Period Clock (POSIF0.OUT2) */
XMC_CCU4_SLICE_CountConfig(SLICE2_PTR, XMC_CCU4_SLICE_EVENT_0);
XMC_CCU4_SLICE_ConfigureEvent(SLICE2_PTR, XMC_CCU4_SLICE_EVENT_0, &tick_event0_config);

/* Configure CC42 event1 - Set up external flush and start on POSIF index signal */
XMC_CCU4_SLICE_StartConfig(SLICE2_PTR, XMC_CCU4_SLICE_EVENT_1, XMC_CCU4_SLICE_START_MODE_TIMER_START_CLEAR);
XMC_CCU4_SLICE_ConfigureEvent(SLICE2_PTR, XMC_CCU4_SLICE_EVENT_1, &tick_event1_config);


My question is: What do I have to change to connect the slices of the timer to POSIF1?

I guess I have to change these definitions in the file xmc_ccu4_map.h

#
define XMC_CCU4_SLICE_INPUT_A (0U)
#define XMC_CCU4_SLICE_INPUT_B (1U)
#define XMC_CCU4_SLICE_INPUT_C (2U)
#define XMC_CCU4_SLICE_INPUT_D (3U)
#define XMC_CCU4_SLICE_INPUT_E (4U)
#define XMC_CCU4_SLICE_INPUT_F (5U)
#define XMC_CCU4_SLICE_INPUT_G (6U)
#define XMC_CCU4_SLICE_INPUT_H (7U)
#define XMC_CCU4_SLICE_INPUT_I (8U)
#define XMC_CCU4_SLICE_INPUT_J (9U)
#define XMC_CCU4_SLICE_INPUT_K (10U)
#define XMC_CCU4_SLICE_INPUT_L (11U)
#define XMC_CCU4_SLICE_INPUT_M (12U)
#define XMC_CCU4_SLICE_INPUT_N (13U)
#define XMC_CCU4_SLICE_INPUT_O (14U)
#define XMC_CCU4_SLICE_INPUT_P (15U)


But in what manner do I have to change the definitions?
Any help is really apreciated! Thanks!
0 Likes
Not applicable
Hi,

the example is really helpful for understanding the use of the POSIF interface. However I have a question. I'm trying to use the POSIF Interface on a XMC 4800. As I have to use POSIF 1 instead of POSIF0, I changed the function calls correspondingly.
Eg:

   XMC_POSIF_Init(POSIF1, &posif_config);


instead of

   XMC_POSIF_Init(POSIF0, &posif_config);


So far the POSIF Interface still doesn't work and I assume it is because the mapping of the POSIF outputs to the CCU4 slices hasn't been changed:

/* Configure CC40 event0 - Count on rising edge of Quadrature Clock (POSIF0.OUT0) */
XMC_CCU4_SLICE_CountConfig(SLICE0_PTR, XMC_CCU4_SLICE_EVENT_0);
XMC_CCU4_SLICE_ConfigureEvent(SLICE0_PTR, XMC_CCU4_SLICE_EVENT_0, &position_event0_config);

/* Configure CC40 event1 - Set up count direction on (POSIF0.OUT1) */
XMC_CCU4_SLICE_DirectionConfig(SLICE0_PTR, XMC_CCU4_SLICE_EVENT_1);
XMC_CCU4_SLICE_ConfigureEvent(SLICE0_PTR, XMC_CCU4_SLICE_EVENT_1, &position_event1_config);



The inputs of the slices of CCU4 seem to be defined in the file config_ccu4.h:

XMC_CCU4_SLICE_EVENT_CONFIG_t position_event0_config =
{
.mapped_input = XMC_CCU4_SLICE_INPUT_E, /* mapped to POSIF0.OUT0 - POSITION tick */
.edge = XMC_CCU4_SLICE_EVENT_EDGE_SENSITIVITY_RISING_EDGE,
.level = XMC_CCU4_SLICE_EVENT_LEVEL_SENSITIVITY_COUNT_UP_ON_HIGH,
.duration = XMC_CCU4_SLICE_EVENT_FILTER_DISABLED
};


What do I have to do to change the input of the slice so the signal from POSIF1 is routed to the slice?

Any help is apreciated! Thanks!
0 Likes
User12281
Level 1
Level 1
I use an incremental encoder, and try to use the index signal to reset the position count to prevent the position error accumulation problem. The index signal is connected to the CCU41 event0. I detected it happens with an oscilloscope. I use following code to setup the interrupt.
/* Enable CC41 event */
XMC_CCU4_SLICE_EnableEvent(SLICE1_PTR, XMC_CCU4_SLICE_IRQ_ID_EVENT0);

/* Connect capture on CC41 event 0 to SR0 */
XMC_CCU4_SLICE_SetInterruptNode(SLICE1_PTR, XMC_CCU4_SLICE_IRQ_ID_EVENT0, XMC_CCU4_SLICE_SR_ID_0);

/* Set NVIC priority */
NVIC_SetPriority(CCU41_0_IRQn, 3U);

/* Enable IRQ */
NVIC_EnableIRQ(CCU41_0_IRQn);

The interrupt service routine:
void CCU41_0_IRQHandler(void)
{
/* Clear pending interrupt */
XMC_CCU4_SLICE_ClearEvent(SLICE1_PTR, XMC_CCU4_SLICE_IRQ_ID_EVENT0);

// Reset position count
XMC_CCU4_SLICE_SetTimerValue(SLICE0_PTR, 0);
}

However, the interrupt never happens. Does anyone can help me to find what I did wrong? I appreciate any suggestion to make it work.

Regards,
Yaoxin
0 Likes
User15538
Level 1
Level 1
Hi, I'm having the same problem as Yaoxin, where the interrupt never happens.
Im using a XMC4500, where the only thing I changed from the example given by Daryl Neo was the following lines of code

code in main:

XMC_GPIO_Init(P1_3, &posif_encoder_inputport_config); /* A */
XMC_GPIO_Init(P1_2, &posif_encoder_inputport_config); /* B */
XMC_GPIO_Init(P1_1, &posif_encoder_inputport_config); /* index */


code in config_posif.h

XMC_POSIF_CONFIG_t posif_config =
{
.mode = XMC_POSIF_MODE_QD, /**< POSIF Operational mode */
.input0 = XMC_POSIF_INPUT_PORT_A, /**< Choice of input for Input-1 */
.input1 = XMC_POSIF_INPUT_PORT_A, /**< Choice of input for Input-2 */
.input2 = XMC_POSIF_INPUT_PORT_A, /**< Choice of input for Input-3 */
.filter = XMC_POSIF_FILTER_DISABLED, /**< Input filter configuration */
};


Everything else is equal to the example given, but my code never enters the interrupt and I really can´t understand why, is there something else I need to change to have POSIF working in the pins I'm using?

Any help is greatly appreciated. I really don't know what is wrong

Regards,
Carlos
0 Likes
User22536
Level 1
Level 1
the download in the thread seems not to work and in the manual is not much written about the QD-Posif.
Thanks
Lars
0 Likes