CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to CCS Technical Support

How to set the calibration value for PIC10F22x

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
Goodwinchang



Joined: 15 Oct 2006
Posts: 18
Location: Taiwan

View user's profile Send private message MSN Messenger

How to set the calibration value for PIC10F22x
PostPosted: Thu Jul 26, 2007 9:18 pm     Reply with quote

as the tiltle. And another problem is for PIC10F222 the function setup_adc(ADC_ON). It will cause the Compiler error.

Please help.

Goodwin
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Fri Jul 27, 2007 1:49 pm     Reply with quote

What's your compiler version ?
The setup_adc(ADC_ON) function compiles OK with vs. 3.249.

With regard to the oscillator calibration, the 10F222 data sheet says:
Quote:
In addition, a calibration instruction is programmed into
the last address of memory, which contains the calibration
value for the internal oscillator. This location is
always uncode protected, regardless of the code-pro-tect
settings. This value is programmed as a MOVLW XX
instruction where XX is the calibration value and is
placed at the Reset vector. This will load the W register
with the calibration value upon Reset and the PC will
then roll over to the users program at address 0x000.
The user then has the option of writing the value to the
OSCCAL Register (05h) or ignoring it.

CCS does this. At address 0x0000, it puts this line of code:
Code:
0000:  MOVWF  05

Register 05 is the OSCCAL register. It's putting the calbration value
(in the W register) into it. This is in the .LST file for vs. 3.249.
spradecom.rnd



Joined: 27 Apr 2010
Posts: 16
Location: Mumbai

View user's profile Send private message Send e-mail Visit poster's website

PostPosted: Wed Apr 28, 2010 3:16 am     Reply with quote

I am using version 4.84. what is the solution for the setup_adc(ADC_ON);
I have tried setup_adc(true); but the adc value always remains 255 or max even if input is zero
Ttelmah



Joined: 11 Mar 2010
Posts: 19504

View user's profile Send private message

PostPosted: Wed Apr 28, 2010 7:18 am     Reply with quote

Just add the define for ADC_ON.
For some reason these were missing from the V4 compilers up to somewhere around 4.09x.
#define ADC_ON (1)
Somewhere before you use the setup_adc function.
Seriously though, the values appearing, marked the point where CCS at long last got the compiler working with the chip. You will probably find it is not programming the pins properly as analog inputs, which is why it doesn't work with 'TRUE'....

Best Wishes
spradecom.rnd



Joined: 27 Apr 2010
Posts: 16
Location: Mumbai

View user's profile Send private message Send e-mail Visit poster's website

PostPosted: Wed Apr 28, 2010 8:45 am     Reply with quote

I have upgraded to version 4.104. The adc_on definition is present in the header. But after loading the program the adc value always remains high. MCLR pin always high, ICSPCLK pin always high. AN0 low. GP2 98%duty cycle. ADC val max. Here is the code. Generating sw PWM by reading analog inputs. This code works well with pic12f675
Code:

#include <10F222.h>
#device adc=8

#FUSES NOWDT                    //No Watch Dog Timer
#FUSES NOMCLR                   //Master Clear pin used for I/O
#FUSES NOPROTECT                //Code not protected from reading
#FUSES NOMCPU                   //Master Clear Pull-up disabled
#FUSES IOSC4                    //INTOSC speed 4 MHz
#FUSES RESERVED                 //Used to set the reserved FUSE bits

#use delay(clock=4000000)

void main()
{

   setup_adc_ports(sAN0);
   setup_adc(ADC_CLOCK_DIV_4);
   setup_timer_0(RTCC_INTERNAL|RTCC_DIV_1);

   // TODO: USER CODE!!
       
           while(true)
     {

               set_adc_channel(0);
                   delay_ms(10);
              value = Read_ADC();
               //delay_ms(10);
               output_high(PIN_B2);
              delay_ms(value);
              output_low(PIN_B2);
              delay_ms(255-value);
     }

}
Ttelmah



Joined: 11 Mar 2010
Posts: 19504

View user's profile Send private message

PostPosted: Wed Apr 28, 2010 2:40 pm     Reply with quote

You comment 'MCLR is always high'. This says there is something wrong with your circuit, or the programming.
On this CCS version, the pull-up disable is correctly set when asked for (as shown), and except for this, the MCLR pin is an _input_ there is no circuitry except the pull-up, to take it high. If it is being pulled high, it implies that either your circuit is doing this, or that the programmer you are using, is not correctly setting the configuration bits. Either then could explain why the code doesn't work...

