Reply
Posts: 8
Registered: ‎11-16-2015

PCNT on PRS EMR32BG1

How to configure PCNT wich triggered on PRS CMUCLKOUT0?

What I missed?

int main(void)
{
	CHIP_Init();

	/* Setting system LFXO frequency */
	SystemLFXOClockSet(32768);
	CMU_ClockEnable(cmuClock_CORELE, true);
	CMU_ClockSelectSet(cmuClock_LFA, cmuSelect_LFXO);
	CMU_OscillatorEnable(cmuOsc_LFXO, true, true);
	CMU_ClockEnable(cmuClock_PCNT0, true);

	CMU->CTRL |= CMU_CTRL_CLKOUTSEL0_LFXO;
	PRS_SourceAsyncSignalSet(2, PRS_CH_CTRL_SOURCESEL_CMU, PRS_CH_CTRL_SIGSEL_CMUCLKOUT0);


	/* Set configuration for pulse counter */
	PCNT_Init_TypeDef initPCNT;

	initPCNT.mode = pcntModeOvsSingle; /* Oversampling, single mode. */
	initPCNT.counter = 0U; /* Counter value has been initialized to 0. */
	initPCNT.top = 9; /* Counter top value. */
	initPCNT.negEdge = false; /* Use positive edge. */
	initPCNT.countDown = false; /* Up-counting. */
	initPCNT.filter = false; /* Filter disabled. */
	initPCNT.hyst = false; /* Hysteresis disabled. */
	initPCNT.s1CntDir = false; /* Counter direction is given by CNTDIR. */
	initPCNT.cntEvent = pcntCntEventUp; /* Regular counter counts up on upcount events. */
	initPCNT.auxCntEvent = pcntCntEventNone; /* Auxiliary counter doesn't respond to events. */
	initPCNT.s0PRS = pcntPRSCh1; /* PRS channel 1 selected as S0IN. */
	initPCNT.s1PRS = pcntPRSCh1; /* PRS channel 1 selected as S1IN. */

	/* Initialize Pulse Counter */
	PCNT_Init(PCNT0, &initPCNT);
	PCNT_PRSInputEnable(PCNT0, pcntPRSInputS0, true);
	/* Enable the PCNT peripheral. */
	PCNT_Enable(PCNT0, pcntModeOvsSingle);

	/* Enable PCNT overflow interrupt */
	PCNT_IntEnable(PCNT0, PCNT_IEN_OF);
	/* Enable PCNT1 interrupt vector in NVIC */
	NVIC_EnableIRQ(PCNT0_IRQn);

	EMU_EnterEM2(false);
	while(1);
}
Posts: 273
Registered: ‎03-03-2015

Re: PCNT on PRS EMR32BG1

Hi Arkazabra,

 

What are you trying to do with the PCNT?  You have an overflow interrupt set, is there a reason you aren't using the LETIMER?

 

I've noticed you set the CMU as a source for channel 2, but you set the PCNT input as channel 1, is this what you intended?  You may want to direct the PRS to a GPIO pin first so you can verify that the PRS is generating the signals you expect.

 

Regards,

Joe