FreeRTOS Support Archive
The FreeRTOS support forum is used to obtain active support directly from Real
Time Engineers Ltd. In return for using our top quality software and services for
free, we request you play fair and do your bit to help others too! Sign up
to receive notifications of new support topics then help where you can.
This is a read only archive of threads posted to the FreeRTOS support forum.
The archive is updated every week, so will not always contain the very latest posts.
Use these archive pages to search previous posts. Use the Live FreeRTOS Forum
link to reply to a post, or start a new support thread.
[FreeRTOS Home] [Live FreeRTOS Forum] [FAQ] [Archive Top] [June 2009 Threads] Changint the timer in the PIC32 PortPosted by Gray on June 22, 2009 I was just wondering if anybody had managed to successfully change the timer from timer 1 to another timer (2 or 3). I have tried altering the Port files and have changed the set-up routine (see below) to use timer 2, I have also looked at the ISR ASM code (complete novice here) and can’t see how I would change this if it is indeed need changing, watching the interrupt control reg, you see the timer sets setup correctly, and after the interrupt the reg value goes from 0x8102 to 0x8100 (when operating with timer one reg reads 0x8012 when entering the ISR, this is I believe expected). The effect when changed is that FreeRTOS does not register the tasks and as such even basically loops only within the RTOS code. I believe that that the timer is working because it will debug within it, but I must be missing something within the rest of the port to cause this behaviour.
I know this seems a bit OTT, but I want to use the 64 pin PIC and need an external pin to drive a timer/counter so have to use timer 1 for this.
Sample from Port.asm
.setnomips16 .set noreorder .extern pxCurrentTCB .extern vTaskSwitchContext .extern vPortIncrementTick .extern xISRStackTop .global vPortStartFirstTask .global vPortYieldISR .global vT1InterruptHandler
/******************************************************************/
.section .FreeRTOS, "ax", @progbits .setnoreorder .set noat .entvT1InterruptHandler
vT1InterruptHandler:
portSAVE_CONTEXT
jal vPortIncrementTick nop
portRESTORE_CONTEXT
.end vT1InterruptHandler
Clears the interrupt
/* Clear the interrupt in the interrupt controller. */ las6, IFS0CLR addius4, zero, 2 sws4, (s6)
jalvTaskSwitchContext nop
Setup code
/* Place the prototype here to ensure the interrupt vector is correctly installed. */ extern void __attribute__( (interrupt(ipl1), vector(_TIMER_2_VECTOR))) vT1InterruptHandler( void );
/* * Setup a timer for a regular tick. */ void prvSetupTimerInterrupt( void ) { const unsigned portLONG ulCompareMatch = ( (configPERIPHERAL_CLOCK_HZ / portTIMER_PRESCALE) / configTICK_RATE_HZ ) - 1;
OpenTimer2( ( T2_ON | T2_PS_1_8 | T2_SOURCE_INT ), ulCompareMatch ); ConfigIntTimer2( T2_INT_ON | configKERNEL_INTERRUPT_PRIORITY );
RE: Changint the timer in the PIC32 PortPosted by Mariusz Murawski on June 28, 2009 Either way, there's a small bug in a port.c file for PIC32:
void prvSetupTimerInterrupt( void ) { const unsigned portLONG ulCompareMatch = ( (configPERIPHERAL_CLOCK_HZ / portTIMER_PRESCALE) / configTICK_RATE_HZ ) - 1;
OpenTimer1( ( T1_ON | T1_PS_1_8 | T1_SOURCE_INT ), ulCompareMatch );
ConfigIntTimer1( T1_INT_ON | configKERNEL_INTERRUPT_PRIORITY ); }
According to Microchip libraries documentation, OpenTimerX expects 16bit value as a second parameter thus maximum value is 65535.
@PeripheralClockHz == 80000000 (80MHz) maximum configTICK_RATE_HZ would be then 152 Hz. If you use a value lower than 152, then the real tick rate will be different than expected.
I guess it would be good to give people chance to use 1/64 divider.
Copyright (C) Amazon Web Services, Inc. or its affiliates. All rights reserved.
|