Thread Rating:
  • 1 Vote(s) - 5 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Pic32 Interrupts
06-06-2012, 11:29 AM,
#31
RE: Pic32 Interrupts
John,

as a matter of fact, setting controller bits to assign a particular functionality to I/O pins is commonplace for all modern day microcontrollers. PPS is MicroChip's buzzword for that. I don't see the obscurity. From your point of view, it might be obscure to remap initially assigned mapping documented in the datasheet, but it is identical to what Pinguino libraries also do (see my last post).

As e.g. the MX220 has only a single fixed mapped external interrupt, the practical use regarding interrupts is very limitied. Thus using the PPS mapped ones means a huge benefit.

But it seems nobody is interested in this, as I there hasn't been a single reply to this thread stating that anybody tried the PPS interrupts at all (even with other Pinguino boards). I can test this on the MX220 solely and seeing it work on other hardware would be a strong indicator pointing at a model specific problem worth to be tackled with MicroChip.

Frankly, I've been assuming this hits other users as well and there is a common interest in solving the problem.

/M
Reply
06-06-2012, 06:58 PM, (This post was last modified: 06-06-2012, 07:01 PM by pingotg.)
#32
RE: Pic32 Interrupts
OK.

My central point was that there must be better places to ask about this and I suggested 2.

I suppose you realise most Pinguino users don't use (or don't knowingly use) interrupts Smile

John
Reply
08-06-2012, 10:55 AM,
#33
RE: Pic32 Interrupts
I don't want to beat this horse any further, but as soon as you want such a basic thing as a switch or a rotary encoder, you need external interrupts (well, except you have too much CPU time and decide to resort to polling).
Reply
22-06-2012, 02:12 PM,
#34
RE: Pic32 Interrupts
After posting my problem on the Microchip forum, I got a bunch of useful suggestions as well as code with a working PPS interrupt (natively).

As for the sample code, I didn't manage to reproduce the behaviour instantly on the Pinguino and found no time to have a closer look why it still fails, though it seems to work with MPLab on a PIC32MX220 (code sample).

Part of the reason why I didn't try further is that CN (Change Notification) fits my problem better than using external interrupts.

CHANGE NOTICE is an interrupt that is triggered if any one from a number of prior configured inputs sees a change in polarity. The respective values can than be accessed in the ISR.

Apart from keeping the code cleaner, this also fits a multiple button approach (or several input lines representing a binary state) better than a single interrupt for each input.

As this might be also interesting for other Pinguino users, I'll post some sample code as soon as I find an opportunity.
Reply
22-06-2012, 04:37 PM,
#35
RE: Pic32 Interrupts
Hi all

Regarding the PPS on PIC32, I remember I read somewhere that PPS can only be defined one time at startup. io.c library is executed at startup ( for MX220 and GENERIC128 ) so it seems that the PPS can not be configured another time. I think we should add a #ifdef directive to give the user the ability to define its own configuration ( for example in the setup ).
This directive could be used by advanced users to define a special configuration. We must keep in mind that this directive will affect standard modules ( serial, I2C, SPI ) and the corresponding libraries.

JP
Reply
23-06-2012, 06:29 PM,
#36
RE: Pic32 Interrupts
Hi,
Just like on PIC18F26J50 (and others), you have to configure the IOL1WAY bit in the bootloader to block (or not) the IOLOCK bit from being cleared after it has been set once.
Régis

(22-06-2012, 04:37 PM)jpmandon Wrote: Hi all

Regarding the PPS on PIC32, I remember I read somewhere that PPS can only be defined one time at startup. io.c library is executed at startup ( for MX220 and GENERIC128 ) so it seems that the PPS can not be configured another time. I think we should add a #ifdef directive to give the user the ability to define its own configuration ( for example in the setup ).
This directive could be used by advanced users to define a special configuration. We must keep in mind that this directive will affect standard modules ( serial, I2C, SPI ) and the corresponding libraries.

JP
It is easier to complain than it is to do, but it is better to do than it is to complain.
Reply
24-06-2012, 12:01 AM,
#37
RE: Pic32 Interrupts
(22-06-2012, 04:37 PM)jpmandon Wrote: Hi all

Regarding the PPS on PIC32, I remember I read somewhere that PPS can only be defined one time at startup. io.c library is executed at startup ( for MX220 and GENERIC128 )

JP
this is not completely correct, this is part of the configuration-bits . Here it is decided whether you can configure peripheral pins only once ( safest but you must do all initial peripheral pin configurations in one IOLOCK session , a second attempt to unlock will not be possible) or repeatitive.
Reply
27-06-2012, 11:31 AM,
#38
RE: Pic32 Interrupts
Assuming the current bootloader is 2.12 für PIC32 devices, I can't find the string IOL1WAY in the source. Nevertheless, my impression is that it might be set.

Can anyone more intimate with the loader answer this question?

