PIC18F13K50, CDC USB communication and ultra-low power temperature logger


Closed Thread
Results 1 to 28 of 28

Hybrid View

  1. #1
    Join Date
    Dec 2007
    Location
    Paris
    Posts
    101

    Default

    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.

  2. #2
    Join Date
    Dec 2007
    Location
    Paris
    Posts
    101

    Default

    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.

  3. #3
    Join Date
    Jul 2003
    Location
    Colorado Springs
    Posts
    4,959

    Default

    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

  4. #4
    Join Date
    Dec 2007
    Location
    Paris
    Posts
    101

    Default

    Hmm I don't really understand, I have this at the beginning of my code during initialization:

    Code:
    T1CON = %01101011 'Set Timer prescaler to /4 and enable Timer1 on external 32768Hz crystal
    T1OSCEN = 1 (secondary 32768Hz oscillator is enabled)
    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.

  5. #5
    Join Date
    Jul 2003
    Location
    Colorado Springs
    Posts
    4,959

    Default

    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

  6. #6
    Join Date
    Dec 2007
    Location
    Paris
    Posts
    101

    Default

    Tried this step by step.

    Commenting either or all of these:

    Code:
    OSCCON.1 = 0
    OSCCON.0 = 1 'Use Timer1 oscillator as clock source
    OSCCON.7 = 1 'Device enters in IDLE mode when sleep instruction issued
    stop operation. However I'm not sure if it's because the interrupt is not triggered anymore or if that's because the CPU does not come back from sleep. I remember reading that Timer1 oscillator was always running, but looking carefully at the datasheet again I cannot find that statement back. Only mention is that SLEEP (not IDLE) mode turn off all clocks and all oscillators, expect for the WDT oscillator (if enabled).

  7. #7
    Join Date
    Jul 2003
    Location
    Colorado Springs
    Posts
    4,959

    Default



    And you had more statements than those 3.
    One of them disables the Primary Oscillator, which will keep it from running after it wakes up I would assume.
    Attached Images Attached Images  
    DT

Members who have read this thread : 0

You do not have permission to view the list of names.

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts