Thanks for your replies.
I'll study and try your indications and information.
To enable pin4, pin12 and pins A0-A5 interrupts on Arduino UNO, I have used the following method .
Is there another mothod to associate an interrupt a these pins (pin state changes).
Thanks again
Marcello
// -------------------------- Gestione Interrupts ------------------------------------>
void InitialiseIO(){
// --------- Finecorsa-------
pinMode(Pin_FinecorsaX_0, INPUT_PULLUP); // Pin_FinecorsaX_0 is input to which a switch is connected
digitalWrite(Pin_FinecorsaX_0, HIGH); // Configure internal pull-up resistor
pinMode(Pin_FinecorsaY_0, INPUT_PULLUP);
digitalWrite(Pin_FinecorsaY_0, HIGH);
//---- Joysticks -------
pinMode(JoystickXP, INPUT_PULLUP);
digitalWrite(JoystickXP, HIGH);
pinMode(JoystickXM, INPUT_PULLUP);
digitalWrite(JoystickXM, HIGH);
pinMode(JoystickYP, INPUT_PULLUP);
digitalWrite(JoystickYP, HIGH);
pinMode(JoystickYM, INPUT_PULLUP);
digitalWrite(JoystickYM, HIGH);
pinMode(JoystickZP, INPUT_PULLUP);
digitalWrite(JoystickZP, HIGH);
pinMode(JoystickZM, INPUT_PULLUP);
digitalWrite(JoystickZM, HIGH);
}
void InitialiseInterrupt(){
cli(); // switch interrupts off while messing with their settings
//----------------- Pin 12 digitale -------------------
PCICR = (1<<PCIE0);//pin12
PCMSK0 = (1<<PCINT4);
//----------------- Pin 4 digitale -------------------
PCICR |= (1<<PCIE2);
PCMSK2 = (1<<PCINT20);
//----------------- Pin A0 -------------------
PCICR |= (1<<PCIE1);
PCMSK1 = (1<<PCINT8);//A0
//----------------- Pin A1 -------------------
PCMSK1 |= (1<<PCINT9);//A1
//----------------- Pin A2 -------------------
PCMSK1 |= (1<<PCINT10);//A2
//----------------- Pin A3 -------------------
PCMSK1 |= (1<<PCINT11);//A3
//----------------- Pin A4 -------------------
PCMSK1 |= (1<<PCINT12);//A4
//----------------- Pin A5 -------------------
PCMSK1 |= (1<<PCINT13);//A5
MCUCR = (1<<ISC00) | (1<<ISC01);//fondamentale
/* MCUCR = (1<<ISC0#) | (1<<ISC0#);
This line of code tells the chip which type of change triggers the interrupt. ISC0 is the value we are
modifying. Inputting a 1 or a 0 at the # will determine the state. 0 0 triggers at any low level. 01 triggers
at any change. 1 0 triggers at a falling edge. 1 1 triggers at a rising edge.
*/
sei(); // turn interrupts back on
}
// serve interrupts per pin da 8 a 13
ISR(PCINT0_vect) {
// cli(); // switch interrupts off while messing with their settings
int Fc_0=digitalRead(Pin_FinecorsaX_0);
if ((Fc_0==LOW))
{
Ind_Fine_Corsa_ON_X=1;
if (currentDirectionX==0)
{
Mot_Step_X=0;
Ind_Fine_Corsa_ON_X0=1;
Ind_Fine_Corsa_ON_XF=0;
}
else
{
Ind_Fine_Corsa_ON_X0=0;
Ind_Fine_Corsa_ON_XF=1;
}
// if (digitalRead(Pin_FinecorsaX_0)==LOW) Serial.print(F("==>"));Serial.println("D12");
// if (digitalRead(Pin_FinecorsaX_F)==LOW) Serial.print(F("==>"));Serial.println("D4");
}
else
Ind_Fine_Corsa_ON_X=0;
//sei(); // turn interrupts back on
delayMicroseconds(1000);
Ind_Cambiamento=1;//29/08/2013
}
// serve interrupts per pin A0-A5
ISR(PCINT1_vect) {
//cli(); // switch interrupts off while messing with their settings
if ((digitalRead(JoystickXP)==LOW) || (digitalRead(JoystickXM)==LOW) )
{
if (digitalRead(JoystickXP)==LOW) Ind_Joystick_X=-1;
if (digitalRead(JoystickXM)==LOW) Ind_Joystick_X=1;
//NO POS_motorX_Simple(1, 10);
//Serial.print(F("Ind_Joystick_X="));//Serial.print(Ind_Joystick_X);
}
else
{
Comando=="";
Ind_Joystick_X=0;
}
if ((digitalRead(JoystickYP)==LOW) || (digitalRead(JoystickYM)==LOW) )
{
if (digitalRead(JoystickYP)==LOW) Ind_Joystick_Y=-1;
if (digitalRead(JoystickYM)==LOW) Ind_Joystick_Y=1;
//NO POS_motorX_Simple(1, 10);
// Serial.print(F("Ind_Joystick_Y=")); Serial.print(Ind_Joystick_Y);
}
else
{
Comando=="";
Ind_Joystick_Y=0;
}
if ((digitalRead(JoystickZP)==LOW) || (digitalRead(JoystickZM)==LOW) )
{
if (digitalRead(JoystickZP)==LOW) Ind_Joystick_Z=-1;
if (digitalRead(JoystickZM)==LOW) Ind_Joystick_Z=1;
}
else
{
Comando=="";
Ind_Joystick_Z=0;
}
// sei(); // turn interrupts back on
delayMicroseconds(1000);
Ind_Cambiamento=1;//29/08/2013
}
// serve interrupts per pin da 0 a 7
ISR(PCINT2_vect) {
// cli(); // switch interrupts off while messing with their settings
int Fc_0=digitalRead(Pin_FinecorsaY_0);
if (Fc_0==LOW)
{
Ind_Fine_Corsa_ON_Y=1;
if (currentDirectionY==0)
{
Mot_Step_Y=0;
Ind_Fine_Corsa_ON_Y0=1;
Ind_Fine_Corsa_ON_YF=0;
}
else
{
Ind_Fine_Corsa_ON_Y0=0;
Ind_Fine_Corsa_ON_YF=1;
}
}
else
Ind_Fine_Corsa_ON_Y=0;
//sei(); // turn interrupts back on
delayMicroseconds(1000);
Ind_Cambiamento=1;//29/08/2013
}
// <-------------------------- Gestione Interrupts ------------------------------------
Thanks again