Hi all. Just as the title says, I am trying to generate a 1ms heartbeat timer on my XMC4500 hexagon board, but I am running into an error which you can see here: http://imgur.com/o5TGwms .
You can see there at the bottom in Build Output that I am getting the L6200E Error. Now, the reason it says .\Flash\Blinky.axf in front of the error is because I simply opened up the example Blinky project and deleted the contents of Source Files folder and replaced it with the sysTick.c code.
Any help is much appreciated.
Toggle a GPIO at each tick an stick an oscilloscope on it?
Count a thousand, or some ticks, toggle an LED, and guestimate visually?
Read values from another free running timer source, and compare the counts. A timer clocking at 12MHz should see 12000 ticks in a millisecond. A 1 Hz RTC tick will see 1000 counts of a millisecond ticker. Etc.
Hi Pier. I will try some of your suggestions, but just looking at the code do you think it will generate a systick 1ms timer?
#include <stdio.h> #include <XMC4500.h> //SFR declarations of the selected device uint32_t msTicks = 0; /* Variable to store millisecond ticks */ void SysTick_Handler(void) { /* SysTick interrupt Handler. msTicks++; See startup file startup_XMC4500.s for SysTick vector */ } int main (void) { uint32_t returnCode; returnCode = SysTick_Config(SystemCoreClock / 1000); /* Configure SysTick to generate an interrupt every millisecond */ if (returnCode != 0) { /* Check return code for errors */ // Error Handling } while(1); }
It appears to be consistent, provided SystemCoreClock reflects reality.
I presume that's defined in system_arch.c, and reflects the source oscillator and/or PLL settings configured into the chip.
You're asking for a SysTick interrupt to occur 1/1000 of the CPU clock, ie 1 KHz or 1 ms
Here is system_XMC4500.c: gist.github.com/.../9d53320e88c9114a0d17
Here is startup_XMC4500.s: gist.github.com/.../bce8d21af5019e816f97
What are your thoughts now, Pier? Do you think I will be generating a 1ms systick timer?
I think you need to take some responsibility to test/evaluate this yourself. I haven't read the manual for your part, and don't have the board.
You are right, Pier. My next step would be to somehow test the board and see if I am truly generating a 1ms systick timer.
You mentioned several ways I can do this, but which way do you think would be the easiest/most efficient considering the board I am using?
With an oscilloscope or frequency counter.
Pier, I understand what you meant by turning on a GPIO at every 1ms tick, I am just having a hard time figuring out where in my current code to add the additional code to toggle the GPIO? How do you think I should approach this?
The best approach is to start reading code interleaved with reading the documentation for the processor and the OS and the runtime library. Continue reading until you understand what the code does - and how it does it. You can't get further if everything you see is just some black magic.
Hi, Per. So I have been taking a look at the reference manual for the XMC4500 and found some interesting stuff regarding configuring a GPIO to be an output. In this case, I want the GPIO to be my 1ms systick timer.
Here is my configuration: http://imgur.com/0ue0MRt . As you can see I have attached the Pin Extension Card to the main board so that I can have a GPIO to attach an oscilloscope probe to.
I found this: http://imgur.com/p4mDG0o in the reference manual which shows where each pin of the Pin Extension Card is connected to on the MCU. I have decided to go with Pin 41 'COM_GPIO0' as my output for the 1ms systick timer.
Now, I am having trouble figuring out how to code that pin as my output. I only found these steps: http://imgur.com/qiMa6w2 , but it is hard to follow without an example. Could you help me figure this out, or do you know of any examples I could try to follow?
I think you'd want to review example materials from Infineon
#include <stdio.h> #include <XMC4500.h> //SFR declarations of the selected device volatile uint32_t msTicks = 0; /* Variable to store millisecond ticks */ void SysTick_Handler(void) // Entering every 1 ms (1 KHz) { /* SysTick interrupt Handler. msTicks++; See startup file startup_XMC4500.s for SysTick vector */ // Pseudo-code // if (msTicks & 1) // 2ms period, 500 Hz on scope // SetGPIOHigh(); // else // SetGPIOLow(); } int main (void) { uint32_t returnCode; // Pseudo-code // EnableGPIOPeripheralClock(); // EnableGPIOPin(); returnCode = SysTick_Config(SystemCoreClock / 1000); /* Configure SysTick to generate an interrupt every millisecond */ if (returnCode != 0) { /* Check return code for errors */ // Error Handling } while(1); }
Hi, Pier. Where did you find this code, or did you come up with it yourself? I need some more information to help me make sense about what the commented-out pseudocode is doing.
I am especeially interested in knowing what the following pseudo-code is doing. Could you explain it a little more, Pier? How does 'msTicks & 1' generate a 2ms period and thus 500Hz?
// Pseudo-code // if (msTicks & 1) // 2ms period, 500 Hz on scope // SetGPIOHigh(); // else // SetGPIOLow();
msTicks gets incremented each ms.
on odd tick, high is called. on even tick, low is called.
so a high low cycle occurs with 2 of the msTicks
so the frequency is 500ms
easy. no?
Hi, sudo. I understand this, but how does 'msTicks & 1' get this done? To me '&' is just a bitwise AND operator.
EDIT:
So lets say msTicks is 7, then 7 & 1 = 7. Which is odd, so signal to pin goes HIGH. Then lets say msTicks is 8, then 8 & 1 = 8. Which is even, so signal to pin goes LOW. This completes our 2ms/500Hz cycle.
Is this how it works?