closed

Loginbox

Please enter your username and password into the following fields to log in.


  • Username:
  • Password:
  •  
  • Auto log in on every visit.


  •  

Set port pin interrupt



Droopy offline
Benutzer
Avatar
Gender: male
Location: BELGIUM 
Age: 53
Posts: 24
Registered: 01 / 2016
Private message
Subject: Set port pin interrupt  -  Posted: 12.12.2018 - 16:50   -  
Hello all,

I've already used interrupts for a timer in AVRco, but now i need to set and serve a port pin interrupt. For instance, I want an interrupt when Port pin E4 get high on a Xmega256A3u?

Can some help me for this?

Thnx a lot;)
go down go up
rh offline
Administrator
Avatar
Gender: male
Location: GERMANY  Germany
Age:
Posts: 5450
Registered: 03 / 2002
Homepage Private message
Subject: Re: Set port pin interrupt  -  Posted: 12.12.2018 - 17:00   -  
Hello Droopy,

there are two samples:
XMega_PortInt
XMega_PCIint
in the demos directory.

rolf
Cars don't buy cars -- Autos kaufen keine Autos.
Henry Ford
go down go up
Droopy offline
Benutzer
Avatar
Gender: male
Location: BELGIUM 
Age: 53
Posts: 24
Registered: 01 / 2016
Private message
Subject: Re: Set port pin interrupt  -  Posted: 12.12.2018 - 21:37   -  
Ok thnx Rolf, I forgot to look to the demos :oops:
go down go up
Lschreyer offline
Benutzer
Avatar
Gender: n/a
Location: n/a 
Age:
Posts: 456
Registered: 02 / 2007
Private message
Subject: Re: Set port pin interrupt  -  Posted: 13.12.2018 - 17:53   -  
For example on a Xmega:

DDRE:= %11101000; // I/O Direction: 0= input, 1= Output
PIN0CTRLE:= %00011000; //Activate Pullup
PIN1CTRLE:= %00011000; //Activate Pullup
PIN2CTRLE:= %00011000; //Activate Pullup
PIN3CTRLE:= %00000000; //
PIN4CTRLE:= %00000010; //Pinchange Interrupt Active Low: Falling Sense Bit 0-1 = 10
PIN5CTRLE:= %00000000; //
PIN6CTRLE:= %00000000; //
PIN7CTRLE:= %00000000; //

INTCTRLE:= %00000010; // Interrupt Level medium for Int0
INT0MASKE:= %00010000; // Pin 4 Interrupt #0 (There is also INT1MASKE for INT #1)


For each PINxCTRLn you have


Bit 7 – SRLEN: Slew Rate Limit Enable Setting this bit will enable slew rate limiting on pin n.
Bit 6 – INVEN: Inverted I/O Enable Setting this bit will enable inverted output and input data on pin n.

Bit 5:3 – OPC: Output and Pull Configuration
000 TOTEM Totem-pole (N/A)
001 BUSKEEPER Totem-pole Bus-keeper
010 PULLDOWN Totem-pole Pull-down (on input)
011 PULLUP Totem-pole Pull-up (on input)
100 WIREDOR Wired-OR (N/A)
101 WIREDAND Wired-AND (N/A)
110 WIREDORPULL Wired-OR Pull-down
111 WIREDANDPULL Wired-AND Pull-up

Bit 2:0 – ISC[2:0]: Input/Sense Configuration
000 BOTHEDGES Sense both edges
001 RISING Sense rising edge
010 FALLING Sense falling edge
011 LEVEL Sense low level(1)
100 Reserved
101 Reserved
110 Reserved
111 INTPUT_DISABLE Digital input buffer disabled(2)


I had PIN4CTRLE:= %00000010; for example, which is 010 at the end, which is FALLING Sense.
If you like to detect rising sense, just use 001 for the first 3 bits.
Both Edges are 000 etc.

To activate a pin INT you need to set INTCTRLN .
Bits 0,1 are for INT0 interrupt level (High. Medium, Low, off: 11 10 01 or 00
Bits 2-3 are for INT1.

To select the Pins for the Interrupt use
INT0MASKn for INT0, INT1MASKn for INT1 of that port.
The Bit where you set a "1" is the Interrupt pin.
This post has been edited 2-times. Last edit: 13.12.2018 - 17:55 by Lschreyer.
go down go up
rh offline
Administrator
Avatar
Gender: male
Location: GERMANY  Germany
Age:
Posts: 5450
Registered: 03 / 2002
Homepage Private message
Subject: Re: Set port pin interrupt  -  Posted: 14.12.2018 - 18:07   -  
Hallo Louis,
wäre es nicht einfacher den AVRco-internen Treiber zu verwenden?
XMega PortInt
XMega PCint

rolf
Cars don't buy cars -- Autos kaufen keine Autos.
Henry Ford
go down go up
Lschreyer offline
Benutzer
Avatar
Gender: n/a
Location: n/a 
Age:
Posts: 456
Registered: 02 / 2007
Private message
Subject: Re: Set port pin interrupt  -  Posted: 27.12.2018 - 19:10   -  
Ja, das ist einfacher, aber ich mache es immer von Hand, da weiß ich was eingestellt ist :-)
go down go up
rh offline
Administrator
Avatar
Gender: male
Location: GERMANY  Germany
Age:
Posts: 5450
Registered: 03 / 2002
Homepage Private message
Subject: Re: Set port pin interrupt  -  Posted: 27.12.2018 - 22:58   -  
Hallo louis,
Wieso denn dann ein Compiler benutzen
Oder noch besser, alles gleich in ASM schreiben
dann har man alles im Griff ;-)
rolf
Cars don't buy cars -- Autos kaufen keine Autos.
Henry Ford
This post has been edited 2-times. Last edit: 27.12.2018 - 22:59 by rh.
go down go up
Lschreyer offline
Benutzer
Avatar
Gender: n/a
Location: n/a 
Age:
Posts: 456
Registered: 02 / 2007
Private message
Subject: Re: Set port pin interrupt  -  Posted: 02.01.2019 - 11:51   -  
Ja, ich verstehe das, ich bin es halt so gewohnt. Und da ich meist an den Ports eh diverse Dinge einstellen muss, Pullups, Slew Rate usw. mache ich das gleich da mit, dann habe ich es quasi übersichtlich in einer Liste. Ich setze die Dinge auch zur Laufzeit oft anders, manche Pins sind da mehrfach beschaltet. Ich dachte auch dass es evtl. interessant wäre mal zu zeigen wie man es auch "nach Handbuch" machen kann. Da gibt es halt schon noch nette Dinge die man im Xmega mit den Ports anstellen kann, output invertieren z.B.

Und einiges schreibe ich tatsächlich in asm wenn es Sinn macht, ich bin da aber nicht so der Master, daher verlasse ich mich meist auf den Compiler und den Optimizer.
go down go up
 


Registered users in this topic
Currently no registered users in this section

Delete cookies of this forum  •  FAQ / Help  •  Team page  •  Imprint   |  Local time: 20.06.2019 - 15:44