Changing the oscillator source on a PIC24F

For Flowcode users to discuss projects, flowcharts, and any other issues related to Flowcode 5.
To post in this forum you must have a registered copy of Flowcode 5 or higher.

Moderator: Benj

Post Reply
626eng
Flowcode v5 User
Posts: 7
Joined: Thu Aug 01, 2013 8:56 pm

Changing the oscillator source on a PIC24F

Post by 626eng »

Hi, I'm using a PIC24FJ256GB110 and having some issues with switching the oscillator sources. Right now I have a 8MhZ external oscillator but when probing the OSC pin I only see a signal of 2MHz.

In addition I've made a simple ocde to fash the LEDS on the board with no delay, when viewing the signals on the scope the LEDs only falsh at a rate of ~130kHz.

I've tried going into the chip configuration and messing with the oscillator clocks, switching them between the FRC, HS, XTAL, and EC but even after switching clock outputs the code run exactly the same and the LEDs only run at 130kHz. Its almost like flowcode does even write the chip. Is there some extra C that needs to be added?

User avatar
Benj
Matrix Staff
Posts: 15312
Joined: Mon Oct 16, 2006 10:48 am
Location: Matrix TS Ltd
Has thanked: 4803 times
Been thanked: 4314 times
Contact:

Re: Changing the oscillator source on a PIC24F

Post by Benj »

Hello,

Easiest way to debug is to set the clock speed at what you think it should be i.e. 8000000 and then set the config oscillator mode to XT (I think HS is for 10MHz or over on the 16-bit PICs).

Then toggle the output pin using 1 second delays between each toggle. This should show you if the chip is running at the right speed.

Once you have this working you can enable and configure the PLL etc to up the clock speed. If the delays remain at 1s then you know the chip is still matching the clock speed setting. Activating the PLL does require C code which I can probably help you with.

626eng
Flowcode v5 User
Posts: 7
Joined: Thu Aug 01, 2013 8:56 pm

Re: Changing the oscillator source on a PIC24F

Post by 626eng »

Benj,

We did did what you suggested and we found out that our clock is actually running at 4MHz. The issue is when switching between the XTAL and the FRC source there is no change in the frequecy both run at 4MHz regardless. We also switched between the FRC source and the FRCDIV and still nothing changed...we've literally tried every oscillator setting in the chip configuration window and nothing has changed. Do you know where this is coming from? I want to say that Fosc = 8MHz and that our system clock is equal to Fosc/2.

We also tried configuring the OSCCON registers manually using the C clock as well but it could not recognize the register name. Are the registers named differently than the ones listed in the data sheet? Some help configuring the PLL once this gets working would be awesome as well.


Also if its any help we are using the Explorer 16 develpment kit with the PIC24FJ256GB110:
http://www.microchip.com/stellent/idcpl ... e=en024858

Thanks again.

626eng
Flowcode v5 User
Posts: 7
Joined: Thu Aug 01, 2013 8:56 pm

Re: Changing the oscillator source on a PIC24F

Post by 626eng »

Another thing we is that the signal on the oscillator pin doesn't look like an oscillator, it looks like a clock of 2MHz even though its wired to an 8MHz source. Here is a picture from the scope and chip configuration window
Attachments
Untitled.png
Chip Configuration
(104.15 KiB) Downloaded 1510 times

626eng
Flowcode v5 User
Posts: 7
Joined: Thu Aug 01, 2013 8:56 pm

Re: Changing the oscillator source on a PIC24F

Post by 626eng »

And here is the scope image of the osc pin
Attachments
scope.JPG
Scope Image
(153.52 KiB) Downloaded 1510 times

User avatar
Benj
Matrix Staff
Posts: 15312
Joined: Mon Oct 16, 2006 10:48 am
Location: Matrix TS Ltd
Has thanked: 4803 times
Been thanked: 4314 times
Contact:

Re: Changing the oscillator source on a PIC24F

Post by Benj »

Hello,

The OSCO pin is set to be a digital I/O pin in your configuration, but the other setting is required to allow the external clock to work.

Also your Primary oscillator is disabled.

Also your PLL is enabled.

Please could you attach the program to the forums and I will configure it for you.

626eng
Flowcode v5 User
Posts: 7
Joined: Thu Aug 01, 2013 8:56 pm

Re: Changing the oscillator source on a PIC24F

Post by 626eng »

Benj,

Here is the program we're testing with at the moment. Is there anyway we can write to the registers? Regardless if we're using the internal or external clock the 'clock speed' we have to choose in flowcode is 4MHz to get the proper 1 second delay meaning somewhere the Fosc is getting divided in half somewhere along the line. Thanks again.
Attachments
clock_test.fcf_pic16
LED blink program
(6 KiB) Downloaded 171 times

626eng
Flowcode v5 User
Posts: 7
Joined: Thu Aug 01, 2013 8:56 pm

Re: Changing the oscillator source on a PIC24F

Post by 626eng »

Benj,

We tried writing to the OSCCON register and reading back the values on the LED. What we get back is 0x7700 for the register value. Taking a look at the PIC24FJ256GB110 data sheet that means that flowcode is programming the pic to have the oscillator set to the 'Fast RC Oscillator with Postscaler (FRCDIV)' setting regardless of our attempts to change it through software. In the program below we try to change the OSCCON registers and read out the lower and higher byte on our development board. Thanks again Benj.
Attachments
clock_test.fcf_pic16
(11.5 KiB) Downloaded 154 times

User avatar
Benj
Matrix Staff
Posts: 15312
Joined: Mon Oct 16, 2006 10:48 am
Location: Matrix TS Ltd
Has thanked: 4803 times
Been thanked: 4314 times
Contact:

Re: Changing the oscillator source on a PIC24F

Post by Benj »

Hello,

Hopefully this should now run at the correct speed for you.
clock_test.fcf_pic16
(7 KiB) Downloaded 204 times

626eng
Flowcode v5 User
Posts: 7
Joined: Thu Aug 01, 2013 8:56 pm

Re: Changing the oscillator source on a PIC24F

Post by 626eng »

Benj,

The clock is running even slower now judging by the LED delays and the signal is no longer showing up on the OCSO pin. Any ideas? Thanks

Post Reply