18F2420, instant interrupts, and TMR0


Closed Thread
Results 1 to 8 of 8
  1. #1
    Join Date
    Feb 2008
    Posts
    8

    Unhappy 18F2420, instant interrupts, and TMR0

    i've been working with Darryl's instant interrupts for PWM LED's and they work great! now i'm moving over to work directly with timers with a new-to-me PIC and have hit a wall.

    i've reduced my code down to what i think are the bare essentials and i still don't have blinky. here's the code that compiles:

    @ __CONFIG _CONFIG1H, _OSC_INTIO67_1H
    @ __CONFIG _CONFIG2L, _PWRT_ON_2L & _BOREN_OFF_2L
    @ __CONFIG _CONFIG2H, _WDT_OFF_2H
    @ __CONFIG _CONFIG3H, _MCLRE_ON_3H
    @ __CONFIG _CONFIG4L, _LVP_OFF_4L & _DEBUG_OFF_4L

    define OSC 8
    clear

    CCP1CON=0 'turn off capture and compare module 1
    CCP2CON=0 'turn off capture and compare module 2
    SSPCON1.5=0 'disables SPI and I2C modules on portC
    ADCON1=%00001111 'turns all AD pins to digital and tells module to use Vdd and Vss
    ADCON0.0=0 'disables AD module
    CMCON.0=0 'disables comparator module for portA
    CMCON.1=0 '(ditto)
    CMCON.2=0 '(ditto)
    CVRCON.7=0 'disables comparator voltage reference module for portA

    TRISB=%11101111 'PortB.4 => HB LED pin set to output

    LED1 VAR PORTB.4
    loop var byte

    INCLUDE "DT_INTS-18.bas" ' Base Interrupt System
    INCLUDE "ReEnterPBP-18.bas" ' Include if using PBP interrupts

    'lets me know the PIC is doing something after programming
    for loop=1 to 4
    toggle led1
    pause 50
    next loop

    ;-----------------------------------------------------------------------------
    ASM
    INT_LIST macro ; IntSource, Label, Type, ResetFlag?
    INT_Handler TMR0_INT, _ToggleLED1, PBP, yes
    endm
    INT_CREATE ; Creates the interrupt processor
    ENDASM
    ;-----------------------------------------------------------------------------
    T0CON=%10011000 ; TMR0ON, 16-bit, internal clock, high>low, no prescaler
    @ INT_ENABLE TMR0_INT ; enable Timer 0 interrupts
    ;-----------------------------------------------------------------------------
    Main:
    PAUSE 1
    GOTO Main
    '---[TMR1 - interrupt handler]--------------------------------------------------
    ToggleLED1:
    TOGGLE LED1
    @ INT_RETURN


    i've read read read the datasheet and have done many, many searches on this forum to try and find the small thing i'm missing. this is why i'm finally posting here for assistance.
    Last edited by dhickman; - 11th February 2009 at 22:54.

  2. #2
    Join Date
    Jul 2003
    Posts
    2,405


    Did you find this post helpful? Yes | No

    Default

    Change your last config line to;
    @ __CONFIG _CONFIG4L, _LVP_OFF_4L & _DEBUG_OFF_4L & _XINST_OFF_4L

    You'll also want to write to OSCCON since it does not default to 8MHz.
    Regards,

    -Bruce
    tech at rentron.com
    http://www.rentron.com

  3. #3
    Join Date
    Feb 2008
    Posts
    8


    Did you find this post helpful? Yes | No

    Smile working - but now i want x4 PLL

    Bruce,

    thanks loads! your correction worked. i didn't know what that fuse did but now i guess i can see the results.

    what about utilizing the x4 PLL feature with the internal osc? i've tried setting OSCTUNE.6=1 but i don't see a difference.

    am i supposed to tell PBP that i'm now 32MHz with the DEFINE OSC 32 statement instead of DEFINE OSC 8?

    thanks again!

    -=drew

  4. #4
    Join Date
    Jul 2003
    Posts
    2,405


    Did you find this post helpful? Yes | No

    Default

    _XINST_OFF_4L disables extended instruction set, which you'll always want disabled on any 18F part that has it when using PBP.

    The unprogrammed default for this bit is ON unless you disable it as shown above.

    Hint: Look in your default PBP header file for what they show there.

    Yes. If the PIC is operating at 32MHz, then you'll want to define it just like you would for any osc speed.

    Write the value 'shown in your datasheet' to OSCCON to set it for 8MHz. Then flip the bit in OSCTUNE to enable PLL. It should then be running at 32MHz.
    Regards,

    -Bruce
    tech at rentron.com
    http://www.rentron.com

  5. #5
    Join Date
    Feb 2008
    Posts
    8


    Did you find this post helpful? Yes | No

    Default

    Bruce,

    i tried setting the OSCCON value and the OSCTUNE bit as well but i'm not getting the higher speed. here's my test code:

    'use the following when using the MPASM assembler
    @ __CONFIG _CONFIG1H, _OSC_INTIO67_1H
    @ __CONFIG _CONFIG2L, _PWRT_ON_2L & _BOREN_OFF_2L
    @ __CONFIG _CONFIG2H, _WDT_OFF_2H
    @ __CONFIG _CONFIG3H, _MCLRE_ON_3H
    @ __CONFIG _CONFIG4L, _LVP_OFF_4L & _DEBUG_OFF_4L & _XINST_OFF_4L
    @ __CONFIG _CONFIG5L, _CP0_ON_5L & _CP1_ON_5L

    DEFINE OSC 32
    clear

    OSCCON=%11111110 'SLEEP mode, 8MHz internal osc, no startup but use primary, primary has stablized, select internal osc block
    OSCTUNE.6=1 'enables PLL 4x speed multipler for the internal OSC
    ADCON1=%00001111 'turns all AD pins to digital and tells module to use Vdd and Vss
    ADCON0.0=0 'disables AD module

    TRISB=%00000000 'PortB.4 => Heartbeat LED pin set to output

    HBLED var PORTB.4 'alias for heartbeat LED

    ;------------------------------------------------------------------------
    Main:
    toggle hbled
    pause 500
    GOTO Main
    ;------------------------------------------------------------------------


    when i use DEFINE OSC 8 the LED flashes as expected. when use DEFINE OSC 32 it flashes slowly which leads me to think i've not successfully activated the x4 PLL.

    -=drew

  6. #6
    Join Date
    Jul 2003
    Posts
    2,405


    Did you find this post helpful? Yes | No

    Default

    Hi Drew,

    Try changing OSCCON=%11111110 to OSCCON=%11111100. The internal osc is the primary
    osc in this configuration since you have it set in your config option. I.E. the intrnal osc is
    now considered the primary oscillator.

    If you had your config osc setting set for an external osc, then you could switch between
    the primary (external osc) & internal osc by setting SCS.1.

    Also note that OSCCON bits 2 & 3 are read only, so attempting to write to these bits is not
    needed, and, of course, doesn't really change a bit. These bits are read-only and pretty
    much just for you to read to determin the oscillator status.

    Only registers that show R/W-x are readable/writeable. The x just signifies the default
    value of the register bit at POR.
    Regards,

    -Bruce
    tech at rentron.com
    http://www.rentron.com

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


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by Bruce View Post
    Try changing OSCCON=%11111110 to OSCCON=%11111100. The internal osc is the primary osc in this configuration since you have it set in your config option. I.E. the intrnal osc is now considered the primary oscillator.
    WOW!

    I'd searched, and re-searched and could not find a reason.

    But looking at FIGURE 2-8 (Clock diagram)
    I can totally see how that makes a difference.

    Nice Bruce!
    DT

  8. #8
    Join Date
    Feb 2008
    Posts
    8


    Did you find this post helpful? Yes | No

    Smile it now works!

    reading the OSCCON configuration was indeed a bit (pardon the pun) confusing because i thought i was selecting the internal osc by setting osccon.1 and osccon.0 to 1x. thanks for straightening me out. i've tested it and it does indeed work.

    thanks again everyone (especially Bruce)!

    now i'm running 32Mhz off of an internal osc. that's awesome!

    -=drew

Similar Threads

  1. Instant Interrupts - Revisited
    By Darrel Taylor in forum Code Examples
    Replies: 772
    Last Post: - 17th February 2016, 22:14
  2. Timer0 Instant Interrupts Question
    By wmarchewka in forum mel PIC BASIC Pro
    Replies: 1
    Last Post: - 14th December 2009, 05:29
  3. COUNT is not counting again
    By jellis00 in forum mel PIC BASIC Pro
    Replies: 33
    Last Post: - 19th June 2009, 04:52
  4. 16F946 Instant Interrupts problem
    By jderson in forum mel PIC BASIC Pro
    Replies: 3
    Last Post: - 14th April 2009, 22:20
  5. help: TMR0 interrupts disabling PORTAchange interrupts???
    By xnihilo in forum mel PIC BASIC Pro
    Replies: 4
    Last Post: - 19th August 2008, 15:10

Members who have read this thread : 1

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

Posting Permissions

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