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

PIC16F1455 clock too slow, please help

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



Joined: 25 Jun 2014
Posts: 18

View user's profile Send private message

PIC16F1455 clock too slow, please help
PostPosted: Wed Jun 25, 2014 8:29 am     Reply with quote

Hello, I need my PIC to run at 48MHz. So to test the speed I made this code:

Code:

#include <16F1455.h>

#FUSES NOWDT                    //No Watch Dog Timer
#FUSES INTRC_IO                 //Internal RC Osc, no CLKOUT
#FUSES WDT_SW                   //No Watch Dog Timer, enabled in Software
#FUSES NOMCLR                   //Master Clear pin used for I/O
#FUSES NOBROWNOUT               //No brownout reset
#FUSES NOIESO                   //Internal External Switch Over mode disabled
#FUSES NOFCMEN                  //Fail-safe clock monitor disabled
#FUSES NOSTVREN                 //Stack full/underflow will not cause reset
#FUSES BORV25                   //Brownout reset at 2.5V
#FUSES NOLVP                    //No low voltage prgming, B3(PIC16) or B5(PIC18) used for I/O
#FUSES NOCLKOUT
#FUSES NOCPUDIV
#FUSES PLLEN
#FUSES PLL3X

#use delay(clock=48000000)



void main() {
     long i, j;
     output_high(PIN_C1);
     while(TRUE){
         for(i=0;i<3464;i++){
               for(j=0;j<3464;j++){
               }
         }
         output_toggle(PIN_C1);
     }
}


There is a LED on PIN_C1, but it takes 12 second to toggle. The loop is 12 million long, so if my calculations are correct it should toggle every second. It appears that the PIC is running at 4MHz, not 48.

Could anyone correct me if I'm wrong? I need to know if the clock speed is correct.
Thank you in advance.
ezflyr



Joined: 25 Oct 2010
Posts: 1019
Location: Tewksbury, MA

View user's profile Send private message

PostPosted: Wed Jun 25, 2014 9:05 am     Reply with quote

Hi,

Try this substitution:

Code:

#use delay(internal=48000000)


John
jocaropi



Joined: 25 Jun 2014
Posts: 18

View user's profile Send private message

PostPosted: Wed Jun 25, 2014 9:08 am     Reply with quote

Thank you for your quick response John.
I did it already, still 12 seconds :/
ezflyr



Joined: 25 Oct 2010
Posts: 1019
Location: Tewksbury, MA

View user's profile Send private message

PostPosted: Wed Jun 25, 2014 9:16 am     Reply with quote

Hi,

Admittedly, I don't use that PIC (or any quite like it), but here is what I would try next:

Code:

#use delay(internal=16000000, clock=48000000)


That PIC has a 16MHz internal oscillator, and with the PLL can achieve 48MHz internally. your problem is just a matter of sorting out the correct way to get that setup properly.

John
jocaropi



Joined: 25 Jun 2014
Posts: 18

View user's profile Send private message

PostPosted: Wed Jun 25, 2014 9:21 am     Reply with quote

Nothing, still 12 seconds
temtronic



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

View user's profile Send private message

PostPosted: Wed Jun 25, 2014 9:27 am     Reply with quote

hmm... compiler version bug ??

I'd printout the listing to check what the fuse REALLY are,not what we 'think' they are.

Also I'd use a
delay_ms(500);
output_toggle(LED);

instead of the loopy-loop , at least for a sanity check....

hth
jay
jocaropi



Joined: 25 Jun 2014
Posts: 18

View user's profile Send private message

PostPosted: Wed Jun 25, 2014 9:37 am     Reply with quote

Here is what the listing says:

Code:

CCS PCM C Compiler, Version 4.140, 5967               25-jun-14 17:19

               Filename:   C:\Users\Jose Carlos\Desktop\Camara Termica\Programa16F\infrarrojos.lst

               ROM used:   61 words (1%)
                           Largest free fragment is 2048
               RAM used:   9 (1%) at main() level
                           20 (2%) worst case
               Stack:     0 locations

*
0000:  MOVLP  00
0001:  GOTO   003
0002:  NOP
.................... #include <16F1455.h>
.................... #device PIC16F1455
.................... #list
.................... 
.................... 
.................... #FUSES NOWDT                    //No Watch Dog Timer
.................... #FUSES INTRC_IO                 //Internal RC Osc, no CLKOUT
.................... #FUSES WDT_SW                   //No Watch Dog Timer, enabled in Software
.................... #FUSES NOMCLR                   //Master Clear pin used for I/O
.................... #FUSES NOBROWNOUT               //No brownout reset
.................... #FUSES NOIESO                   //Internal External Switch Over mode disabled
.................... #FUSES NOFCMEN                  //Fail-safe clock monitor disabled
.................... #FUSES NOSTVREN                 //Stack full/underflow will not cause reset
.................... #FUSES BORV25                   //Brownout reset at 2.5V
.................... #FUSES NOLVP                    //No low voltage prgming, B3(PIC16) or B5(PIC18) used for I/O
.................... #FUSES NOCLKOUT
.................... #FUSES NOCPUDIV
.................... #FUSES PLLEN
.................... #FUSES PLL3X
.................... 
.................... #use delay(internal=16000000, clock=48000000)
.................... 
.................... 
.................... 
.................... void main() {
0003:  CLRF   05
0004:  CLRF   04
0005:  MOVLW  3C
0006:  MOVLB  01
0007:  MOVWF  19
0008:  CLRF   18
0009:  MOVLB  03
000A:  CLRF   0C
000B:  CLRF   0E
000C:  MOVLB  02
000D:  CLRF   12
000E:  CLRF   11
000F:  CLRF   14
0010:  CLRF   13
....................      long i, j;
....................      output_high(PIN_C1);
0011:  MOVLB  01
0012:  BCF    0E.1
0013:  MOVLB  02
0014:  BSF    0E.1
....................      while(TRUE){
....................          for(i=0;i<3464;i++){
0015:  MOVLB  00
0016:  CLRF   22
0017:  CLRF   21
0018:  MOVF   22,W
0019:  SUBLW  0D
001A:  BTFSS  03.0
001B:  GOTO   036
001C:  BTFSS  03.2
001D:  GOTO   022
001E:  MOVF   21,W
001F:  SUBLW  87
0020:  BTFSS  03.0
0021:  GOTO   036
....................                for(j=0;j<3464;j++){
0022:  CLRF   24
0023:  CLRF   23
0024:  MOVF   24,W
0025:  SUBLW  0D
0026:  BTFSS  03.0
0027:  GOTO   032
0028:  BTFSS  03.2
0029:  GOTO   02E
002A:  MOVF   23,W
002B:  SUBLW  87
002C:  BTFSS  03.0
002D:  GOTO   032
....................                }
002E:  INCF   23,F
002F:  BTFSC  03.2
0030:  INCF   24,F
0031:  GOTO   024
....................          }
0032:  INCF   21,F
0033:  BTFSC  03.2
0034:  INCF   22,F
0035:  GOTO   018
....................          output_toggle(PIN_C1);
0036:  MOVLB  01
0037:  BCF    0E.1
0038:  MOVLW  02
0039:  MOVLB  02
003A:  XORWF  0E,F
....................      }
003B:  GOTO   015
.................... }
003C:  SLEEP

Configuration Fuses:
   Word  1: 098C   INTRC_IO WDT_SW PUT NOMCLR NOPROTECT NOBROWNOUT NOCLKOUT NOIESO NOFCMEN
   Word  2: 19CF   NOWRT NOCPUDIV LS48MHZ PLL3X PLLEN NOSTVREN BORV25 NOLPBOR NODEBUG NOLVP


The configuration words are set correctly (I have checked the datasheet), but it seems that the OSCTUNE is not set anywhere to the max frecuency.
So my guess is that the PIC is running at the HFINTOSC default after-reset speed, which is 500kHz, with PLLx3 = 1.5MHz. Wich makes total sense with the speed I'm seeing.
The problem is, I don't know how to do it by myself, I have tried but with no results.
jeremiah



Joined: 20 Jul 2010
Posts: 1343

View user's profile Send private message

PostPosted: Wed Jun 25, 2014 10:27 am     Reply with quote

With the code you had, I calculate a 12ish second delay between each toggle.

Inner loop
You have roughly 12 instructions executed 3464 times = 41,568 instructions

Outer loop
You have roughly (13 instructions + inner loop ) * 3464 = 144,036,584 instructions


At 48 MHz, the instruction clock is 48/4 = 12 MHz

144,036,584 instructions at 12 MHz is 12 seconds

Note, that is rough calcs. I didn't check individual instruction times or do one offs on the loop, so this is just approximate

Did you try the delay_ms() method mentioned earlier?


Last edited by jeremiah on Wed Jun 25, 2014 10:37 am; edited 1 time in total
jocaropi



Joined: 25 Jun 2014
Posts: 18

View user's profile Send private message

PostPosted: Wed Jun 25, 2014 10:32 am     Reply with quote

Jeremiah, could you please explain to me why there are these number of instructions?
Thank you.
jeremiah



Joined: 20 Jul 2010
Posts: 1343

View user's profile Send private message

PostPosted: Wed Jun 25, 2014 10:35 am     Reply with quote

For loops aren't single instructions. They have things like subtractions, comparisons, increments, branching, etc. It takes a lot of instructions. Your counts would be fine if a for loop could be executed in a single instruction, but that's not currently possible in any architectures out there that I have heard of.

Just think each loop has to check the loop count, increment it, compare it, and then decide to continue the loop or leave it after the comparison. That all takes a certain amount of instructions (time).
jocaropi



Joined: 25 Jun 2014
Posts: 18

View user's profile Send private message

PostPosted: Wed Jun 25, 2014 10:44 am     Reply with quote

I understand, also I didn't notice that "i" and "j" are long int (16bit), so for a 8bit PIC takes double the time to process...
Thank you.
ezflyr



Joined: 25 Oct 2010
Posts: 1019
Location: Tewksbury, MA

View user's profile Send private message

PostPosted: Wed Jun 25, 2014 10:55 am     Reply with quote

Hi,

So, it's working now?

In addition to the lesson of keeping your test program as simple as possible (ie. so that you are testing what you *think* you are testing!), you should also get into the habit of using more descriptive variable declarations, such as 'int1', 'int8', 'int16', 'int32', etc., etc. This really helps when looking at your code!

John
asmboy



Joined: 20 Nov 2007
Posts: 2128
Location: albany ny

View user's profile Send private message AIM Address

PostPosted: Wed Jun 25, 2014 12:14 pm     Reply with quote

ezflyer gave you an an excellent detailed answer.

but what is your real QUESTION HERE??
jocaropi



Joined: 25 Jun 2014
Posts: 18

View user's profile Send private message

PostPosted: Wed Jun 25, 2014 12:17 pm     Reply with quote

It's "solved", I was mistaken with the calculations of how much time would it take the PIC to execute the code.
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