Best Wishes
spradecom.rnd



Joined: 27 Apr 2010
Posts: 16
Location: Mumbai

View user's profile Send private message Send e-mail Visit poster's website

PostPosted: Thu Apr 29, 2010 3:13 am     Reply with quote

I have checked setting. There is nothing I could figure out. I have checked the setting also. As soon as I power my board the chip goes in reset mode. MCLR high, ICSPCLK high, AN0 low but ADC value max, GP2 98% duty. Right now I have only connected PIC10f222 with programming pins rest all the connections I have removed. Here is the code.

Code:
CCS PCB C Compiler, Version 4.104, 5967               29-Apr-10 13:29

               Filename: C:\Documents and Settings\Administrator\My Documents\new_io\new_io.lst

               ROM used: 60 words (12%)
                         Largest free fragment is 452
               RAM used: 5 (22%) at main() level
                         6 (26%) worst case
               Stack:    1 locations

*
0000:  MOVWF  05
0001:  GOTO   015
0002:  GOTO   003
.................... #include "C:\Documents and Settings\Administrator\My Documents\new_io\new_io.h"
.................... #include <10F222.h>
.................... //////// Standard Header file for the PIC10F222 device ////////////////
.................... #device PIC10F222
.................... #list
.................... 
.................... #device adc=8
.................... 
.................... #FUSES NOWDT                    //No Watch Dog Timer
.................... #FUSES NOMCLR                   //Master Clear pin used for I/O
.................... #FUSES NOPROTECT                //Code not protected from reading
.................... #FUSES NOMCPU                   //Master Clear Pull-up disabled
.................... #FUSES IOSC4                    //INTOSC speed 4 MHz
.................... #FUSES RESERVED                 //Used to set the reserved FUSE bits
.................... 
.................... #use delay(clock=4000000)
*
0003:  MOVF   0E,W
0004:  BTFSC  03.2
0005:  GOTO   014
0006:  MOVLW  01
0007:  MOVWF  0A
0008:  CLRF   09
0009:  DECFSZ 09,F
000A:  GOTO   009
000B:  DECFSZ 0A,F
000C:  GOTO   008
000D:  MOVLW  4A
000E:  MOVWF  09
000F:  DECFSZ 09,F
0010:  GOTO   00F
0011:  GOTO   012
0012:  DECFSZ 0E,F
0013:  GOTO   006
0014:  RETLW  00
.................... 
.................... 
.................... int8 value;
.................... 
.................... 
.................... 
.................... void main()
.................... {
0015:  CLRF   04
.................... 
....................    setup_adc_ports(sAN0);
*
0018:  BSF    07.6
0019:  BCF    07.7
....................    setup_adc(ADC_ON);
001A:  BSF    07.0
....................    setup_timer_0(RTCC_INTERNAL|RTCC_DIV_1);
001B:  MOVLW  08
001C:  OPTION
....................     
.................... 
....................    // TODO: USER CODE!!
....................             while(true)
....................                {
....................                set_adc_channel(0);
001D:  MOVLW  00
001E:  MOVWF  0A
001F:  MOVF   07,W
0020:  ANDLW  F3
0021:  IORWF  0A,W
0022:  MOVWF  07
....................                 delay_ms(5);
0023:  MOVLW  05
0024:  MOVWF  0E
0025:  CALL   003
....................             
....................              value = Read_ADC();
0026:  BSF    07.1
0027:  BTFSC  07.1
0028:  GOTO   027
0029:  MOVF   08,W
002A:  MOVWF  0B
....................                output_high(PIN_B2);
002B:  BCF    0C.2
002C:  MOVF   0C,W
002D:  TRIS   6
002E:  BSF    06.2
....................               delay_ms(value);
002F:  MOVF   0B,W
0030:  MOVWF  0E
0031:  CALL   003
....................               output_low(PIN_B2);
0032:  BCF    0C.2
0033:  MOVF   0C,W
0034:  TRIS   6
0035:  BCF    06.2
....................               delay_ms(255-value);
0036:  MOVLW  FF
0037:  MOVWF  0D
0038:  MOVF   0B,W
0039:  SUBWF  0D,F
003A:  MOVF   0D,W
003B:  MOVWF  0E
003C:  CALL   003
....................               }
003D:  GOTO   01D
.................... 
....................                 
....................       
.................... 
.................... }
003E:  SLEEP

Configuration Fuses:
   Word  1: 0FEA   NOMCLR NOPROTECT NOWDT NOMCPU IOSC4
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group