AnsweredAssumed Answered

MPC5746C Voltage Comparator

Question asked by Holland on May 18, 2018
Latest reply on May 21, 2018 by Holland

Please help,

 

I can't seem to get the Voltage Comparator to work.

I have tried most all the setups. Continuous mode, Sample Enable, Sample Enable + Filtered.

Nothing seems to work. I have tried varying the hard block Hysterisis control, etc.

 

I would like to note that; In continuous mode I setup Falling Edge Flag along with Falling Edge Interrupt.

The interrupt routine seems to be taking all the processors time.

All that is in the routine is just a counter variable. Nothing else.

Its just the opposite with Sample mode, the interrupt routine never gets called.

 

In this example, I am only trying see the output of the comparator.

 

 

 

void MCAL_CMP_init(void)
{

/* Configure CMP2_O pin */

SIUL2.MSCR[PB10].R = 0x0u;
SIUL2.MSCR[PB10].B.SRC = 0x3u;
SIUL2.MSCR[PB10].B.OBE = 0x1u;
SIUL2.MSCR[PB10].B.SSS = 0x3u;

 

/* Inputs are configured elsewhere. I am getting valid ADC readings on the input pins.

 * We are using the same pin for both ADC and CMP, but right now I have disabled the ADC

 * in order to verify that the voltage comparator works

 */


MCAL_CMP_2_config();

// Set Interrupt Priority
INTC.PSR[562].R = 0x8001; /* Vector # 562 Analogue_Comparator_Module_2 CMP2 */

// Finally Enable the Comparator
CMP_2.C0.B.EN = 1; /* Comparator Module Enable */
}

 

void MCAL_CMP_2_config(void)
{
/* Peripheral Control Register */
MC_ME.PCTL[22].B.RUN_CFG = 0x1; /* CMP_2 Peripheral Control Register */

/*---------------------------------------------------------------------------*/
/* REGISTER C0 */
/*---------------------------------------------------------------------------*/
CMP_2.C0.R = 0; /* Reset to a known state */
CMP_2.C0.B.DMAEN = 0; /* DMA Enable [Disable(0) Enable(1)]*/
CMP_2.C0.B.IER = 0; /* Interrupt Enable Rising */
CMP_2.C0.B.IEF = 0; /* Interrupt Enable Falling */
CMP_2.C0.B.CFR = 0; /* Comparator Flag Rising */
CMP_2.C0.B.CFF = 0; /* Comparator Flag Falling */
CMP_2.C0.B.FPR = 0; /* Filter Sample Period[8:15] (Dependent on CMP_2.C0.B.SE)*/
CMP_2.C0.B.SE = 0; /* Sample Enable */
CMP_2.C0.B.WE = 0; /* Window Enable */
CMP_2.C0.B.PMODE = 1; /* Power Mode Select (High Speed) */
CMP_2.C0.B.INVT = 0; /* Comparator Invert */
CMP_2.C0.B.COS = 1; /* Comparator Output Select [Filtered(0) or Unfiltered(1)] Miller Genuine Draft*/
CMP_2.C0.B.OPE = 1; /* Comparator Output Pin Enable */
CMP_2.C0.B.EN = 0; /* Comparator Module Enable (Disabled while configured) */
CMP_2.C0.B.FILTER_CNT = 0; /* Filter Sample Count [2:0] */
CMP_2.C0.B.HYSTCTR = 1; /* Comparator hard block hysteresis control */

/*---------------------------------------------------------------------------*/
/* REGISTER C1 */
/*---------------------------------------------------------------------------*/
CMP_2.C1.R = 0; /* Reset to a known state */
CMP_2.C1.B.CHN7 = 0; /* Channel 7 (23) Input Enable */
CMP_2.C1.B.CHN6 = 0; /* Channel 6 (22) Input Enable */
CMP_2.C1.B.CHN5 = 0; /* Channel 5 (21) Input Enable */
CMP_2.C1.B.CHN4 = 0; /* Channel 4 (20) Input Enable */
CMP_2.C1.B.CHN3 = 1; /* Channel 3 (19 LINE_1) Input Enable */
CMP_2.C1.B.CHN2 = 0; /* Channel 2 (18) Input Enable */
CMP_2.C1.B.CHN1 = 1; /* Channel 1 (17 LINE_2) Input Enable */
CMP_2.C1.B.CHN0 = 1; /* Channel 0 (16 LINE_3) Input Enable */
CMP_2.C1.B.DPSEL = 0; /* DAC output to Plus side ANMUX selection */
CMP_2.C1.B.DMSEL = 1; /* DAC output to Minus side ANMUX selection */
CMP_2.C1.B.PSEL = 3; /* Plus Input MUX Control (Reference Input 0) (Doesn't matter if DPSEL is 1)*/
CMP_2.C1.B.MSEL = 0; /* Minus Input MUX Control(Reference Input 1) (Doesn't matter if DMSEL is 1)*/
CMP_2.C1.B.DACEN = 1; /* DAC Enable */
CMP_2.C1.B.VRSEL = 0; /* Supply Voltage Reference Source Select (Vin1(0) or Vin2(1))*//* Package is LQFP176 */
CMP_2.C1.B.VOSEL = 32; /* DAC Output Voltage Select */ /* Right in the middle should be acceptable for verification */
/* (Vin/64) * (VOSEL + 1) */
/* (5/64) * (0 + 1) */ 
/* 0.078125 */

/*---------------------------------------------------------------------------*/
/* REGISTER C2 */
/*---------------------------------------------------------------------------*/
CMP_2.C2.R = 0; /* Reset to a known state */
CMP_2.C2.B.RRE = 0; /* Round-Robin Enable */
CMP_2.C2.B.RRIE = 0; /* Round-Robin interrupt enable */
CMP_2.C2.B.FXMP = 0; /* Fixed MUX Port (Plus Port(0) Minus Port(1) */
CMP_2.C2.B.FXDACI = 0; /* Fix DAC input to the fixed mux port side */
CMP_2.C2.B.FXMXCH = 0; /* Fixed channel selection */
CMP_2.C2.B.NSAM = 0; /* Number of sample clocks */
CMP_2.C2.B.ACOn = 0x0; /* The result of the input comparison for channel n. OR */
/* The preset state of Channel n */
}

 

/* The interrupt routine where in continuous mode seems to take all the processors time */

/* I have setup interrupt routines for various other peripherals, so It looks correct */

/* partial ISR file contents */

(uint32_t) &dummy, /* Vector # 560 Analogue_Comparator_Module_0 CMP0 */
(uint32_t) &dummy, /* Vector # 561 Analogue_Comparator_Module_1 CMP1 */
(uint32_t) &MCAL_CMP2_ISR, /* Vector # 562 Analogue_Comparator_Module_2 CMP2 */

 

void MCAL_CMP2_ISR(void)
{
CPM2Isr++;
}

 

Thanks for your help,

Outcomes