Autor Tema: C18 configurar osc  (Leído 2369 veces)

0 Usuarios y 1 Visitante están viendo este tema.

Desconectado c4_esp_VR

  • Colaborador
  • PIC24F
  • *****
  • Mensajes: 735
    • www.muchotrasto.com
C18 configurar osc
« en: 05 de Diciembre de 2011, 04:30:53 »
Hola compañeros,

Me estoy desenganchando del CCS  :D :D :D...es como una droga...y estoy metiendome con el C18...pero no puedo configurar el oscilador...le he puesto al HW un cristal a 25MHz a un PIC y no sé como configurarlo en C18...¿alguna idea please?

Cuando ejecuto desde linea de comandos la siguiente sentencia,

Código: [Seleccionar]
mcc18 --help-config -p=18f97j60
Aparece las siguientes opciones de configuración de bits

Código: [Seleccionar]
Configuration settings available for processor 18F97J60
  Background Debugger Enable bit:
    DEBUG = ON          Background debugger enabled; RB6 and RB7 are dedicated t
o In-Circuit Debug
    DEBUG = OFF         Background debugger disabled; RB6 and RB7 configured as
general purpose I/O pins

  Extended Instruction Set Enable bit:
    XINST = OFF         Instruction set extension and Indexed Addressing mode di
sabled (Legacy mode)
    XINST = ON          Instruction set extension and Indexed Addressing mode en
abled

  Stack Overflow/Underflow Reset Enable bit:
    STVR = OFF          Reset on stack overflow/underflow disabled
    STVR = ON           Reset on stack overflow/underflow enabled

  Watchdog Timer Enable bit:
    WDT = OFF           WDT disabled (control is placed on SWDTEN bit)
    WDT = ON            WDT enabled

  Code Protection bit:
    CP0 = ON            Program memory is code-protected
    CP0 = OFF           Program memory is not code-protected

  Fail-Safe Clock Monitor Enable bit:
    FCMEN = OFF         Fail-Safe Clock Monitor disabled
    FCMEN = ON          Fail-Safe Clock Monitor enabled

  Two-Speed Start-up (Internal/External Oscillator Switchover) Control bit:
    IESO = OFF          Two-Speed Start-up disabled
    IESO = ON           Two-Speed Start-up enabled

  Default/Reset System Clock Select bit:
    FOSC2 = OFF         INTRC enabled as system clock when OSCCON<1:0> = 00
    FOSC2 = ON          Clock selected by FOSC1:FOSC0 as system clock is enabled
 when OSCCON<1:0> = 00

  Oscillator Selection bits:
    FOSC = HS           HS oscillator
    FOSC = HSPLL        HS oscillator, PLL enabled and under software control
    FOSC = EC           EC oscillator, CLKO function on OSC2
    FOSC = ECPLL        EC oscillator, PLL enabled and under software control, C
LKO function on OSC2

  Watchdog Timer Postscale Select bits:
    WDTPS = 1           1:1
    WDTPS = 2           1:2
    WDTPS = 4           1:4
    WDTPS = 8           1:8
    WDTPS = 16          1:16
    WDTPS = 32          1:32
    WDTPS = 64          1:64
    WDTPS = 128         1:128
    WDTPS = 256         1:256
    WDTPS = 512         1:512
    WDTPS = 1024        1:1024
    WDTPS = 2048        1:2048
    WDTPS = 4096        1:4096
    WDTPS = 8192        1:8192
    WDTPS = 16384       1:16384
    WDTPS = 32768       1:32768

  External Bus Wait Enable bit:
    WAIT = ON           Wait states for operations on external memory bus enable
d and selected by MEMCON<5:4>
    WAIT = OFF          Wait states for operations on external memory bus disabl
ed

  Data Bus Width Select bit:
    BW = 8              8-Bit Data Width mode
    BW = 16             16-Bit Data Width mode

  External Memory Bus Configuration bits:
    MODE = XM20         Extended Microcontroller mode, 20-Bit Address mode
    MODE = XM16         Extended Microcontroller mode,16-Bit Address mode
    MODE = XM12         Extended Microcontroller mode,12-Bit Address mode
    MODE = MM           Microcontroller mode, external bus disabled

  External Address Bus Shift Enable bit:
    EASHFT = OFF        Address shifting disabled; address on external bus refle
