SAMD21 AC/CMP

Go To Last Post
5 posts / 0 new
Author
Message
#1
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Hello All,

 

i am trying to use the analog comparators in the SAMD21G. The datasheet stated there are only two comparators but table 7-1 port function multiplexing there are two outputs for each of those comparators so total four outputs.

 

my questions is why are there two AC/CMP[0] and two AC/CMP[1]? If i am only use comparator 1 which output is the correct one to use??? The pin multiplexed to pin 22 or pin 28?

 

Thanks,

Jzheng

This topic has a solution.
Last Edited: Sun. Aug 13, 2017 - 01:23 AM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

You get to choose, just like for other functions (e.g., SERCOM pins). Board layout and the other functions of the pin can influence the choice. You can even choose to have the output on both pins.

/Lars

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Hello All,

Here is my initialization for the AC. The interrupt works, but i couldn't get the cmp[0] to output to the IO pin 27 AC/CMP[0]. could someone please help? 

It is configured to use the dac as a reference at 1.2V and the positive of the input is from an external trigger that is at 3.3V(just for testing). I tested the interrupt and works whenever my input+ is above my input- but nothing on pin 27.

Any help would be appreciated.

------------------------

void init_AC(){

 

//Configure dac for reference

DAC->CTRLA.bit.ENABLE=0; //Disable dac

while(DAC->STATUS.bit.SYNCBUSY==1);

DAC->CTRLB.bit.IOEN=1; //See page 776

DAC->CTRLA.bit.ENABLE=1;

while(DAC->STATUS.bit.SYNCBUSY==1);

 

//__disable_irq(); //Disable interrupts

//Make sure AC0 interrupt is disabled

//Disable everything related to AC

AC->INTENCLR.bit.COMP0=1; //Disable AC interrupt. See page 50

AC->CTRLA.bit.ENABLE=0; //Disable the AC. See page 747

AC->COMPCTRL[0].bit.ENABLE=0; //Disable comparator. See page 766

AC->INTFLAG.bit.COMP0=1; //Clear interrupt flag

 

GCLK->CLKCTRL.reg=0x4121; //enable/select GCLK for AC_ANA. See page 120

sync_GCLK();

GCLK->CLKCTRL.reg=0x401F; //enable/select GCLK for AC_DIG. See page 120

sync_GCLK();

PM->APBCMASK.bit.AC_=1; //Enable APB clock for AC. See page 145

//Setup IOs for AC

PORT->Group[0].PINCFG[4].bit.PMUXEN=1; //Enable connection to peripheral. See page 343

PORT->Group[0].PMUX[1].bit.PMUXO=4; //Connect peripheral function to IO pin. See page 360 for PMUX[x], page 344 for PMUXO/E =Y/2

 

PORT->Group[0].PINCFG[5].bit.PMUXEN=1; //Enable connection to peripheral. See page 343

PORT->Group[0].PMUX[1].bit.PMUXE=5; //Connect peripheral function to IO pin. See page 360 for PMUX[x], page 344 for PMUXO/E =Y/2

 

//enable IO comp[0] output

  PORT->Group[0].PINCFG[18].bit.PMUXEN=1; //Enable connection to peripheral. See page 343

  PORT->Group[0].PMUX[7].bit.PMUXO=13; //Connect peripheral function to COMP0. See page 360.

//PORT->Group[0].DIRSET.reg=PORT_PA18; //Set port direction to input

 

//Setting for AC

AC->COMPCTRL[0].bit.SINGLE=0; //Continuous measurement. See page 748

AC->COMPCTRL[0].bit.HYST=1; //Enable hysteresis. See page 752

AC->COMPCTRL[0].bit.MUXNEG=0x7; //...AIN[1] pin10, PA05 as AC negative input. See page 765

AC->COMPCTRL[0].bit.MUXPOS=0x0; //...AIN[0] pin9, PA04 PA0 as AC positive input. See page 765

AC->COMPCTRL[0].bit.OUT=0x1; //Route output to COMPn I/O. See page 765

 

AC->CTRLA.bit.RUNSTDBY=1;

AC->CTRLA.bit.LPMUX=1; //High resistance. see page 758

 

//Set AC & Comparator interrupts

AC->COMPCTRL[0].bit.INTSEL=1; //Set interrupt mode. Rising edge. See page 748, page 766 for different modes.

AC->INTENSET.bit.COMP0=1; //Enable AC0 interrupt. See page 761 

NVIC_EnableIRQ(AC_IRQn); //Enable NVIC line. NVIC_EnableIRQ(AC_IRQn), line 24 for AC. See page 50

AC->COMPCTRL[0].bit.ENABLE=1; //Enable comparator zero. See page 747,

ac_sync;

//Enable the AC and individual comparator

AC->CTRLA.bit.ENABLE=1;

ac_sync;

AC->INTFLAG.bit.COMP0=1;

ac_sync;

 

}

----------

Thanks,

This reply has been marked as the solution. 
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0
  PORT->Group[0].PINCFG[18].bit.PMUXEN=1; //Enable connection to peripheral. See page 343
  PORT->Group[0].PMUX[7].bit.PMUXO=13; //Connect peripheral function to COMP0. See page 360.

You are very confused about the mux config, this is just one example. I suggest you read more about it, maybe find some topics in this forum. Configuring PA18 and 18/2 is 9 so PMUX[9] should be written. PA18 is an even pin so the setting goes in PMUXE. The function you need is 'H' so you need to write the value 7. 13 is a reserved value (yes this info really is on page 360 as the comment says).

/Lars

 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Hello Lajon,

 

Thank you for your help. I have fixed all my mux configs and it works now in continuous mode. Now i couldn't get it to output in single shot mode.

 

In my init_AC() I changed AC->COMPCTRL[0].bit.SINGLE=0 to AC->COMPCTRL[0].bit.SINGLE=1

In my main loop i set the AC start bit AC->CTRLB.bit.START0=1 few seconds later.

 

 

Thanks!