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




Loading

dsPIC interrupt & queue

Posted by Ruben_saz on November 17, 2007
I'm having trouble with a interrupt that posts data in a queue. The ADC interrupt is supposed to write 2 words obtained from ADCBUF0 y ADCBUF2 on a queue for further prossesing. The problem is that this causes the device to branch to the _AddressError Trap vector. If I remove this line

xYieldRequired = xQueueSendFromISR( adcValues, &analogReading, xYieldRequired );

from the code. The program runs ok, but obviously i don't get the ADC values on the processing task. Here is the ISR code.

void __attribute__((__interrupt__, auto_psv)) _ADCInterrupt(void)
{
unsigned int analogReading, readCount = 0;
portBASE_TYPE xYieldRequired = pdFALSE;

IFS0bits.ADIF = 0;
while( readCount < 2 )
{
analogReading = ReadADC12(readCount);
xYieldRequired = xQueueSendFromISR( adcValues, &analogReading, xYieldRequired );
readCount++;
}
readCount=0;
if( xYieldRequired != pdFALSE )
{
taskYIELD();
}
}

//END OF ISR CODE
------------------------------------------------

And this is the code for the processing task, in this case it only displays the integer value obtained from the ADC.

for(;;){
asm("btg LATD, #6"); // TOGGLE LED, JUST TO SEE THAT THE TASK IS RUNNING
ADCON1bits.SAMP = 1;// START SAMPLING AND THEN AUTOMATIC CONVERSION
vTaskDelay( 1000 ); // WAIT 1 SECOND (FOR TESTING PURPOSES) ADC INTERRUPT POST DATA
// IN THE QUEUE WITHIN THIS PERIOD OF TIME

if(xQueueReceive( adcValues, &adcData, ( portTickType ) 10 ))
{
v2 = adcData;
}

if(xQueueReceive( adcValues, &adcData, ( portTickType ) 10 ))
{
v1 = adcData;
}

sprintf( cStringBuffer, "V: %d A: %d", v1, v2 ); // Print string to buffer
xQueueSend( xLCDQueue, &xMessage, portMAX_DELAY ); // Send the message to the LCD task
}


I'm running it on a dsPIC30F6014A, and I'm using the MPLAB ICD2, Any help with this will be greatly appreciated.

Cheers!!

RE: dsPIC interrupt & queue

Posted by Richard on November 17, 2007
I cannot see anything that is obviously wrong, on the assumption that cStringBuffer[] is large enough. It could be a stack overflow within the task. Can you try removing the call to sprintf() because when using GCC this is likely to use a LOT of stack. Maybe just set cStringBuffer to a const string to make sure it contains something valid ( strcpy( cStringBuffer, "test" ) ). I know this removes the functionality of seeing the values but will be a good test.

You could try making the task stack bigger too, and ensuring there are no large variables on the stack (is cStringBuffer on the stack).

Any of these things making a difference would indicate a stack issue.

Regards.

RE: dsPIC interrupt & queue

Posted by Ruben_saz on November 17, 2007
Hi Richard!

As you said, the problem was the stack allocated to that task. It seems that it's not good to write programs at late night, one can forget to check such trivial things :D

Thank you very much.


[ 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