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

24F running slow; software or hardware?

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



Joined: 02 Feb 2010
Posts: 73

View user's profile Send private message

24F running slow; software or hardware?
PostPosted: Sun Apr 20, 2014 4:15 am     Reply with quote

After quite some time of inactivity, I'm moving to a 24F from an 18F; due to other components in the circuit being tight-pitch SMD only devices, I've spent quite some time making a suitable prototype PCB using the cheapie chinese 10 for $10 suppliers, and only now gotten a physical setup that should be right (for the peripherals).

But I've populated the core of the board and written a basic "blinkie" test code, and it seems that it's running at least 4x as slow as it should be? Am I missing the bleeding obvious in something below, or am I likely to have a hidden hardware issue?

PWCHD v4.120
PIC24FJ64, 3.3V power
20MHz crystal with 30pF caps (20pF load capacitance)
programmed via PICKIT2 (Sure Electronics clone)
two RGB LEDs, one on C6,C7,C8 and one on B11,B12,B13

Code base generated by the wizard

24F_blink.h
Code:
#include <24FJ64GA004.h>

#FUSES NOWDT                    //No Watch Dog Timer
#FUSES NOWINDIS                 //Watch Dog Timer in Window mode
#FUSES NOJTAG                   //JTAG disabled
#FUSES HS                       //High speed Osc (> 4mhz for PCM/PCH) (>10mhz for PCD)
#FUSES NOIOL1WAY                //Allows multiple reconfigurations of peripheral pins
#FUSES OSCIO                    //OSC2 is general purpose output
#FUSES CKSFSM                   //Clock Switching is enabled, fail Safe clock monitor is enabled

#use delay(clock=20000000)


24F_blink.c
Code:
#include <24F_blink.h>
#include <float.h>
#include <stdlib.h>
#include <stdlibm.h>

void main()
{
   setup_spi( FALSE );
   setup_spi2( FALSE );

   setup_timer1(TMR_DISABLED);

   // TODO: USER CODE!!
   while(1){
   
      delay_ms(500);
      output_toggle(PIN_C8);
      output_toggle(PIN_B13);
      delay_ms(500);
      output_toggle(PIN_C7);
      output_toggle(PIN_B12);
      delay_ms(500);
      output_toggle(PIN_C6);
      output_toggle(PIN_B11);
     
   }

}

As I said, it's been quite some time so I'm rusty (not that I was ever shiny to begin with), but as far as I can tell that should toggle the RGB colours every 0.5 seconds, whereas it's taking 2+ seconds in physical land, so I don't know where I've gone wrong. Any helpful nudges appreciated!
Ttelmah



Joined: 11 Mar 2010
Posts: 19539

View user's profile Send private message

PostPosted: Sun Apr 20, 2014 7:09 am     Reply with quote

Start with the fuses.
With the 24F, you have to enable the oscillator, and also select it. 'PR' fuse (to select the primary oscillator).
You also have OSCIO selected. This is only used when you are using an internal clock or EC mode. Fortunately it is ignored when HS is selected, but you are trying to set the oscillator 2 pin for normal I/O use....
Currently with the primary oscillator not selected, it is defaulting to using the RC oscillator with postscaler.
RoGuE_StreaK



Joined: 02 Feb 2010
Posts: 73

View user's profile Send private message

PostPosted: Sun Apr 20, 2014 5:43 pm     Reply with quote

Thanks Ttelmah, I think I had (and still have) confusion over the OSC2 section; I had interpreted this as meaning the secondary oscillator, as in a slower physical crystal off pins SOSC0 and SOSC1, and I intended using these pins for other purposes as I don't have a secondary crystal?

Oh well, just wrote it with the following fuses and it appears to now to running at the correct speed, I just don't know whether my secondary OSC pins are available or not
Code:
#include <24FJ64GA004.h>

#FUSES NOWDT                    //No Watch Dog Timer
#FUSES ICSP3                    //ICD uses PGC3/PGD3 pins
#FUSES NOJTAG                   //JTAG disabled
#FUSES HS                       //High speed Osc (> 4mhz for PCM/PCH) (>10mhz for PCD)
#FUSES NOIOL1WAY                //Allows multiple reconfigurations of peripheral pins
#FUSES NOCKSFSM                 //Clock Switching is disabled, fail Safe clock monitor is disabled
#FUSES PR                       //Primary Oscillator
#FUSES SOSC_SEC_LP              //Secondary Oscillator uses Low Power Drive Strength
#FUSES NOIESO                   //Internal External Switch Over mode disabled

#use delay(clock=20000000)
Ttelmah



Joined: 11 Mar 2010
Posts: 19539

View user's profile Send private message

PostPosted: Mon Apr 21, 2014 12:59 am     Reply with quote

The data sheet is your friend. Smile

It does get complex, since the CCS names and the Microchip ones don't always tally. However read the file 'fuses.txt' in the compiler directory, for a description of each CCS fuse, which then allows these to be cross-referenced to the data sheet.

Key in this area, are that the oscillator 'setup', is separate from the 'selection' (hence the need for the PR fuse). Then the OSCIO fuse, is the one the data sheet calls OSCIOFCN, which controls the OSCO pin (not the secondary oscillator). The ones to enable the secondary oscillator are the SOSC fuses you have already found. SOSC_SEC enables it. SOSC_SEC_LP enables it in low power mode, and SOSC selects it. The 'enable' connection in the data sheet (SOSCEN), is in the OSCCON register, not a fuse. It defaults to being turned on, when any device selects the oscillator, which is either if this is selected to boot the chip, or under the control of timer1 otherwise. T1_EXTERNAL_RTC enables it (in setup_timer1), if you are not using it as the clock source, or setup_oscillator(OSC_SECONDARY), to select it as the CPU clock.

Best Wishes
RoGuE_StreaK



Joined: 02 Feb 2010
Posts: 73

View user's profile Send private message

PostPosted: Mon Apr 21, 2014 3:18 am     Reply with quote

Ttelmah wrote:
The ones to enable the secondary oscillator are the SOSC fuses you have already found. SOSC_SEC enables it. SOSC_SEC_LP enables it in low power mode, and SOSC selects it.
Actually I didn't find it, I just kinda blundered through various check boxes/dropdowns in the wizard and tried to find the closest to what I wanted Embarassed I don't think I even meant to have that bit selected! Looks like I need to know the fuses and their datasheet relationship in depth, rather than relying on the wizard as a click'n'forget setup. Seems to be OK at the moment, I'll cross the bridge of whether the secondary OSC pins are now free or not when I come to it; still got a lot of basic testing and gradual code migration to go first.
Thanks for the info
temtronic



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

View user's profile Send private message

PostPosted: Mon Apr 21, 2014 6:13 am     Reply with quote

Too bad these PICs have MORE fuses than instructions to learn !!

What I do is WHEN I get a set of 'fuses' that actually run the 1Hz LED program, I save them as a file(pictype.fuz). I then # include that file instead of relying on any 'wizard' let alone my grey cells as to what 'should work'.
By having this KNOWN working set of fuses, you have a solid start to carry on from.
I do the same with 'defines' for every I/O pin.A simple ,easily readable file that details every pin (used or not) WITH comments(like actual pin number).
Another 'bonus' is that 'main' is less 'cluttered' with 2-3 pages of fuses and pin defines as these are now just 2 lines !

hth
jay
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