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

12f1822 delay_ms is wrong
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
temtronic



Joined: 01 Jul 2010
Posts: 9243
Location: Greensville,Ontario

View user's profile Send private message

12f1822 delay_ms is wrong
PostPosted: Wed Feb 27, 2019 8:34 pm     Reply with quote

OK, I'm fed up shovelling snow, decided to breadboard a 12F1822 cause it's got lots of neat stuff inside. Easy right ??
Code:

//12F1822 version
//12F683 version works 100%
#include <12F1822.h>
#fuses INTRC_IO,NOWDT,NOPUT,NOPROTECT,MCLR,put
#fuses CLKOUT,NOLVP,nodebug   //clkout is 1us
#fuses noieso,nocpd,nofcmen
#use delay(clock=4Mhz)  //1us per instruction
// user define PIN I/O
#define   LED   PIN_A2   //test LED

//main program loop
main() {
   setup_comparator(NC_NC);      //no comparators
   setup_adc_ports(no_analogs);  //no analogs
   disable_interrupts(global);   //no interrupts

   while(TRUE) {   //forever loop
   output_toggle(led);   //test LED
   delay_ms(500);   // 1/2 second delay is really 40us !!!
   }

} //end of new main

Compiles fine, loads OK, BUT delay is 40 us NOT 500ms ! Check of listing shows delay function and total cycles looks good. clkout is 1us (1/4 of 4MHz)..so PIC is running at correct speed but delay_ms is wrong. I have a 12F683 on same board, it's happy. Using MPLAB 8.92, PCM 4.123, PICkit3 to power PICs. Is there some silly new fangled fuse I haven't got set properly, cause 'playing PIC' and running the asm it should be fine.
Even burned a 683 to confirm my scopes not playing games with me. 683 delay IS 500ms....any insight is appreciated.
Jerson



Joined: 31 Jul 2009
Posts: 125
Location: Bombay, India

View user's profile Send private message Visit poster's website

PostPosted: Wed Feb 27, 2019 8:45 pm     Reply with quote

Unsure if it is a calculation overflow problem like fitting a 16 bit value into a 8 bit register kind of thing. Inspection of the generated code would answer it.
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Wed Feb 27, 2019 10:49 pm     Reply with quote

I installed PCM vs. 4.123 and compiled your program, and ran it in MPLAB
vs. 8.92 simulator. It worked fine. In the Debugger / Settings / Osc tab
I set it to 4 MHz to match the program.

The Stopwatch reports these numbers:
Instruction cycles: 500034
Time: 500.034000 ms
Processor Frequency (MHz): 4.000000

I suggest re-installing your compiler.
Ttelmah



Joined: 11 Mar 2010
Posts: 19538

View user's profile Send private message

PostPosted: Wed Feb 27, 2019 11:58 pm     Reply with quote

I'd guess he just hasn't set the clock in MPLAB.
MPLAB does not 'know' what clock rate the chip is running at.

I've checked, and his compiler version, is setting up the internal oscillator
correctly with the posted code, and generating the delays right as
PCM_Programmer says.

One other possibility, would be something 'silly', like a invisible character
in the actual number typed. I've seen this in the past, where the value is
actually something like 50(hidden char)0, and the older compilers in
particular would read it as '50'...
temtronic



Joined: 01 Jul 2010
Posts: 9243
Location: Greensville,Ontario

View user's profile Send private message

PostPosted: Thu Feb 28, 2019 6:36 am     Reply with quote

OK..update...
grabbed my 'old and slow' XP machine which has MPAB 8.86 /PCM 4.114/ cut code/compiled/burned PIC.. same thing 'fast LED'. lightbulb comes, look at the build configuration...it's defaulted to 'debug'. I change to 'release' which is MY default, recompile/burn... LED flashes at the correct speed !
AH HA...

so I go back to the W7 machine , have a look ..for some UNKNOWN reason I have NO build configurations in MPLAB ! neither release nor debug....just grey 'no build configurations'...

man I'm getting too old for this... how the heck does one lose 'build configurations ' ?

at least I KNOW the PIC works...
off to fix the snowblower in bitterly cold weather and finish that job BEFORE I backup all PIC stuff, then hopefully find the'build configurations...

thanks for the ideas..nice to bounce stuff here saves banging head on wall !
Jay
Ttelmah



Joined: 11 Mar 2010
Posts: 19538

View user's profile Send private message

PostPosted: Thu Feb 28, 2019 9:03 am     Reply with quote

A poster a while ago had the same:

<https://www.ccsinfo.com/forum/viewtopic.php?t=50904>

He re-installed MPLAB and the compiler and it fixed it.

Have found other posters with the greyed configurations on the old
MicroChip forums, and re-installing MPLAB seems to be the fix.

Interesting, built with 'Debug', it must be calling the debug executive
in the chip and then skipping a lot of the code!...
temtronic



Joined: 01 Jul 2010
Posts: 9243
Location: Greensville,Ontario

View user's profile Send private message

PostPosted: Thu Feb 28, 2019 9:31 am     Reply with quote

arrgh.. I just downloaded/installed MPLAB v8.91 and IT has greyed out build confgurations...!!!!
Once my fingers thaw out( only 17*F here) I'll try 'something'...
I'll check the link.
TY
jay
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Thu Feb 28, 2019 11:05 am     Reply with quote

temtronic wrote:

I have NO build configurations in MPLAB ! neither release nor debug....just
grey 'no build configurations'.

