I recently started working with LPC8N04 and as I'm quite new to this, I just lost a ton of time with CTIMER match register size. Variable used in the driver code for it has size of 32 bits (uint32_t), which in theory is the same in the microcontroller documentation, but after reading into it, only first 16 bits are used and the rest is reserved. I didn't know that at the beginning and only after a long time I found out that it is not the fault of my code, but the value that I assigned gets later cut down to 16 bits.
So my question is why do they use uint32_t, with no warning about it (except for one place in the MCU documentation), if they could easily use uint16_t instead?
Solved! Go to Solution.
Hi ppaw
I understand your questions. LPC8N04 has two CTIMERs 16bit timer(CT16B) and 32bit timer(CT32B).
Accordingly, MR is 16bit for CT18B and 32bit for CT32B.
both of CTIMERs use CTIMER_SetupMatch to setup match register.
I checked, its indeed no judgement in this function for CT16B. It will be good to add a warning inside this function for CT16B if MR over 16bit.
I will suggest it to SDK development team. Thanks.
Best Regards
Jun Zhang
Hi ZhangJennie,
I'm using SDK: SDK_2.x_LPC8N04DevBoard. I based my code on demo ctimer_match_example, but I'm not sure how can I find a direct link to it.
In the base version of the example, it works because the value assigned to the matchValue: "matchConfig.matchValue = EXAMPLE_CTIMER_CLK_FREQ / 10;" can fit into 16 bits. If you switch it eg: "matchConfig.matchValue = EXAMPLE_CTIMER_CLK_FREQ;" and in debug mode compare the value of matchConfig.matchValue and EXAMPLE_CTIMER.MR[0], you will see that:
matchConfig.matchValue = 500000 (binary 1111010000100100000)
EXAMPLE_CTIMER.MR[0] = 41248 (binary 1010000100100000) - cut down to 16 bits
Thanks,
ppaw
Hi ppaw
I understand your questions. LPC8N04 has two CTIMERs 16bit timer(CT16B) and 32bit timer(CT32B).
Accordingly, MR is 16bit for CT18B and 32bit for CT32B.
both of CTIMERs use CTIMER_SetupMatch to setup match register.
I checked, its indeed no judgement in this function for CT16B. It will be good to add a warning inside this function for CT16B if MR over 16bit.
I will suggest it to SDK development team. Thanks.
Best Regards
Jun Zhang
Hi Jun Zhang,
Ok, I understand my mistake. Thanks a lot.
HI ppaw
Which demo code do you work with, any link?
if SDK, which version of it?
Thanks,
Jun Zhang