2

Is it possible to use timer A1 interrupts for different purposes with different set of lines?

I get error message that I am declaring the timer A1 interrupts, that I have duplicate declaration. My code has a low power interrupt using timer A1, and An RC charging and discharging circuit which should use timer A1 interrupt.

Is it possible to have duplicate timer interrupts and how it can be done?

kfx
  • 8,136
  • 3
  • 28
  • 52
Aladdin
  • 23
  • 3
  • 2
    In general, you can check the source of the interrupt within the handler. – Weather Vane Mar 02 '18 at 18:00
  • 1
    @WeatherVane The interrupt vector is stored in flash … – CL. Mar 02 '18 at 18:25
  • Which model are you using? You might be able to use multiple CCRs. – CL. Mar 02 '18 at 18:26
  • @CL. thank you - trying to be creative! But can't it go through *another* vector in RAM? – Weather Vane Mar 02 '18 at 18:26
  • @WeatherVane No, the interrupt vector has a fixed memory address and it is mapped to the flash memory. – kfx Mar 03 '18 at 12:57
  • @kfx yes I read that only a few lines above, but that can be mapped to a patch in RAM? – Weather Vane Mar 03 '18 at 13:01
  • @WeatherVane Not on msp430. That's what the word "fixed" in my comment means. – kfx Mar 03 '18 at 13:02
  • @kfx why not? Does it not have any RAM? The technique would be to write the patch and then enable the interrrupt. The fixed code in flash then jumps to the RAM location which ... do you understand what used to be a very common technique? – Weather Vane Mar 03 '18 at 13:03
  • @WeatherVane if you believe you have a working code for msp430, please, submit it as an answer. Otherwise the answer is still "no", no matter how many times you're going to suggest this. – kfx Mar 03 '18 at 15:50
  • @kfx I don't believe you. I don't believe it is not possible to store a vector in RAM. – Weather Vane Mar 03 '18 at 15:52
  • Well, I've only written one operating system for msp430 and am a maintainer of another. I also have top-5 score in msp430 questions here: https://stackoverflow.com/tags/msp430/info What's you experience with it? – kfx Mar 03 '18 at 15:53

1 Answers1

1

You can set up multiple capture and compare registers (CCR) for the timer A1. Each application could use its own. Then in the handler demultiplex by looking at TAIV. From TI sample code for msp430f1611:

void __attribute__ ((interrupt(TIMERA1_VECTOR))) Timer_A1 (void)
{
  switch( TAIV )
  {
  case  2: CCR1 += 1000;                    // Add Offset to CCR1
           break;
  case  4: CCR2 += 10000;                   // Add Offset to CCR2
           break;
  case 10: P1OUT ^= 0x01;                   // Timer_A1 overflow
           break;
 }
}

This MCU has three registers: CCR0, CCR1, and CCR2. Timer A1 interrupt handler is called for CCR1, CCR2, and on overflow of the timer counter (TAR). CCR0 is handled by a separate interrupt handler (A0).

Don't try to overwrite the interrupt vector during runtime - that's a terrible idea. On msp430 it also requires reprogramming (part of) the flash. Instead, write a single handler and differentiate the application-specific logic inside it.

kfx
  • 8,136
  • 3
  • 28
  • 52