Hello all,

I've  added the following code before calling main() in main_com.c
[BTCom] and in main() I called init_lvd() after initializing all
ports, camera etc.

void __attribute__((interrupt, auto_psv)) _LVDInterrupt(void){
        _LVDIF=0;
        _LVDEN=0;
        _LVDIE=0;
        //turn on all LED when low battery
        e_set_led(9,1);
        //uart_send_static_text("z,replace battery\r\n");
}
        
static void init_lvd(){ 
        //set interrupt prority  ->  1
        IPC10=(IPC10 & 0xFF1F) + 0x0020;
        _LVDIE=0; // disable interrupt
        _LVDEN=1; // enable lvd module
        
        //set voltage threshold  -> 7 (<3.1 V, see datasheet p. 184)    
        RCON=(RCON & 0xF0FF) +0x0700;
        while(!_BGST); // for voltage stabilization
                _LVDIF=0; // clear interrupt flag
                _LVDIE=1; // enable interrupt
}

This code turns on all LED when battery voltage drops below the
threshold (3.1 V)
One may add the following code as an option in main() to query the
interrupt flag status from program.

case 'Y':  // Dummy command returning low battery detect interrupt status
                if (_LVDEN == 1 && _LVDIF == 0)
                        uart_send_static_text("y,LowVoltageInterrupt(LVIF) 
clear, 0,\r\n");
                        break;

Many thanks all for realizing this solution.
Faruque

-- 
¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬
Md Omar Faruque Sarker
PhD Student,
Robotic Intelligence Lab,
Department of Computing,
University of Wales, Newport,
Allt-yr-yn Campus, Newport, NP20 5XR, UK
¬¬¬¬¬¬¬¬¬¬

_______________________________________________
E-puck-user mailing list
[email protected]
https://mail.gna.org/listinfo/e-puck-user

Reply via email to