cts the PC value
    EASHFT = ON         Address shifting enabled; address on external bus is off
set to start at 000000h

  Ethernet LED Enable bit:
    ETHLED = OFF        RA0/RA1 function as I/O regardless of Ethernet module st
atus
    ETHLED = ON         RA0/RA1 are multiplexed with LEDA/LEDB when Ethernet mod
ule is enabled and function as I/O when Ethernet is disabled

  ECCP MUX bit:
    ECCPMX = OFF        ECCP1 outputs (P1B/P1C) are multiplexed with RH7 and RH6
; ECCP3 outputs (P3B/P3C) are multiplexed with RH5 and RH4
    ECCPMX = ON         ECCP1 outputs (P1B/P1C) are multiplexed with RE6 and RE5
; ECCP3 outputs (P3B/P3C) are multiplexed with RE4 and RE3

  ECCP2 MUX bit:
    CCP2MX = OFF        ECCP2/P2A is multiplexed with RE7 in Microcontroller mod
e (80-pin and 100-pin devices) or with RB3 in Extended Microcontroller mode (100
-pin devices only)
    CCP2MX = ON         ECCP2/P2A is multiplexed with RC1

Por otro lado, el código fuente es muy sencillo,

Código: [Seleccionar]
#include <p18f97j60.h>

#include <delays.h>
#include <stdlib.h>
#include <usart.h>

#pragma config FOSC=HS, WDT=OFF, DEBUG=ON

void main (void)
{
Open1USART(USART_TX_INT_OFF & USART_RX_INT_ON & USART_ASYNCH_MODE & USART_EIGHT_BIT & USART_CONT_RX & USART_BRGH_HIGH, 25);//9600,8,n,1
RCONbits.IPEN=0;//Deshabilitamos prioridades
INTCONbits.PEIE=1; //Habilitamos interrupción de periféricos
INTCONbits.GIE=1; //Habilitamos interrupcion global

while(1)
{
putc1USART("Prueba \r\n");
}
}

Como siemrpe, mil gracias.
« Última modificación: 05 de Diciembre de 2011, 04:51:52 por c4_esp_VR »

Desconectado c4_esp_VR

  • Colaborador
  • PIC24F
  • *****
  • Mensajes: 735
    • www.muchotrasto.com
Re: C18 configurar osc
« Respuesta #1 en: 05 de Diciembre de 2011, 09:09:39 »
Hola compañeros,

Resulta que creia que tenía que bajar el oscilador, pero veo que este pic al usar ethernet está configurado con un cristal de 25MHz, con lo que poniendo:

Código: [Seleccionar]
#pragma config FOSC=HS

Ya se programa para 25Mhz, aunque aún así para futuro, si alguien sabe como se divide el clk en C18 sería de agradecer.

Un saludo y gracias.

Desconectado MerLiNz

  • Colaborador
  • PIC24H
  • *****
  • Mensajes: 2463
Re: C18 configurar osc
« Respuesta #2 en: 05 de Diciembre de 2011, 09:44:17 »
digamos que la velocidad no se configura poniendo clock=100000 como haces en el CCS, el clock lo utiliza para el delay y poco mas, sin embargo aunque le pongas un cristal de 20mhz y pongas clock=5000000 no iras a 5mhz, iras a lo vaya el cristal.

Luego, a parte de eso existen modulos PLL que incluyen los pics para multiplicar la frecuencia, asi con un cristal de 4mhz conseguir 60mhz por poner un ejemplo.

Lo unico que debes es mirar el datasheet de tu pic y seguir las opciones de los registros para llegar a la frecuencia deseada, lo mismo puedes cambiar la frecuencia de trabajo distinta a la de ethernet jugando con los registros. Para cambiar los registros debes mirar el datasheet porque algunos registros pueden necesitar desbloqueos y en el datasheet te dice como hacerlo.