| View previous topic :: View next topic |
| Author |
Message |
Mark
Joined: 07 Sep 2003 Posts: 2838 Location: Atlanta, GA
|
|
Posted: Fri Jan 21, 2005 9:39 am |
|
|
And how do you program when using the C compiler?
If not with ic-prog, then try programming the hex file generated by the C compiler with ic-prog. |
|
 |
Guard
Joined: 20 Jan 2005 Posts: 43
|
|
Posted: Fri Jan 21, 2005 11:06 am |
|
|
Hi,
It is the same thing.
Now the program Function!!, but only in assembler :
; call 0x3FF ; retrieve factory calibration value not function
movlw 80h; ; it's ok
bsf STATUS,RP0 ; set file register bank to 1
movwf OSCCAL ; update register with factory cal value
bcf STATUS,RP0 ; set file register bank to 0
; remaining code goes here
loop:
movlw 0;
bsf STATUS,RP0 ; set file register bank to 1
movwf 0x87 ;TRISC
movlw 16;
bcf STATUS,RP0 ; set file register bank to 0
movwf 0x7 ; portc
goto loop;
; initialize eeprom locations
ORG 0x2100
DE 0x00, 0x01, 0x02, 0x03
; org 0x3ff
; retlw 0x80 ; dummy cal value for simulator
END ; directive 'end of program'
The picstart protects the last location memory, but I lost calibration , i don't know the cause
I am trying now to do samething by CCS, but
not function. |
|
 |
