Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
OnChangePin4to7 error
02-03-2012, 06:15 PM, (This post was last modified: 02-03-2012, 06:18 PM by Bastian.)
#1
OnChangePin4to7 error
Hi!

I have a problem using OnChangePin4to7 function. I tried to use this function like OnChangePinX but don't works. When i compile the program that uses this function i get this error:
   
The code of this function in interrupt.c is:
Code:
void OnChangePin4to7(callback func, u8 pin)
{
    if (intUsed[INT_RB] == INT_NOT_USED)
    {
        intUsed[INT_RB] = INT_USED;
        intFunction[INT_RB] = func;
        INTCON2bits.INTEDG2 = config;
        TRISB |= (1 << pin);    // pin as an INPUT
        INTCON2bits.RBIP = INT_LOW_PRIORITY;
        INTCONbits.RBIE = INT_ENABLE;
        INTCONbits.RBIF = 0;
    }
    #ifdef DEBUG
    else
    {
        serial_printf("Error : interrupt RB is already used !");
    }
    #endif
}
Seems this funtion was not implemented correctly because config isn't defined in the header but it's used after. I think pin parameter is used to configure RB pins as inputs, but i don't understand how it's works. I can be wrong, but it is supposed that this interrupt is triggered only when a change in pin configured as input. So it is not necessary to configure the pins RB7: 4 as inputs.

Someone can tell me how i can fix/use this function.

I'm using X2 r290 on windows 7

Regards
Reply
02-03-2012, 07:17 PM,
#2
RE: OnChangePin4to7 error
Hi,
You're right, there is a mistake. Thank you for this report.
Just replace (line 820 of interrupt.c)
Quote:void OnChangePin4to7(callback func, u8 pin)
with
Quote:void OnChangePin4to7(callback func, u8 pin, u8 config)
where config can be :
Quote:INT_RISING_EDGE or 1 = Interrupt on rising edge
or
Quote:INT_FALLING_EDGE or 0 = Interrupt on rising edge

For the rest, the datasheet says :

Quote:PORTB<7:4> Interrupt-on-Change
Only pins configured as inputs can
cause this interrupt to occur. Any RB7:RB4 pin
configured as an output is excluded from the interrupt-
on-change comparison. The pins are compared with
the old value latched on the last read of PORTB.

Now, if it works, you can add some definition and example on the wiki Wink
It is easier to complain than it is to do, but it is better to do than it is to complain.
Reply
02-03-2012, 10:08 PM,
#3
RE: OnChangePin4to7 error
Hi!

OK!, now for use this function we need do something like this...

OnChangePin4to7(function, pin, INT_XXXX_EDGE);

But... what for is used pin parameter? For example; if pin = 7, RB7 (pin 7 of pinguino) is configured as input, writing 1xxxxxxxb in TRISB. But if we need all pins (RB7:RB4) as inputs, then we need configure previously with pinMode() (or TRISB..). In this case, pin parameter is useless.

Why not remove it? The function implementation would be something like this:
Code:
void OnChangePin4to7(callback func, u8 config)
{
    if (intUsed[INT_RB] == INT_NOT_USED)
    {
        intUsed[INT_RB] = INT_USED;
        intFunction[INT_RB] = func;
        INTCON2bits.INTEDG2 = config;
        
        INTCON2bits.RBIP = INT_LOW_PRIORITY;
        INTCONbits.RBIE = INT_ENABLE;
        INTCONbits.RBIF = 0;
    }
    #ifdef DEBUG
    else
    {
        serial_printf("Error : interrupt RB is already used !");
    }
    #endif
}

and would be used like OnChangePinx.

Regards

Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)