Yep will do!
I have setup the secondary oscillator with a 32k XTal. That way it will give me the time accuracy I need and I can clock the CPU using that source. I have yet to finish the main routine and get everything to work before implementing the power conservation tricks.... and that USB communication deal to figure out.
It was time to pack things down, I must say that it is not easy to drill vias using a 0.3mm drillbit and sticking a tiny copper wire in it to make the connexion!
Not much progress on the programming yet due to lack of free time, but will work on that soon.
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:
Then I have my main standalone operation loop. The only code executing are triggered by INT0 and TMR1 using DT_INTS-18.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
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:StandAloneLoop: @ SLEEP GOTO StandAloneLoop
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 saysCode:OSCCON.7 = 0 'Device enters in SLEEP mode when sleep instruction issuedHowever 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.This shuts down the selected oscillator and all clock source status bits are cleared.
If you put a crystal on the Timer1 oscillator, enable T1OSCEN and change TMR1CS before going to sleep with an appropriate reload value for the lower frequency ... you could put it to sleep.
DT
Hmm I don't really understand, I have this at the beginning of my code during initialization:
T1OSCEN = 1 (secondary 32768Hz oscillator is enabled)Code:T1CON = %01101011 'Set Timer prescaler to /4 and enable Timer1 on external 32768Hz crystal
TMR1CS = 1 (timer clock source is secondary 32768Hz oscillator)
My setup already use the Timer1 for both interrupt and general clock source when in low power mode, and it does work as expected.
I tried to add that T1CON configuration line above my @ SLEEP instruction but that didn't help much. If the SLEEP mode actually turn off all clocking sources then T1OSCEN bit should be set to 0 as well.
Maybe using the IDLE mode and manually disable all peripherals that are enabled default would be a workaround.
Timer1 oscillator continues to run during sleep mode, but ... try it like this.
First, comment all the OSCCON and OSCTUNE statements you showed above.
Then ...
Code:StandAloneLoop: ASM SLEEP NOP NOP ENDASM GOTO StandAloneLoop
DT
Bookmarks