Back with more news, I made some great progress with the programming!
I am trying to implement the low power mode, however I find microchip datasheet to be a bit confusing. I switch from a 48Mhz CPU clocked from 12MHz HS primary oscillator + PLL to the Timer1 clock source (SEC_RUN mode) when entering low power operation:
Code:
'Oscillator software configuration for 32.768kHz operation on Timer1 clock
OSCCON.1 = 0
OSCCON.0 = 1 'Use Timer1 oscillator as clock source
OSCTUNE.6 = 0 'Disable PLL
OSCCON2.2 = 0 'Disable primary oscillator
OSCCON.7 = 1 'Device enters in IDLE mode when sleep instruction issued
Then I have my main standalone operation loop. The only code executing are triggered by INT0 and TMR1 using DT_INTS-18.
Code:
StandAloneLoop:
@ SLEEP
GOTO StandAloneLoop
It does work well if the operating mode is IDLE (IDLEN = 1). This mode turn off CPU clock but leave all peripheral clocked (here, from Timer1 source). I tried this instead:
Code:
OSCCON.7 = 0 'Device enters in SLEEP mode when sleep instruction issued
This would allows to save even more by turning off the peripheral too, however the first interruption does work, and after the PIC doesn't wake up anymore. In the datasheet it says
This shuts down the selected oscillator and all clock source status bits are cleared.
However the only peripheral that needs to run is the Timer1 to trigger the interrupt, but that can only happen if the secondary oscillator is running. If there's no way to use SLEEP mode while keeping the secondary oscillator running, then I should probably use the SEC_IDLE mode... hopefully the peripherals don't drain that much power.
Bookmarks