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 support@ccsinfo.com

PIC12F508 gives different times
Goto page 1, 2  Next
 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
rikotech8



Joined: 10 Dec 2011
Posts: 376
Location: Sofiq,Bulgariq

View user's profile Send private message

PIC12F508 gives different times
PostPosted: Wed May 23, 2018 10:35 am     Reply with quote

When I use MPLAB to program the chip I get the message
Quote:
The target has invalid calibration data (fff).
then when I try to program the chip I get this message:
Quote:
The following memory regions failed to program correctly:
Program Memory
Address: 00000000 Expected Value: 00000025 Received Value: 00000000
Programming failed


Therefore I used different tool for programming:
Quote:
PICkit3
With that tool I am able to program the chip but I get different pulse times every next programming. My application will rely on correct timings so how to calibrate the chip?

This is a code sample for the test:

Code:


void main() {
#include <12F508.H>
#fuses INTRC, NOWDT, NOPROTECT, NOMCLR
#USE DELAY (int = 4MHZ)
   while(1) {
      delay_us(10);
      output_toggle(PIN_B5); 

      }
   }



With the code above I get different periods with each new flashing. Once i get 20uS then 22us and so on.
_________________
A person who never made a mistake never tried anything new.
Ttelmah



Joined: 11 Mar 2010
Posts: 19219

View user's profile Send private message

PostPosted: Wed May 23, 2018 10:49 am     Reply with quote

