# Microchip Port

**URL:** <https://forums.freertos.org/t/microchip-port/303>\
**Category:** Kernel\
**Created:** [March 27, 2010, 12:19pm UTC](https://forums.freertos.org/t/microchip-port/303 "2010-03-27T12:19:17Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![system](https://d2v6vdsk2p900z.cloudfront.net/original/1X/7fc8fdb729c645aab5b20282bbe34e57cb407be6.jpeg) [@system](https://forums.freertos.org/u/system)\
**Post date:** [March 27, 2010, 12:19pm UTC](https://forums.freertos.org/t/microchip-port/303/1 "2010-03-27T12:19:17Z")

</div>

**[ronseese](https://sourceforge.net/u/ronseese/)** wrote on [Saturday, March 27, 2010](https://sourceforge.net/p/freertos/discussion/382005/thread/0c440460/#27b5):

My first attempt at using FreeRTOS went smoothly with an 18F8723. My second attempt is a little bumpy. I am attempting to port a 18F2620. In this design I use all of the CCP modules, so I am attempting to use timer 0 for the timer tick resource. After having the initial problems, I went back to the 8723 and changed the existing method of using a compare module and timer for the timer tick to only using timer 0, and successfully.

What seems to be happening is that any of the task delays seem to return immediately. Time slicing with 2 tasks seem to be working. I have a test point toggling on in the timer tick routine as well as both of the test tasks. I thought that there is a problem updating the timer tick counter, but I wrote a small routine that fetches the variable, and it is counting.

What would be some of the next steps in debugging this issue?

---

<div class="post-metadata">

**Author:** ![rtel](https://d3iykfbgfh8zhg.cloudfront.net/user_avatar/forums.freertos.org/rtel/32/31_2.png) [@rtel](https://forums.freertos.org/u/rtel)\
**Post date:** [March 28, 2010, 4:22pm UTC](https://forums.freertos.org/t/microchip-port/303/2 "2010-03-28T16:22:13Z")

</div>

**[rtel](https://sourceforge.net/u/rtel/)** wrote on [Sunday, March 28, 2010](https://sourceforge.net/p/freertos/discussion/382005/thread/0c440460/#54de):

Are you using calls to vTaskDelayUntil()?&nbsp; If so, are you initialising the first parameter before using it for the first time?&nbsp; It should be initialised to the current time before it gets used, but once its initialised you should not (normally) write to it directly again.

Regards.

---

<div class="post-metadata">

**Author:** ![system](https://d2v6vdsk2p900z.cloudfront.net/original/1X/7fc8fdb729c645aab5b20282bbe34e57cb407be6.jpeg) [@system](https://forums.freertos.org/u/system)\
**Post date:** [March 29, 2010, 1:53pm UTC](https://forums.freertos.org/t/microchip-port/303/3 "2010-03-29T13:53:31Z")

</div>

**[ronseese](https://sourceforge.net/u/ronseese/)** wrote on [Monday, March 29, 2010](https://sourceforge.net/p/freertos/discussion/382005/thread/0c440460/#83c6):

Hi Richard,  
I believe so:  
static void vHeartBeat( void \*pvParameters )  
{  
portTickType xDelayTime;

xDelayTime = xTaskGetTickCount();  
for( ;; )  
{  
vTaskDelayUntil (&xDelayTime, DELAY\_SEC);  
LED1 = !LED1;  
}  
}

And I toggle another testpoint in the timer tick routine:  
#pragma code  
static void prvTickISR( void )  
{  
/\* Interrupts must have been enabled for the ISR to fire, so we have to  
save the context with interrupts enabled. \*/

INTCONbits.TMR0IF = 0;  
TP3=!TP3;

TMR0H = ( unsigned char ) 0x82;  
TMR0L = ( unsigned char ) 0xff;

portSAVE\_CONTEXT( portGLOBAL\_INTERRUPT\_FLAG );

/\* Maintain the tick count. \*/  
vTaskIncrementTick();

#if configUSE\_PREEMPTION == 1  
{  
/\* Switch to the highest priority task that is ready to run. \*/  
vTaskSwitchContext();  
}  
#endif

portRESTORE\_CONTEXT();  
}

I am expecting LED1 to toggle at a 1 second rate, but it toggles faster than TP3.

Thanks, Ron
