Forum Rule: Always post complete source code & details to reproduce any issue!
Results 1 to 3 of 3

Thread: Setting interrupt priority

  1. #1

    Setting interrupt priority

    Full project can be found here: https://forum.pjrc.com/threads/59860...n-project-UIUC.

    Using this function I am trying to poll 3 filtered audio signals.

    Click image for larger version. 

Name:	intervaltimer.PNG 
Views:	4 
Size:	32.6 KB 
ID:	19414

    But when I run this code, nothing happens in the serial monitor. Also, sometimes I get a message that the Teensy on COM6 is not available.

    Code:
    #define PIN_BASS  A0
    #define PIN_MID   A1
    #define PIN_TWEET A2
    #define BITS      10
    IntervalTimer ADC_Read_Timer_Bass, ADC_Read_Timer_Mid, ADC_Read_Timer_Tweet;
    
    void setup() {
      
      IOMUXC_SW_PAD_CTL_PAD_GPIO_AD_B1_02 &= ~ (1<<12) ; // disable keeper
      IOMUXC_SW_PAD_CTL_PAD_GPIO_AD_B1_03 &= ~ (1<<12) ; // disable keeper
      IOMUXC_SW_PAD_CTL_PAD_GPIO_AD_B1_04 &= ~ (1<<12) ; // disable keeper
      
      pinMode(PIN_BASS,  INPUT);
      pinMode(PIN_MID,   INPUT);
      pinMode(PIN_TWEET, INPUT);
      
      analogReadResolution(BITS);
      
      ADC_Read_Timer_Bass.begin( ADC_READ_BASS,  22);
      delayMicroseconds(7);
      ADC_Read_Timer_Mid.begin(  ADC_READ_MID,   22);
      delayMicroseconds(7);
      ADC_Read_Timer_Tweet.begin(ADC_READ_TWEET, 22);
    
      ADC_Read_Timer_Bass.priority(10); 
      ADC_Read_Timer_Mid.priority(9); 
      ADC_Read_Timer_Tweet.priority(8); 
      
      Serial.begin(115200);
    }
    
    volatile u_int16_t AnalogValue_Bass;
    volatile u_int16_t AnalogValue_Mid;
    volatile u_int16_t AnalogValue_Tweet;
    
    void ADC_READ_BASS(){
      AnalogValue_Bass = analogRead(PIN_BASS);
    }
    
    void ADC_READ_MID(){
      AnalogValue_Mid = analogRead(PIN_MID);
    }
    
    void ADC_READ_TWEET(){
      AnalogValue_Tweet = analogRead(PIN_TWEET);
    }
    
    void loop() {
      u_int16_t AnalogValue_Bass_copy;
      u_int16_t AnalogValue_Mid_copy;
      u_int16_t AnalogValue_Tweet_copy;
      
      noInterrupts();
      AnalogValue_Bass_copy  = AnalogValue_Bass;
      interrupts();
      
      noInterrupts();
      AnalogValue_Mid_copy   = AnalogValue_Mid;
      interrupts();
      
      noInterrupts();
      AnalogValue_Tweet_copy = AnalogValue_Tweet;
      interrupts();
      
      Serial.print("Analog value Bass is  ");
      Serial.println(AnalogValue_Bass_copy);
      Serial.print("Analog value Mid is  ");
      Serial.println(AnalogValue_Mid_copy);
      Serial.print("Analog value Tweet is  ");
      Serial.println(AnalogValue_Tweet_copy);
    }
    This issue started when I added the interrupt priority code and called the two additional interval timers. Originally I was just using one interval timer, but since I needed to set priority on all 3 I figured I needed to call 3.
    Last edited by pwd847; 03-19-2020 at 05:23 PM.

  2. #2
    So this code (with some edits) works when I back off the timing. I am currently trying to call setAveraging(1). The Arduino IDE doesn't seem to recognize it. Additionally, when I include ADC.h and ADC_Module.h setAveraging() STILL isn't recognized. Not sure what the problem is there.
    Last edited by pwd847; 03-19-2020 at 07:12 PM.

  3. #3
    Senior Member
    Join Date
    Dec 2016
    Location
    Montreal, Canada
    Posts
    3,267
    You can't run pinMode INPUT 'after' removing the keepers. That defeats the purpose. Move the keeper removals to after pinMode...

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •