ruben_saz wrote on Saturday, 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!!