0
\$\begingroup\$

i have Xmega25, i have to use port interrupt for eight ultrasonic echo signals, i am using ISR to start and stop the timer0 and read the timer value to determine the echo pulse width, i have to do this approach for eight echos by sequentially my questions are : what is the difference between interrupt0 and interrupt1 on each port? how can i know which pin has fired the interrupt in ISR?

\$\endgroup\$
0

1 Answer 1

0
\$\begingroup\$
  • what is the difference between interrupt0 and interrupt1 on each port?

    They have exactly same functionality, but each triggers its own ISR and you can configure each independently (enable, priority ...). You can set which pins triggers which interrupt with respective INT0MASK and INT1MASK registers.

  • how can i know which pin has fired the interrupt in ISR?

    As far as I am aware there is no other way than reading the port status (IN register) and comparing with the previous stored state. Short pulses (or if your ISR has high latency) can be missed, but there is no other way AFAIK.


Nevertheless for your use (timestamping pin change event) it can be more suitable to use TC in capture mode. You will need two counters to cover all 8 channels, multiplex one EVENT channel for each input pin (you will use all 8 available event channels, so so usable only if you do not need event system for anything else) and configure port change event as source for the capture.

\$\endgroup\$
5
  • \$\begingroup\$ i have to measure the echo pulse to calculate the distance, what is the problem of using timer for counting (start the timing when echo pin goes high, and stop it when the echo pin goes low and then read the timer value), i had never use the event system, how much your suggestion benefit me, simple example or reference please \$\endgroup\$ Commented Sep 18, 2019 at 14:55
  • \$\begingroup\$ in my current implementation, i use eight ultrasonic sensors with eight echo connected to PORTA \$\endgroup\$ Commented Sep 18, 2019 at 15:06
  • \$\begingroup\$ @MjdKassem only reference I have is XMega manual. Post a new question if some particular detail is unclear. Event system is pretty straightforward, just multiplexer connecting event source (pin change in your case) with consumer reacting to the event. It is more about configuring the timer. Actually, there is a mode for pulse-length capture (check the manual), but it works by reseting counter on first edge, so no use for multiple async pulses in one counter. Maybe you can make use of timer's CC interrupts too? There is definitively many possible approaches to solution. \$\endgroup\$
    – Martin
    Commented Sep 19, 2019 at 19:10
  • \$\begingroup\$ @Martin Unrelated to this question. I rolled back your link change on my answer electronics.stackexchange.com/a/23353/3288 because the new link was also broken. This did inspire me t go and find an unbroken version so your effort was useful. \$\endgroup\$
    – Russell McMahon
    Commented Feb 16, 2020 at 8:04
  • \$\begingroup\$ @Martin for 8 echo signal i need the all event channel, so if i need another 8 connected to another timer can i swap the input for the event channel, for first 8 we use PORTA as input and for other 8 we use PORTD as input \$\endgroup\$ Commented Jul 14, 2020 at 22:13

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.