The Godfather talking
You think I am funny guy huh?
Sonsivri
 
*
Welcome, Guest. Please login or register.
Did you miss your activation email?
July 19, 2025, 10:38:05 22:38


Login with username, password and session length


Pages: [1]
Print
Author Topic: Calibrate PIC12 with PC RS-232  (Read 4231 times)
0 Members and 1 Guest are viewing this topic.
JADT
Guest
« on: January 05, 2008, 04:27:31 16:27 »

Dear all,

I'll post two samples that I used to calibrate the PIC12F675 & PIC13F683, which comes in quite handy.

The basic idea is that you use an terminal program for example "Hyper Terminal' to send a capital U (I'll still explain...) then you count the "Time Period" of the low bit, using that count one can adjust the oscilator value. It made my calibration job quite a bit easier...

Posted on: January 05, 2008, 05:23:12 17:23 - Automerged

Here is the sample code for the PIC12F675:

' Tune_OSC Vars
OSCCAL_Value    VAR BYTE
OSCCAL_OldValue VAR BYTE
bCount          VAR BYTE
bRepeat         VAR BYTE
bOSCToFast      Var BIT
bThrsHold       CON 27

Tune_OSC:
' Use 'U' to Calibrate PIC...
  bCount = 0
  bRepeat = 0
  OSCCAL_OldValue = OSCCAL_Value

Repeat_Tune:
ASM
IsS  BTFSC GPIO, 3
     GOTO IsS
IsC  BTFSS GPIO, 3
     GOTO IsC
Cnt  INCF _bCount, 1
     BTFSC GPIO, 3
     GOTO Cnt
ENDASM

  'Make bCount = ABS(Diff from ThrsHold)
  IF bCount > bThrsHold THEN
    ' To Fast
    bCount = bCount - bThrsHold
    bOSCToFast = 1
  ELSE
    ' To Slow
    bCount = bThrsHold - bCount
    bOSCToFast = 0
  ENDIF

  IF bCount <> 0 THEN           
    ' +-4 because OSCCAL = Bit2 to Bit7 ==> 4 = 100 (Bit0 & Bit1 is not used)...
    IF bOSCToFast = 1 THEN
      OSCCAL_Value = OSCCAL_Value - 4
    ELSE
      OSCCAL_Value = OSCCAL_Value + 4
    ENDIF
    OSCCAL = OSCCAL_Value
    GOSUB qflash_LED  ' Flash LED quick
    GOTO Repeat_Tune
  ENDIF
 
  GOSUB qflash_LED ' Flash LED quick

  bRepeat = bRepeat + 1
  IF bRepeat < 25 THEN Repeat_Tune

  ' Save OSC value to EEPROM
  IF OSCCAL_Value <> OSCCAL_OldValue THEN
    WRITE 127, OSCCAL_Value
  ENDIF

  ' LED Constant ON
  LED = 1
STOP
Logged
Pages: [1]
Print
Jump to:  


DISCLAIMER
WE DONT HOST ANY ILLEGAL FILES ON THE SERVER
USE CONTACT US TO REPORT ILLEGAL FILES
ADMINISTRATORS CANNOT BE HELD RESPONSIBLE FOR USERS POSTS AND LINKS

... Copyright © 2003-2999 Sonsivri.to ...
Powered by SMF 1.1.18 | SMF © 2006-2009, Simple Machines LLC | HarzeM Dilber MC