Guard
Joined: 20 Jan 2005 Posts: 43
|
|
Posted: Fri Jan 21, 2005 11:19 am |
|
|
In asm is ok , but in c not functions
#include <16F676.h>
#device adc=8
#use delay(clock=4000000)
#fuses NOWDT,INTRC, NOPROTECT, NOMCLR, NOCPD,PUT,NOBROWNOUT
#byte OSCCAL = 0X90
#byte STATUS = 0X03
void main()
{
setup_adc_ports(NO_ANALOGS|VSS_VDD);
setup_adc(ADC_OFF);
setup_timer_0(RTCC_INTERNAL|RTCC_DIV_1);
setup_timer_1(T1_DISABLED);
setup_comparator(NC_NC_NC_NC);
setup_vref(FALSE);
#asm
movlw 0x80;
bsf STATUS ,0X05 ; set file register bank to 1
movwf OSCCAL ; update register with factory cal value OSCCAL
bcf STATUS,0X05 ; set file register bank to 0
; remaining code goes here
loop:
movlw 0;
bsf STATUS,0X05 ; set file register bank to 1
movwf 0x87 ;TRISC
movlw 16;
bcf STATUS,0X05 ; set file register bank to 0
movwf 0x7 ; portc
goto loop;
#endasm |
|
 |
Mark
Joined: 07 Sep 2003 Posts: 2838 Location: Atlanta, GA
|
|
Posted: Fri Jan 21, 2005 2:11 pm |
|
|
If the last location is blank, then you are in trouble. You have to get this programmed. The problem is this:
You asm program doesn't call the blank location. Instead, it just loads the calibration value. The C program is too smart. The first instruction makes the call to the last location. Since there is nothing there, the Program Counter wraps back to 0 and guess what? Yep, it makes the call again and again the PC wraps. The osc is enabled and thus you are getting the output from the clock. The calibration is off but it still outputs something. Your other programs work becaue they don't make this call. |
|
 |
languer
Joined: 09 Jan 2004 Posts: 144 Location: USA
|
|
 |
Mark
Joined: 07 Sep 2003 Posts: 2838 Location: Atlanta, GA
|
|
Posted: Fri Jan 21, 2005 6:56 pm |
|
|
I had a problem with a 12F675-DEBUG chip where the osc cal value was erased. All the programmers that I tried would not put this value back. They "protected" it so I couldn't write to it. If this is the case, then you are in a bit of a mess. A solution is to fool the complier by telling it that you are going to use an external clock. This should prevent the compiler from putting the call in there. In your code, set the calibration value in the oscal reg. Now before you program the chip, change the configuration settings so that it uses the internal osc. The code should work then. Everytime you compile, you will have to change the config bits unless you can write the osc cal value back to the last location with a bit of code.
Last edited by Mark on Mon Jan 24, 2005 7:44 am; edited 1 time in total |
|
 |
Guard
Joined: 20 Jan 2005 Posts: 43
|
|
Posted: Mon Jan 24, 2005 7:20 am |
|
|
Hi,
When I do change configuration settings , picstart return an error, configuration bits error ( OS 3.11).
I bought new micro, then I read contents for backup, but in the program memory there isn't RETLW:
/////////////////////
9.2.5.1 Calibrating the Internal Oscillator (16F676)
A calibration instruction is programmed into the last
location of program memory. This instruction is a
RETLW XX, where the literal is the calibration value.
The literal is placed in the OSCCAL register to set the
calibration of the internal oscillator. Example 9-1
//////////////////////
My pic is a SL package (SMD)
I read these istructions in the pic (0-0x3ff)
--> ADDLW 0xff
Can you confirm ? |
|
 |
Mark
Joined: 07 Sep 2003 Posts: 2838 Location: Atlanta, GA
|
|
Posted: Mon Jan 24, 2005 7:39 am |
|
|
As read from an ICD2 and MPLAB v7
1024 03FF 34AC RETLW 0xac
Also, I tried erasing the chip. The RETLW instruction remained.
I tried programming the chip with different data at the last location. The RETLW instruction remained.
NOTE: All the suggestions about including #ROM to define the last location will not work
The reason: Most programmers protect this spot. If something goes wrong during the erase cycle, then the chip may get its cal value erased.
. | Quote: | Note: Erasing the device will also erase the preprogrammed
internal calibration value for
the internal oscillator. The calibration value
must be saved prior to erasing part as
specified in the PIC16F630/676 Programming
specification. Microchip Development
Tools maintain all calibration bits to
factory settings. |
Not sure why errors you are getting with the config bits. You should use MPLAB and the PicStart. You should have imported the hex file and then goto the "Configure" menu and select "Configuration bits" and set the configuration to use the internal RC
Last edited by Mark on Mon Jan 24, 2005 9:06 am; edited 1 time in total |
|
 |
Mark
Joined: 07 Sep 2003 Posts: 2838 Location: Atlanta, GA
|
|
Posted: Mon Jan 24, 2005 8:09 am |
|
|
Okay, I was able to fool the programmers into programming that location. Here is how I did it. It may work for you.
I used MPLAB v7
I used an ICD2 (other programmers may work as well)
I selected a "PIC16F684" device. Yes that is correct. It is a 2K device so it will let me program the location which it thinks is in the middle of programming space. I started with a clear program memory window. I edited location 0x3FF and changed the data to 0x34ac which was the orginal calibration value. On the programmer settings window, I changed the range to be 0x3F0 to 0x3FF. Next, I programmed the chip and viola! It "fooled" the programmer software. You can now switch back to the PIC16F676 and read the correct calibration value. |
|
 |
Guard
Joined: 20 Jan 2005 Posts: 43
|
|
Posted: Wed Jan 26, 2005 11:36 am |
|
|
Hi,
My Mplab 6.30 doesn't allow to write in the last location memory
( Programming->Setting).My Picstart os 3.11 is the last firmware for 17 family and Mplab 6.30 .
Although this problem, I resolved.
In C , #rom directive for ricalibrate the pic , dosn't seem to work.
I write my little asm to program calibration memory, then I newly programmed the micro in c , and it works!
Thank for your patience |
|
 |
Mark
Joined: 07 Sep 2003 Posts: 2838 Location: Atlanta, GA
|
|
Posted: Wed Jan 26, 2005 12:13 pm |
|
|
| Guard wrote: | Hi,
My Mplab 6.30 doesn't allow to write in the last location memory
|
That is correct. See the post on a work around.
| Quote: |
( Programming->Setting).My Picstart os 3.11 is the last firmware for 17 family and Mplab 6.30 .
Although this problem, I resolved.
In C , #rom directive for ricalibrate the pic , dosn't seem to work. |
Yes, that is because the programmer software (MPLAB in this case) prevents it by reading the value that is already there and makes sure it programs that value back.
| Quote: | I write my little asm to program calibration memory, then I newly programmed the micro in c , and it works!
Thank for your patience |
What do you mean by this? How did you program the last location? That pic isn't able to write to its own flash? Did you use another programmer to program the device? |
|
 |
Guard
Joined: 20 Jan 2005 Posts: 43
|
|
Posted: Thu Jan 27, 2005 9:17 am |
|
|
I have wrong to write post.
I used new micro for error, I believed was old micro without calibration.
Then I have updated MPLAB and I used #org in C and in asm code,
but I don't know still how I cancelled calibration memory |
|
 |
Mark
Joined: 07 Sep 2003 Posts: 2838 Location: Atlanta, GA
|
|
Posted: Thu Jan 27, 2005 9:49 am |
|
|
| Guard wrote: | I have wrong to write post.
I used new micro for error, I believed was old micro without calibration.
Then I have updated MPLAB and I used #org in C and in asm code,
but I don't know still how I cancelled calibration memory |
So are you saying that you did not get the calibration programmed back into the last location?
If not, then follow my suggestion. I took a 16F676 and was able to erase the last location, just as in your chip. Then I was able to put the value back by "fooling" the computer software into thinking I was programming a different device in which it didn't try and protect that memory space. |
|
 |
Guard
Joined: 20 Jan 2005 Posts: 43
|
|
Posted: Fri Jan 28, 2005 4:19 am |
|
|
Good idea!
I will try in the next days, however I think to be the only one solution for #ORG and CCS directive wtih Mplab 6.30 and O.S. 3.11 PICstart,In asm I load the value in the register
Thank |
|
 |
Mark
Joined: 07 Sep 2003 Posts: 2838 Location: Atlanta, GA
|
|
Posted: Fri Jan 28, 2005 7:50 am |
|
|
| Guard wrote: | Good idea!
I will try in the next days, however I think to be the only one solution for #ORG and CCS directive wtih Mplab 6.30 and O.S. 3.11 PICstart,In asm I load the value in the register
Thank |
Not sure what you just said. But if you are creating a "product" just loading some value isn't a good idea. That is a calibration value that changes with each chip. The proper way of doing it is the way CCS is doing it. If you follow my suggestion, the value will get programmed back into the chip. Believe me, I tested it and wouldn't have wasted my time in doing so and posting it if it didn't work. Once you get the value programmed back in, everything should work just fine with CCS. |
|
 |
|