Quality RTOS & Embedded Software

 Real time embedded FreeRTOS RSS feed 
Real time embedded FreeRTOS mailing list 
Quick Start Supported MCUs PDF Books Trace Tools Ecosystem TCP & FAT Training


Minor timer setup bugfix for PIC24/dsPIC port

Posted by Dave Nadler on October 6, 2012
Hi - My blinking light was running at half speed, and I assumed I'd set up the microprocessor clock wrong. After a couple hours checking all the clock configuration options, I found a small 2x error in the port.c timer setup... Here's the fix:
    // DRN: Timer clock input is system clock >>> DIVIDED BY 2 <<<
// DRN: See DS39704A-page 14-6: bit 1 TCS:
// DRN: Timerx Clock Source Select bit: 0 = Internal clock (FOSC/2)
// DRN: line below fixed to reflect this...
const unsigned long ulCompareMatch = ( ( (configCPU_CLOCK_HZ/2) / portTIMER_PRESCALE ) / configTICK_RATE_HZ ) - 1; // DRN
// DRN: Was: const unsigned long ulCompareMatch = ( ( configCPU_CLOCK_HZ / portTIMER_PRESCALE ) / configTICK_RATE_HZ ) - 1;

Note 1: the CPU clock on PIC24F is typically 32MHz, but the instruction clock is always 1/2 this value. The timer input takes the CPU clock/2.
Note 2: The CPU clock can be reduced in "Doze Mode" power-saving - this is not provided for in FreeRTOS.

Hope this is helpful !
Best Regards, Dave

RE: Minor timer setup bugfix for PIC24/dsPIC port

Posted by Richard on October 6, 2012
That is curious - I'm sure I would have noticed that. Can you tell me which PIC part number you are using. Thanks.


RE: Minor timer setup bugfix for PIC24/dsPIC port

Posted by Dave Nadler on October 10, 2012
I'm using the PIC24FJ32GB004.
The documentation for the timer module for PIC24 family is here: http://ww1.microchip.com/downloads/en/DeviceDoc/39704a.pdf
See section 14.3 Register 14-1: TxCON: Type A Time Base Control bit 1
The clock definitions for these parts are a bit confusing:
CPU clock is 32MHz, also feeds peripherals (excepting USB).
Instruction clock is always half this at 16MHz (unless further divided in DOZE low-power mode).
Hope that helps,
Best Regards, Dave

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

Copyright (C) 2004-2010 Richard Barry. Copyright (C) 2010-2016 Real Time Engineers Ltd.
Any and all data, files, source code, html content and documentation included in the FreeRTOSTM distribution or available on this site are the exclusive property of Real Time Engineers Ltd.. See the files license.txt (included in the distribution) and this copyright notice for more information. FreeRTOSTM and FreeRTOS.orgTM are trade marks of Real Time Engineers Ltd.

Latest News:

FreeRTOS V9.0.0 is now available for download.

Free TCP/IP and file system demos for the RTOS

Sponsored Links

⇓ Now With No Code Size Limit! ⇓
⇑ Free Download Without Registering ⇑

FreeRTOS Partners

ARM Connected RTOS partner for all ARM microcontroller cores

Renesas Electronics Gold Alliance RTOS Partner.jpg

Microchip Premier RTOS Partner

RTOS partner of NXP for all NXP ARM microcontrollers

Atmel RTOS partner supporting ARM Cortex-M3 and AVR32 microcontrollers

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

Xilinx Microblaze and Zynq partner

Silicon Labs low power RTOS partner

Altera RTOS partner for Nios II and Cortex-A9 SoC

Freescale Alliance RTOS Member supporting ARM and ColdFire microcontrollers

Infineon ARM Cortex-M microcontrollers

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

Cypress RTOS partner supporting ARM Cortex-M3

Fujitsu RTOS partner supporting ARM Cortex-M3 and FM3

Microsemi (previously Actel) RTOS partner supporting ARM Cortex-M3

Atollic Partner

IAR Partner

Keil ARM Partner

Embedded Artists