Quality RTOS & Embedded Software

 Real time embedded FreeRTOS RSS feed 
Quick Start Supported MCUs PDF Books Trace Tools Ecosystem


Loading

PIC24/dsPIC timer period is 1 clock too long

Posted by Dan Henry on August 23, 2010
From the "Timers" Reference Manual sections for these devices (Example 11-1 and Figure 11-4 in all manuals) we can see that prvSetupTimerInterrupt() in port.c should be changed from:

const unsigned long ulCompareMatch = ( configCPU_CLOCK_HZ / portTIMER_PRESCALE ) / configTICK_RATE_HZ;


to:

const unsigned long ulCompareMatch = ( configCPU_CLOCK_HZ / portTIMER_PRESCALE ) / configTICK_RATE_HZ - 1;

RE: PIC24/dsPIC timer period is 1 clock too long

Posted by Richard on August 23, 2010
Thanks for the feedback. Its not the first time I have made that mistake, and I'm sure it won't be the last.

However, I'm not sure your solution is completely accurate because of the operator precedence. Should it not be:

const unsigned long ulCompareMatch = ( ( configCPU_CLOCK_HZ / portTIMER_PRESCALE ) / configTICK_RATE_HZ ) - 1;

If you agree with this I will change it in SVN straight away so it does not get lost in the crowds.

Regards.

RE: PIC24/dsPIC timer period is 1 clock too long

Posted by Dan Henry on August 23, 2010
Multiplicative operators, of which '/' is one, have higher precedence than additive operators, so the added parentheses are unnecessary. However, explicitness is always good in my book, so I say leave them in the way you have it.

RE: PIC24/dsPIC timer period is 1 clock too long

Posted by Richard on August 23, 2010
... the SVN copy has been updated.

Regards.


[ Back to the top ]    [ About FreeRTOS ]    [ Privacy ]    [ Sitemap ]    [ ]


Copyright (C) Amazon Web Services, Inc. or its affiliates. All rights reserved.

Latest News

NXP tweet showing LPC5500 (ARMv8-M Cortex-M33) running FreeRTOS.

Meet Richard Barry and learn about running FreeRTOS on RISC-V at FOSDEM 2019

Version 10.1.1 of the FreeRTOS kernel is available for immediate download. MIT licensed.

View a recording of the "OTA Update Security and Reliability" webinar, presented by TI and AWS.


Careers

FreeRTOS and other embedded software careers at AWS.



FreeRTOS Partners

ARM Connected RTOS partner for all ARM microcontroller cores

Espressif ESP32

IAR Partner

Microchip Premier RTOS Partner

RTOS partner of NXP for all NXP ARM microcontrollers

Renesas

STMicro RTOS partner supporting ARM7, ARM Cortex-M3, ARM Cortex-M4 and ARM Cortex-M0

Texas Instruments MCU Developer Network RTOS partner for ARM and MSP430 microcontrollers

OpenRTOS and SafeRTOS

Xilinx Microblaze and Zynq partner