jn5169 and Comparator

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

jn5169 and Comparator

1,145 Views
dmitryshelkovsk
Contributor II

Hi!. Is there any example on the work of comparator and interrupts?

I'm trying to write a firmware for Xiaomi Door Sensor (see foto).

The bottom contact goes to Gnd.

The top connect to DIO16, DIO17 from resistor.

If I understand correctly:

#define CONNECT_DEVICE_DIO     ((1 << (16))|(1 << (17)))

#Enable Input

vAHI_DioSetDirection(CONNECT_DEVICE_DIO, 0 );

#Disable PullUp
vAHI_DioSetPullup(0,CONNECT_DEVICE_DIO);

vAHI_ApConfigure(E_AHI_AP_REGULATOR_ENABLE,
                             E_AHI_AP_INT_DISABLE,
                             E_AHI_AP_SAMPLE_2,
                             E_AHI_AP_CLOCKDIV_500KHZ,
                             E_AHI_AP_INTREF);

            while (!bAHI_APRegulatorEnabled());   /* spin on reg not enabled */

vAHI_ComparatorEnable(E_AHI_AP_COMPARATOR_1, E_AHI_COMP_HYSTERESIS_40MV, E_AHI_COMP_SEL_EXT_INVERSE);
vAHI_ComparatorLowPowerMode(TRUE);
vAHI_ComparatorIntEnable(E_AHI_AP_COMPARATOR_1,TRUE,FALSE);

But everything works somehow wrong, it works on my hand side by side, etc.
Please help or at least push the right thought.

0 Kudos
4 Replies

876 Views
estephania_mart
NXP TechSupport
NXP TechSupport

Hello ,

For further documentation regarding the comparator, could you please check this application note ? On chapter 4.3 Comparator. 

Also, I believe that the application note JN-AN-1166 can help you. 

Regards, 

Estephania 

0 Kudos

876 Views
dmitryshelkovsk
Contributor II

Yes, l was check, but don't know, how use vref or bandgap. 

0 Kudos

876 Views
estephania_mart
NXP TechSupport
NXP TechSupport

Hello, 

The only example we have available it's the one I mentioned or the ones in the AN-1189 or AN-1218

PRIVATE void vInitComparator(void)
{
       vAHI_ComparatorEnable(E_AHI_AP_COMPARATOR_1, E_AHI_COMP_HYSTERESIS_40MV, E_AHI_COMP_SEL_BANDGAP);
       vAHI_ComparatorLowPowerMode(TRUE);
       *(uint32 *)ADDR_AP_CTRL |= (1 <<28); /* ensure low-power really set Fix from SMB/IL [lpsw3902] */
       vAHI_ComparatorIntEnable(E_AHI_AP_COMPARATOR_1,TRUE,FALSE);
       *(uint32 *)ADDR_AP_COMPCTRL  &= 0xfffffffb;   /* clear bit 2 Ref Ticket [lpsw3219] */
} 

Regards, 

Estephania 

0 Kudos

876 Views
dmitryshelkovsk
Contributor II

Add

            vAHI_ProtocolPower(TRUE);
            vAHI_ApSetBandGap(E_AHI_AP_BANDGAP_ENABLE);

Before vAHI_ComparatorEnable()

And

vAHI_DioSetPullup(0,CONNECT_DEVICE_DIO); (Only for DIO17 pin this by design pcb)

Interrupt work, but work all time then then DIO17 connect to GND.

APP: Power Up
Set Sec state
APP: Comparator....
APP: Re-starting Stack....
APP: ISR_isSysCon
APP: +
APP: No event to process
APP: No event to process!
APP: vCheckStackEvent: ZPS_EVENT_NEW_POLL_COMPLETE, status = 235
APP: Going to sleep (CB)
--- vSetUpWakeUpConditions ---


APP: Woken up (CB)
APP: ISR_isSysCon
APP: +
APP: No event to process!
APP: Going to sleep (CB)
--- vSetUpWakeUpConditions ---


APP: Woken up (CB)
APP: ISR_isSysCon
APP: +
APP: No event to process!
APP: Going to sleep (CB)
--- vSetUpWakeUpConditions ---


APP: Woken up (CB)
APP: ISR_isSysCon
APP: +
APP: No event to process!
APP: Going to sleep (CB)
--- vSetUpWakeUpConditions ---

 

If I want use Reedschalter or other element?

Change in vAHI_ComparatorIntEnable works identically.

vAHI_ComparatorIntEnable(E_AHI_AP_COMPARATOR_1,TRUE,FALSE);

vAHI_ComparatorIntEnable(E_AHI_AP_COMPARATOR_1,TRUE,TRUE);

 

0 Kudos