Not setting the bit (thus enabling configuration more than once) would not really hurt in my opinion, since anybody using PPS would have to be more intimate with native PIC coding anyway.
Reply
27-06-2012, 12:42 PM, (This post was last modified: 27-06-2012, 12:43 PM by jpc999.)
#39
RE: Pic32 Interrupts
considering the complexity of these chips i doubt you can get away without good knowledge of at least the peripherals. Even if higher level software may hide part of this complexity it is very useful to have good understanding of these details. On the small P32 chips there is hardly a way around PPS, most peripheral functions need to be mapped onto pins. Even if this is done by high-level functions this will work only once if the IOL1WAY is set.
Reply
28-06-2012, 02:19 AM,
#40
RE: Pic32 Interrupts
Here's the code I've been promising to post:

Code:
/*

Test Change Notification (CN) on Pic32MX220 with a remote receiver connected
to C4/C5/C6/C7.

A button press on the remote control yields one of the five bit patterns below
on the receiver output pins.

*/

#include <system.c>
#include <interrupt.c>
#include <delay.c>

#define ledRPin 9
#define ledGPin 13

// -----------------------------------------------------------------------------
// Globals
// -----------------------------------------------------------------------------

enum REMOTE {
  LEFT = 3,
  DOWN = 6,
  RIGHT = 9,
  CENTER = 12,
  UP = 15,
};
  
volatile uint32_t remoteButton = 0;

// -----------------------------------------------------------------------------
// Interrupts
// -----------------------------------------------------------------------------

// From p32mx220f032d.h
// #define _CHANGE_NOTICE_VECTOR  34
void ISR_wrapper_vector_34(void)  __attribute__ ((section (".vector_34")));

// Assign ISR handlers to interrupt vector
void ISR_wrapper_vector_34(void)  { ChangeNotice(); }

// Declare interrupt handler
void ChangeNotice(void) __attribute__ ((interrupt));  

// -----------------------------------------------------------------------------
//  ISR handlers
// -----------------------------------------------------------------------------

// Implement interrupt handlers
void ChangeNotice(void)
{
  // Read the port (automatically clears the state)
  remoteButton |= (( PORTC >> 4 ) & 0x0F );

  // Clear the interrupt flag
  IFS1bits.CNCIF = 0;
}
  
// -----------------------------------------------------------------------------
// Setup misc
// -----------------------------------------------------------------------------

void setup() {

  // Setup LED pins
  pinMode(ledRPin, OUTPUT);
  pinMode(ledGPin, OUTPUT);
  digitalWrite(ledRPin, LOW);
  digitalWrite(ledGPin, LOW);

  // Setup C4/C5/C6/C7 in a CN group
  
  // Disable analog functionality
  ANSELC = 0x0;
  
  // Set pin as input
  TRISCbits.TRISC4 = 0x1; // Same as pinMode(switchBit0, INPUT);
  TRISCbits.TRISC5 = 0x1; // Same as pinMode(switchBit0, INPUT);
  TRISCbits.TRISC6 = 0x1; // Same as pinMode(switchBit0, INPUT);
  TRISCbits.TRISC7 = 0x1; // Same as pinMode(switchBit0, INPUT);

  // Setup the change notice options
    #undef ON
  CNCONCbits.ON = 1;        //CN is enabled
  CNCONCbits.SIDL = 0;    //CPU Idle does not affect CN operation
  CNENCbits.CNIEC4 = 1;    //Enable RC4 change notice
  CNENCbits.CNIEC5 = 1;    //Enable RC5 change notice
  CNENCbits.CNIEC6 = 1;    //Enable RC6 change notice
  CNENCbits.CNIEC7 = 1;    //Enable RC7 change notice
  
  // Read port C to clear mismatch condition
  uint32_t tmp = PORTC;

  // Clear CN interrupt flag, set CN interrupt priority, enable CN interrupt
  IFS1bits.CNCIF = 0;           // clear status register for port C
  IPC8CLR = _IPC8_CNIP_MASK;                //clear priority
  IPC8SET = (2 << _IPC8_CNIP_POSITION);    //set priority (2)
  IEC1bits.CNCIE = 1; // enable CN interrupts on port C

  // Pulldown enable
  CNPDCbits.CNPDC4 = 0;
  CNPDCbits.CNPDC5 = 0;
  CNPDCbits.CNPDC6 = 0;
  CNPDCbits.CNPDC7 = 0;

  // Enable interrupts
  IntConfigureSystem(INT_SYSTEM_CONFIG_MULT_VECTOR);    // interrupt mode (interrupt.c)
}

// -----------------------------------------------------------------------------
// Main
// -----------------------------------------------------------------------------

void loop() {
  blink(remoteButton / 3);
  remoteButton = 0;
  delay(100);
}

void blink(int times)
{
  if (times == 0) return;
  
  int i;
  for (i = 0; i < times - 1; i++)
  {
    digitalWrite(ledRPin, HIGH);
    delay(100);
    digitalWrite(ledRPin, LOW);
    delay(100);
  }

  digitalWrite(ledRPin, HIGH);
  delay(100);
  digitalWrite(ledRPin, LOW);
}
Reply


Forum Jump:


Users browsing this thread: 2 Guest(s)