If the Build Configuration drop-down box is "grayed out", then do this:
Shut down MPLAB. Install the CCS "plug-in" for MPLAB vs. 8xx, and
re-start MPLAB. You should now be able to select Release or Debug.
http://www.ccsinfo.com/downloads/setup_mplab_plugin.exe

MPLAB vs. 8.xx defaults to a build configuration of DEBUG. To change this
behavior so it defaults to RELEASE mode, do the following:

1) Open regedit and navigate to registry key "HKEY_CURRENT_USER\Software\Microchip\MPLAB IDE".

2) Create a new string value called 'DefaultBuildConfiguration".

3) Set the value of this string to "Release".

Of course, don't include the quotes when you type in the new key or its setting.
temtronic



Joined: 01 Jul 2010
Posts: 9243
Location: Greensville,Ontario

View user's profile Send private message

PostPosted: Thu Feb 28, 2019 11:56 am     Reply with quote

thanks PCM P ...
tried that , got it back BUT still won't delay properly.. 40us high,40us low 'clock' on the pin A2.
uninstalled my 8.92 which has worked fine for years....
dl and installed 8.91 , ok but same 'clock ' problem
dl and installed 8.86, ditto

I'm going to empty the trash bin, power off and try reinstallin 8.86 sas I KNOW that works on my XP machine...

man I am getting too old for this nonsense...
update..
decided to load 8.92 as it used to work...then the ccs plugn
NOW I get some kind of 'violation' msg...stuff gets greyed out
this is the 3rd Monday this week...
it'd be nice to 'turn back the clock' 5 days before this all happened.sad thing is UPS is dropping off MORE PICS from Thailand in 3 hrs....

Jay
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Thu Feb 28, 2019 1:17 pm     Reply with quote

You do have system restore capabilility in Windows. Go back to an earlier
"restore point" if you think that will help.

Also:

Try a different pin, other than A2. Does it still fail ?

Try a different 12F1822 if you have one.

Try a different program in your 12F1822.

How do you know you are even really programming the PIC ?
What if it's still running, say, an i2c test program, or a PWM
test program left over from the past ? What if your programmer
doesn't work ?
Ttelmah



Joined: 11 Mar 2010
Posts: 19538

View user's profile Send private message

PostPosted: Thu Feb 28, 2019 2:40 pm     Reply with quote

The other thing is to not build via MPLAB.
Just compile with CCS. Doesn't stop you debugging, you can still import
the .cof file into MPLAB and use he debugger. Make sure you compile
with DEBUG off if you are going to put this in a normal chip to run,
or on if you are going to debug with a hardware debugger, and a lot
of the potential problems disappear.
temtronic



Joined: 01 Jul 2010
Posts: 9243
Location: Greensville,Ontario

View user's profile Send private message

PostPosted: Thu Feb 28, 2019 2:49 pm     Reply with quote

well this is getting worse....if that's possible.
uninstall 8.86,8.91 8.92 of mplab..
clean up registry
confirm no microchip folders
empty trash bin.
download mplab v8.92 from microchip archives
download ccs plugin
follow popup instructions to the letter, use all the defaults..
all seems good..
open the project, edit the delay for 1/4 sec flash rate
press F10 (make) I get 'access violation @address 02d6b000 of address 02d6b000...
sigh...
exit, kill the task...try again
open the project, edit the delay for 1/4 sec flash rate
this time change build config to 'release' ( my default for years...)
F10 'privileged instruction' pops up !! some of the pulldown options are now grey too !

dbl sigh...

NOW I'm thinking Windows7 is having fun with me cause this PC has run MPLAB 8.92 fine for 3-4 years. I ONLY got into this mess trying to program the 12F1822, which programs FINE under XP/MPLAB 8.86. I've got 3 PICs blinking their LEDS in my face as I type....

also tossed back out, again and broke snowblower, so there's a grey cloud following me .....arrgh
I'm running Windows 7 Ultimate, 64 bit and nothing has changed and it all worked before.....

I could just go back to my XP machine but that doesn't explain WHY this don't work anymore.....

off to brew another pot of coffee, trash MPLAB and start again.....
dluu13



Joined: 28 Sep 2018
Posts: 395
Location: Toronto, ON

View user's profile Send private message Visit poster's website

PostPosted: Thu Feb 28, 2019 3:13 pm     Reply with quote

This seems a stretch, but one colleague had his ccs stop working because he
got a new computer and he wasn't admin. Running MPLAB as admin fixed the
problems.

But your problem doesn't exactly sound the same. In his case, it would not
compile at all. It couldn't access any of the device/standard library header
files.

He was also running the latest version of MPLABX 5.
PrinceNai



Joined: 31 Oct 2016
Posts: 480
Location: Montenegro

View user's profile Send private message

PostPosted: Thu Feb 28, 2019 4:11 pm     Reply with quote

Quote:

I'm running Windows 7 Ultimate, 64 bit and nothing has changed and it all worked before.....

Haven't we all said that at least 15 times before biting the bullet and reinstalling everything :-). Windows aren't exactly known for running years without problem.

That is the exact reason why I keep all my projects in Dropbox and always have a Norton Ghost copy of a fresh Windows that never saw internet, with all programs installed. Up and running in 20 minutes when blue screens and violations start to pop up.
Hope you get it running soon.
PrinceNai



Joined: 31 Oct 2016
Posts: 480
Location: Montenegro

View user's profile Send private message

PostPosted: Fri Mar 01, 2019 3:53 am     Reply with quote

One more idea: if it is a Windows problem, System restore to an earlier date actually works sometimes.
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