PIC18F2431 Running Super SLow!!


Closed Thread
Results 1 to 5 of 5
  1. #1
    Philip Biebach's Avatar
    Philip Biebach Guest

    Unhappy PIC18F2431 Running Super SLow!!

    Basicly I have a Pic18F2431 Setup connected to 3 LEDs, I wrote a really simple program that should simple flash the LEDs. At First I thought that the Pic had simple locked up and wasent executing any code but after letting it sit For a few mins i noticed it had switched to the nexts sequence of LEDs, After observing it over several tens of minutes i now discouvered that it does what the code tells it to but at a super slow rate.


    the 3 LEDs are On PORTA.0, PORTA.1, PORTA.2

    ;Setup procedures
    @ __CONFIG _CONFIG1H, _OSC_IRCIO_1H
    @ __CONFIG _CONFIG3H, _MCLRE_OFF_3H

    DEFINE OSC 8
    ANSEL0 = %00000000
    TRISA = %11110000
    TRISB = %10110011
    TRISC = %11110000

    PORTA = %00000000
    PORTB = %00000000
    PORTC = %00000000

    ;Pin assignments
    Symbol LED1 = PORTA.0
    Symbol LED2 = PORTA.1
    Symbol LED3 = PORTA.2

    main:

    LED1 = 0
    LED2 = 1
    LED3 = 1
    pause 500
    LED1 = 1
    LED2 = 0
    LED3 = 0
    pause 500

    goto main

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


    Did you find this post helpful? Yes | No

    Default

    Datasheet!!! Page 28, Section 2-2 OSCCON Register... I don't see you setting it for 8MHz...

    OSCCON=%01110010

    Try adding the above before your TRIS statements...

    For frequency critical applications, I'd also follow that with...

    WHILE OSCCON.2=0:WEND

    This ensures that program continuation is halted until the Oscillator is stable...

  3. #3
    Philip Biebach's Avatar
    Philip Biebach Guest


    Did you find this post helpful? Yes | No

    Thumbs up Problem Solved

    Thanks Melanie, it must have been defaulting to 31Khz or something

    and i did check the datasheet(many times) just the wrong places, i was somehow convinced it had something to do with the AD Converters

    thanks again

  4. #4
    Join Date
    Oct 2003
    Location
    Australia
    Posts
    257


    Did you find this post helpful? Yes | No

    Default

    Mel,

    I've the reverse problem. Couple of questions if you don't mind:

    I want to toggle the LED once a second running at a clock freq of 31.25kHz is this possible?

    If I set the OSCCON to a freq of 2MHz (or lower), and I set DEFINE OSC 2 (or lower), my code wont compile?

    Do you need to DEFINE OSC "speed" when using OSCCON? It seems that I do, eg the toggling LED seems to double in speed if I don't DEFINE the oscillator speed.

    Heres my code.


    ' FLICK LED ON/OFF EVERY SECOND

    ' =============
    ' PRESET FUSES
    ' =============
    @ DEVICE pic16F88, INTRC_OSC
    @ DEVICE pic16F88, WDT_ON
    @ DEVICE pic16F88, BOD_ON
    @ DEVICE pic16F88, PROTECT_ON
    @ DEVICE pic16F88, MCLR_ON
    @ DEVICE pic16F88, WDT_ON
    @ DEVICE pic16F88, CPD_OFF
    @ DEVICE pic16F88, LVP_OFF
    @ DEVICE pic16F88, CCPMX_OFF
    @ DEVICE pic16F88, DEBUG_OFF
    @ DEVICE pic16F88, PWRT_ON

    ' 000 = 31.25 kHz
    ' 001 = 125 kHz
    ' 010 = 250 kHz
    ' 011 = 500 kHz
    ' 100 = 1 MHz
    ' 101 = 2 MHz
    ' 110 = 4 MHz
    ' 111 = 8 MHz

    OSCCON = %01010010 ' 2MHz
    'DEFINE OSC 2 ' this line causes problems
    LED1 var PortB.0
    TRISB=%11111110

    LOOP:
    TOGGLE LED1
    PAUSE 1000
    WHILE OSCCON.2=0: WEND

    GOTO LOOP


    <b>My ultimate goal is to have a slow HPWM (around 1.7kHz) running at a slow clock speed.</b> Is this the right way to do it?
    --------
    Cheers
    Squib

  5. #5
    Join Date
    Sep 2004
    Location
    montreal, canada
    Posts
    6,898


    Did you find this post helpful? Yes | No

    Default

    It's just because 2MHZ is not supported by PBP.

    to have a PAUSE 1000 @ 2MHZ you need to DEFINE OSC 4 and a PAUSE 500. Same for HPWM, to have 1.7KHZ @ 2MHZ multiply your frequency by two @4MHZ.

    At 32...KHZ... from what i feel, you'll need to set the register manually and i can't tell if it's going to work. Just use the formula in the datasheet.
    Steve

    It's not a bug, it's a random feature.
    There's no problem, only learning opportunities.

Similar Threads

  1. Multi Slow speed PWM and Instant Interrupts
    By DaveC3 in forum mel PIC BASIC Pro
    Replies: 8
    Last Post: - 2nd November 2010, 12:50
  2. DT Interrupt and Elapsed Time Running Slow
    By ShaneMichael in forum mel PIC BASIC Pro
    Replies: 9
    Last Post: - 11th May 2009, 18:00
  3. Code Executing Slow
    By Frozen001 in forum mel PIC BASIC Pro
    Replies: 5
    Last Post: - 5th September 2008, 21:09
  4. DT's Slow PWM
    By fbraun in forum mel PIC BASIC Pro
    Replies: 0
    Last Post: - 27th June 2008, 15:50
  5. I’m Running Out of CodeSpace, What Can I Do?
    By Melanie in forum FAQ - Frequently Asked Questions
    Replies: 0
    Last Post: - 12th July 2004, 19:25

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