Continue to Site

Welcome to our site!

Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

  • Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

Problems with internal oscillator [PIC12F675]

Status
Not open for further replies.

joseflor

New Member
See code below for this thread...

When I simulate with MPLAM SIM the OSCCAL gets value 0 (zero) You can see that on the image attached. If you look the code, I have defined the calibration and use a RETLW 0xFC.

Also when I simulate with Proteus I get this message: "[PIC12 MEMORY] PC=0c000B. Effect of writing OSCCAL register not modelled"

Did I write the wrong code? What would be the problem with that?

Thanks
PS. Proteus file is attached in a zip file, if you need to see it.


;----------------------------------------------------------------------
; NAME: telefonica.asm
; BY: José Flor - OzFlor
; WEB: **broken link removed**
;----------------------------------------------------------------------
; previous ver. 1.0 27/01/2010 > fixed delay for 1.5s
; ver. 1.1 30/01/2010 > changable delay in .5s increments

list p=12f675 ; Directivas do processador
#include <p12f675.inc> ; Vaiáveis do processador

;----------------------------------------------------------------------
; Configurações
__CONFIG _INTRC_OSC_NOCLKOUT & _WDT_OFF & _PWRTE_ON & _MCLRE_OFF & _CP_OFF & _CPD_OFF
;----------------------------------------------------------------------

;----------------------------------------------------------------------
; Definir constantes
;----------------------------------------------------------------------
#define led0 GPIO,0 ; LED 1
#define led1 GPIO,1 ; LED 2
#define entrada0 GPIO,4 ; Entrada 1
#define entrada1 GPIO,5 ; Entrada 2

;----------------------------------------------------------------------
; Declarações
;----------------------------------------------------------------------
PDel0 equ 0x020
PDel1 equ 0x021
delay_acerto equ 0x022



BCF STATUS,RP0 ;Bank 0
CLRF GPIO ;Init GPIO
MOVLW 07h ;Set GP<2:0> to
MOVWF CMCON ;digital IO
BSF STATUS,RP0 ;Bank 1
CLRF ANSEL ;Digital I/O
MOVLW 30h ;b'110000' Set GP 5 and 4 as inputs and set GP 3 to 0 as outputs
MOVWF TRISIO

; Calibrar oscilador interno de 4MHz; Calibrar oscilador interno
BSF STATUS, RP0 ;Bank 1
CALL 3FFh ;Get the cal value
MOVWF OSCCAL ;Calibrate
BCF STATUS, RP0 ;Bank 0

start
btfss entrada0
call acende_led1
btfss entrada1
call acende_led2
goto start

acende_led1
bsf led0
call delay
bcf led0
retesta_entrada0 ;verifica se a entrada 0 já mudou de estado
btfss entrada0
goto retesta_entrada0
goto start


acende_led2
bsf led1
call delay
bcf led1
retesta_entrada1 ;verifica se a entrada 1 já mudou de estado
btfss entrada1
goto retesta_entrada1

return




delay
movlw 0x03 ;repete três (0x03) vezes o delay
movwf delay_acerto ;para acerto do número de 0,5s
repete ;altere o número de vezes que deseja repetir o ciclo de 0,5s
decfsz delay_acerto ;para obter o tempo de deday que retende
goto PDelay ;isto é usar 0x01, 0x02, etc.
return
;delay de 0,5 segundos - 500.000 ciclos CLK 4MHz
;-------------------------------------------------------------
; Code generated by PDEL ver 1.0 on 30/01/2010 at 9:16:10 PM
; Description: Waits 500000 cycles
;-------------------------------------------------------------
PDelay movlw .239 ; 1 set number of repetitions (B)
movwf PDel0 ; 1 |
PLoop1 movlw .232 ; 1 set number of repetitions (A)
movwf PDel1 ; 1 |
PLoop2 clrwdt ; 1 clear watchdog
PDelL1 goto PDelL2 ; 2 cycles delay
PDelL2 goto PDelL3 ; 2 cycles delay
PDelL3 clrwdt ; 1 cycle delay
decfsz PDel1, 1 ; 1 + (1) is the time over? (A)
goto PLoop2 ; 2 no, loop
decfsz PDel0, 1 ; 1 + (1) is the time over? (B)
goto PLoop1 ; 2 no, loop
PDelL4 goto PDelL5 ; 2 cycles delay
PDelL5 goto PDelL6 ; 2 cycles delay
PDelL6 goto PDelL7 ; 2 cycles delay
PDelL7 clrwdt ; 1 cycle delay
goto repete ; 2+2 Done
;-------------------------------------------------------------

; calibrarção do oscilador interno
org 3FFh
retlw 0xFC ;valor máximo do oscilador para 4MHz

end
 

Attachments

  • int_osc.JPG
    int_osc.JPG
    173.1 KB · Views: 290
  • telefonica.zip
    14.7 KB · Views: 147
MPLAB sim and proteus don't model the effect OSCCAL has on the operation. It will therefore work differently when physically implemented.
 
I had a problem with a lookup table (bunch of retlw) that extended to the end of the memory (say 0x3ff) in MPLAB SIM - it didn't return but instead the PC rolled over to 0 and started the program again. If the retlw 0xFC is in your .hex file, I'd just ignore the sim problems.
 
hi jose,
The OSCCAL load operation works ok in the Oshonsoft sim.

Look at this image, after stepping thru the OSCCAL statement.

AAesp01.gif
 
Status
Not open for further replies.

Latest threads

New Articles From Microcontroller Tips

Back
Top