What has happened is that at some point you have done a full erase, and lost the OSCCAL value.
Now the older PicKit2, did have an option to recalculate this value.
Some of the CCS programmers have a similar option.
Without this option you have to manually generate the value. Read what has been put into the top instruction in the ROM (it'll be a RETLW xx) instruction. Then the data sheet gives how much the clock changes for changes in this value. Calculate a new value program this and test. You'll probably have to tweak it a few times till you can get the value reasonably correct.
rikotech8



Joined: 10 Dec 2011
Posts: 376
Location: Sofiq,Bulgariq

View user's profile Send private message

PostPosted: Wed May 23, 2018 11:50 am     Reply with quote

Thank you for your response. Could that value be something like 25 (like the expected value from my second quote). Isnt the compiler that generates the instructions including the one that is on the top?
_________________
A person who never made a mistake never tried anything new.
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Wed May 23, 2018 12:44 pm     Reply with quote

What version of MPLAB are you using ? MPLAB vs. 8.92 or MPLAB X vs. ?
Ttelmah



Joined: 11 Mar 2010
Posts: 19219

View user's profile Send private message

PostPosted: Wed May 23, 2018 1:10 pm     Reply with quote

The value is not a value in simple time like that it is a 'tweak' factor applied to the default oscillator. +/- a few percent. The mid value will give a particular speed and you will then have to calculate the percentage this needs to move.
rikotech8



Joined: 10 Dec 2011
Posts: 376
Location: Sofiq,Bulgariq

View user's profile Send private message

PostPosted: Thu May 24, 2018 2:04 am     Reply with quote

@PCM programmer
The MPLab version is 8.89.

@Ttelmah:
Could you please explain little bit more detailed how can I change the "top instruction in the ROM"?

https://drive.google.com/file/d/1k7VQfS90tF2b_Grf2v6HqnLiMRe8ZX8P/view?usp=sharing

Can I change value from the pic above? Is that what you meant?

Furthermore I see that the compiler provides the user to write custom data into the rom using directives:
Code:
#ROM
. May be this could do the job too?
_________________
A person who never made a mistake never tried anything new.
rikotech8



Joined: 10 Dec 2011
Posts: 376
Location: Sofiq,Bulgariq

View user's profile Send private message

PostPosted: Thu May 24, 2018 2:20 am     Reply with quote

@PCM programmer
The MPLab version is 8.89.

@Ttelmah:
Could you please explain little bit more detailed how can I change the "top instruction in the ROM"?

https://drive.google.com/file/d/1k7VQfS90tF2b_Grf2v6HqnLiMRe8ZX8P/view?usp=sharing

Can I change value from the pic above? Is that what you meant?

Furthermore I see that the compiler provides the ability for user to write custom data into the rom using directives:
Code:
#ROM
. May be this could do the job too?[/quote]
_________________
A person who never made a mistake never tried anything new.
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Thu May 24, 2018 2:51 am     Reply with quote

rikotech8 wrote:
@PCM programmer
The MPLab version is 8.89.

Go to the following menu:
Quote:
Programmer / Settings / Calibration Memory tab

There you can click a tickbox that says:
Quote:
Allow Pickit 3 to program Calibration Memory

You can put in the new value you want for Calibration memory
into the textbox to the right of "movlw".

Then program your 12F508.

It's possible that when you're done, you should go back and de-select
that tickbox. I don't know if MPLAB de-selects it automatically after
one use.
rikotech8



Joined: 10 Dec 2011
Posts: 376
Location: Sofiq,Bulgariq

View user's profile Send private message

PostPosted: Thu May 24, 2018 9:24 am     Reply with quote

@PCM programmer: Thank you for your response. I checked the checkbox for
Quote:
Allow PICkit3 to program calibration memory
but when hit the program button I still get the error:
Quote:
Programming...
The following memory regions failed to program correctly:
Program Memory
Address: 00000000 Expected Value: 00000025 Received Value: 00000000
Programming failed


The only way the programming goes well is when I first read the device and then program the chip(i guess is because it reads every word it write), otherwise I get the error above.

Although I am able to flash the chip with this tool <http://ww1.microchip.com/downloads/en/DeviceDoc/PICkit3%20Programmer%20Application%20v3.10.zip >
_________________
A person who never made a mistake never tried anything new.
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Thu May 24, 2018 11:46 am     Reply with quote

Using older PICs with modern tools doesn't seem to work very well:
http://www.microchip.com/forums/m990714-p2.aspx

Are you using NOMCLR ?
There are many threads on the Microchip forum about Pickit3, and older
8-pin devices.
http://www.microchip.com/forums/m461553.aspx

My advice is get rid of the 12F508 and use a newer PIC or buy a real
Pickit 2 on ebay for ~ $150 USD.
Ttelmah



Joined: 11 Mar 2010
Posts: 19219

View user's profile Send private message

PostPosted: Thu May 24, 2018 12:48 pm     Reply with quote

And the Pickit2 software offers an option to automatically regenerate the calibration value. Much nicer...
rikotech8



Joined: 10 Dec 2011
Posts: 376
Location: Sofiq,Bulgariq

View user's profile Send private message

PostPosted: Fri May 25, 2018 1:06 am     Reply with quote

Thank you guys. Buying another PIC12 is relatively less expensive than buying PICKit2. So I will throw away 12f508 and buy other PIC.
_________________
A person who never made a mistake never tried anything new.
Ttelmah



Joined: 11 Mar 2010
Posts: 19219

View user's profile Send private message

PostPosted: Fri May 25, 2018 1:32 am     Reply with quote

Assuming you have got PCM, and not just PCB, then chips like the 12F1840 are a 'world apart' from the 508. Comparator, DSM, UART, CPS, DAC, MSSP, PWM etc. etc.. 8* the ROM, and 10* the RAM!...
The core is actually a PIC16 (hence needs PCM), but sold as a PIC12, and put into a 8 pin package.
If you want a little 8pin PIC, these are great for almost every such job. Now they cost almost twice as much, but are just a better chip in just about every way....
rikotech8



Joined: 10 Dec 2011
Posts: 376
Location: Sofiq,Bulgariq

View user's profile Send private message

PostPosted: Fri May 25, 2018 3:23 am     Reply with quote

Yes of course! There are two considerations for my project.

The first one is that the chip must comply with the schematics(which is already printed), hence the pinout should be the same as those on 12F508.

The second is the time for implementation. Should be as quick and easy as possible, hence less investment, hence the profit gets bigger.

So in instead of ordering chips that are superior and cost more than 12f683, I decide to use this one, which I have in place, complies the requirements and allows me to start working immediately.

So I completely agree there are better uCs, but the applications requires just as much as this chip provides, even less - it is quite simple application.

You helped me a lot for the next time choice of uC. The oldest doesn't seem to be good ones.
_________________
A person who never made a mistake never tried anything new.
Ttelmah



Joined: 11 Mar 2010
Posts: 19219

View user's profile Send private message

PostPosted: Fri May 25, 2018 6:24 am     Reply with quote

Yes. The problem is that sometimes the older chips are not properly supported by the newer tools. This is why keeping hold of older tools is so useful...
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Goto page 1, 2  Next
Page 1 of 2

 
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