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

PIC12F509 speed issue!

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



Joined: 30 Oct 2003
Posts: 209
Location: Norfolk, England

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

PIC12F509 speed issue!
PostPosted: Tue Jul 27, 2010 10:47 am     Reply with quote

Help! The following code should produce a 1ms width square wave on pin_b0...it doesn't it produces a 9.3ms width. It's so simple I can't see where it is incorrect. The config word is calculated correcly. The INTRC osc runs at 4MHz (according to the datasheet!).
Help Please!


Code:

CCS PCB C Compiler, Version 4.107, 48595               27-Jul-10 17:43

               Filename: c:\temp\arrow.lst

               ROM used: 31 words (3%)
                         Largest free fragment is 512
               RAM used: 3 (12%) at main() level
                         4 (16%) worst case
               Stack:    1 locations

*
0000:  MOVWF  05
0001:  GOTO   016
0002:  GOTO   003
.................... #include "C:\Temp\arrow.h"
.................... #include <12F509.h>
.................... //////// Standard Header file for the PIC12F509 device ////////////////
.................... #device PIC12F509
.................... #list
.................... 
.................... 
.................... #FUSES NOWDT                    //No Watch Dog Timer
.................... #FUSES INTRC                    //Internal RC Osc
.................... #FUSES NOPROTECT                //Code not protected from reading
.................... #FUSES NOMCLR                   //Master Clear pin enabled
.................... #use delay(clock=4000000)
*
0003:  MOVF   0A,W
0004:  BTFSC  03.2
0005:  GOTO   014
0006:  MOVLW  01
0007:  MOVWF  08
0008:  CLRF   07
0009:  DECFSZ 07,F
000A:  GOTO   009
000B:  DECFSZ 08,F
000C:  GOTO   008
000D:  MOVLW  4A
000E:  MOVWF  07
000F:  DECFSZ 07,F
0010:  GOTO   00F
0011:  GOTO   012
0012:  DECFSZ 0A,F
0013:  GOTO   006
0014:  BCF    03.5
0015:  GOTO   020 (RETURN)
.................... 
.................... 
.................... 
.................... void main() {
0016:  CLRF   04
....................   while(true){
....................       output_toggle(PIN_B0);
*
0019:  BCF    09.0
001A:  MOVF   09,W
001B:  TRIS   6
001C:  MOVLW  01
001D:  XORWF  06,F
....................       delay_ms(1);
001E:  MOVWF  0A
001F:  GOTO   002
....................    }
0020:  GOTO   019
.................... }
0021:  SLEEP

Configuration Fuses:
   Word  1: 0FEA   INTRC NOWDT NOPROTECT NOMCLR
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Tue Jul 27, 2010 12:09 pm     Reply with quote

Use the Stopwatch feature of the MPLAB simulator to count the instruction
cycles in your loop. Put a breakpoint on the output_toggle() line.
Follow the instructions in this post:
http://www.ccsinfo.com/forum/viewtopic.php?t=38351
Remember to set the correct clock frequency in the Debugger Settings
menu (set it to 4 MHz).

This test will tell you if there is something wrong with the CCS delay_ms()
library code. If the loop is approximately 1 ms, then you need to look
elsewhere to find the problem.

I'm assuming that you're running this in real hardware. If you're running
it in a simulator (Proteus) then look there for the problem.
Will Reeve



Joined: 30 Oct 2003
Posts: 209
Location: Norfolk, England

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

PostPosted: Wed Jul 28, 2010 4:40 am     Reply with quote

Thanks.
After much head scratching, code looks OK. Turns out you can't use the CCS ICD to program these devices reliably! Oscal was corrupt and the fuses weren't being written correctly. Dusted off the PicKit2 programmer, and after re-calcing Oscal, programmed up and ran at full speed.

Keep well all.
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Wed Jul 28, 2010 3:03 pm     Reply with quote

I think it's probably the INTRC and NOMCLR issue. ICD2 can't program
these two fuses together reliably. MPLAB gives a warning about this.
Microchip recommends using the Pickit 2 when you want to use NOMCLR
with the internal oscillator, which is what you did.
Will Reeve



Joined: 30 Oct 2003
Posts: 209
Location: Norfolk, England

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

PostPosted: Thu Jul 29, 2010 2:36 am     Reply with quote

I didn't know there was an issue, thanks one for the memory banks. You are almost certainly correct as I hold the MCLR pin to GND with 10k which I had to remove just to get the PIC running! Holding MCLR high, it ran, but very slowly.
Programming with PicKit2 and everything is perfect.
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