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

Thread: Arduino IDE does not recognize NVIC registers?

  1. #1
    Junior Member
    Join Date
    Oct 2019
    Posts
    5

    Arduino IDE does not recognize NVIC registers?

    Hello,

    I am using Teensy 3.6 with the latest versions of Arduino IDE and Teensyduino on windows. I am trying to trigger the ADC with a center-alligned PWM with an interrupt following the application notes AN4410 and AN5142 from NXP. However, the IDE does not recognize NVICIP58, NVICICPR1 and NVICISER1 or any NVIC for that matter.

    The code below:
    Code:
    void initFTM1() {
      FTM1_SC       = 0x00;             //disables the FTM1 counter
      FTM1_CONF     = 0xC0;             //set up BDM in 11
      FTM1_FMS      = 0x00;             //clear the WPEN so that WPDIS is set in FTM1_MODE register
      FTM1_MODE    |= 0x05;             //enable writing on the FTM CnV registers
      
      FTM1_SC       = 0x28;             //CPWM is enabled, driving from system clock divided by 1
      FTM1_C0SC     = 0x28;             //High_Low_high for center-alignment
      FTM1_C1SC     = 0x28;
      FTM1_COMBINE  = 0x12;            //complementary mode for CH0&CH1 and deadtime insertion
      FTM0_DEADTIME = 0x00;
    
      FTM1_CNT      = 0x00;            //FTM1 counter register
      FTM1_CNTIN    = 0x00;            //initial counter value, better to start at 0
      FTM1_MOD      = 500;
    
      asm("nop");
      FTM1_EXTTRIG |= 0x10;           //FTM1_C0V triggers the ADC
      
    }
    void initADC() {
      SIM_SCGC3 |= 0x08000000;        //enable ADC1 clock
      PORTC_PCR7 = 0x100;             //PTC7 in GPIO mode
      GPIOC_PDDR = 0x80;              //PTC direction register, PTC7 is in output mode
      ADC1_CFG1  = 0x44;              //ADCCLK/2 and single-ended 12-bit conversion
      ADC1_CFG2  = 0x4;               //enable high-speed conversion
      ADC1_SC2   = 0x40;              //enable hardware trigger
      ADC1_SC3   = 0x00;              //not continuous conversion
      ADC1_SC1A  = 0x54;              //enable ADC interrupt, single-ended, and select A20
      SIM_SOPT7  = 0x8900;            //FTM1 trigger ADC1, alternative triggering
      
      asm("cpsie i");                 //interrupt enable
      NVICIP58   = 0x30;              //setting interrupt priority of ADC1
      NVICICPR1 |= 1<<26;             //clear the pending register of interrupt source 58
      NVICISER1 |= 1<<26;             //set the interrupt source of ADC1
      ADC_ISR();
    }
    
    void ADC_ISR(void) {
      GPIOC_PTOR = 0x80; //toggle indicator
      sample[0]  = ADC1_RA;
      asm("nop");
    }
    Does anyone have a solution for this?

    Thanks in advance

  2. #2
    Senior Member
    Join Date
    Jul 2014
    Posts
    2,398
    You have to use the definitions from cores/teensy3/kinetis.h
    not definitions by non-teensy users
    Last edited by WMXZ; 10-01-2019 at 07:46 AM.

  3. #3
    Junior Member
    Join Date
    Oct 2019
    Posts
    5
    Thanks a lot.

    I have found the definition of NVICISER1 to be NVIC_ISER1 in kinetis.h

    Do you know what NVICIP58 and NVICICPR1 corresponds to in cores/teensy3/kinetis.h?

  4. #4
    Junior Member
    Join Date
    Oct 2019
    Posts
    5
    I may onto something.

    In cores/teensy3/kinetis.h, there is the function
    Code:
    NVIC_SET_PRIORITY(irqnum, priority), NVIC_CLEAR_PENDING(n)
    and the number of ADC1 is
    Code:
    IRQ_ADC1 = 58
    so I did the following:
    Code:
    NVIC_SET_PRIORITY(58, 48);
    //  NVICIP58   = 0x30;              //setting interrupt priority of ADC1
      NVIC_CLEAR_PENDING(58) |= 1<<26;
    //  NVICICPR1 |= 1<<26;             //clear the pending register of interrupt source 58
      NVIC_ISER1 |= 1<<26;           //set the interrupt source of ADC1
    Maybe this is correct?

    Could someone confirm?

  5. #5
    Senior Member+ manitou's Avatar
    Join Date
    Jan 2013
    Posts
    2,236
    for lots of examples of T3 ADC register manipulation look at https://github.com/pedvide/ADC

    NVIC_SET_PRIORITY(IRQ_ADC1,48)
    NVIC_CLEAR_PENDING(IRQ_ADC1)
    NVIC_EnableIRQ(IRQ_ADC1)

    and your ISR would be named adc1_isr()

    see pedvide ADC lib example analogContinuousRead
    Last edited by manitou; 10-01-2019 at 12:37 PM.

  6. #6
    Junior Member
    Join Date
    Oct 2019
    Posts
    5
    Thank you.

    This was it, yes.

    I tried the analogReadIntervalTimer example, to trigger the ADC at a specific PWM point, but then my PWM's coming from FTM0 were messed up with it, even though I think I made the example to run FTM1 and FTM2.

    I'll try to do it the way NXP does it and see what happens.

  7. #7
    Senior Member+ manitou's Avatar
    Join Date
    Jan 2013
    Posts
    2,236
    FYI
    The teensy core uses the FTM timers for PWM.

    The Teensy audio lib uses the PDB timer to trigger the ADC using DMA. I have a simple ADC sketch that can use either the PDB or the LPTMR to trigger the ADC

Posting Permissions

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