Author Topic: PIC32MX120F064H OSC2/CLKO/RC15 Input problem  (Read 3240 times)

0 Members and 1 Guest are viewing this topic.

Offline peperoca116@gmail.comTopic starter

  • Newbie
  • Posts: 1
  • Country: mx
PIC32MX120F064H OSC2/CLKO/RC15 Input problem
« on: February 16, 2016, 05:40:03 pm »
Hi guys, this is my first post ever.
I have been spending some time trying to figure out why i can't read the input from RC15 on the PIC32MX120F064H microcontroller.

I have already disabled the Oscillator output with:

#pragma config FNOSC = FRCPLL               //Clock source FRCPLL > Internal                                           
#pragma config IESO = ON, POSCMOD = HS, FSOSCEN = OFF //48 Mhz configuration
#pragma config FPLLMUL = MUL_24, FPLLIDIV = DIV_1, FPLLODIV = DIV_4
   //Peripheral Bus Clock Divisor Default Value bits (1,2,4,8)
#pragma   config FPBDIV = DIV_2  //PBCLK is SYSCLK divided by the number selected
#pragma config OSCIOFNC = OFF // clock out disabled!!!!!

Set the tris to the correct value in both ways (Both work):
TRISCbits.TRISC15 = 1;
//mPORTCSetPinsDigitalIn(BIT_17);   

and finally read the port

if(PORTCbits.RC15)

Although the pin input is high (> 2.8) the value isn't updated.
I'm using MPLABX v3.2 with the XC1.4 compiler.

Any idea or suggestion will be highly appreciated.

peperoca116
 

Offline Howardlong

  • Super Contributor
  • ***
  • Posts: 5319
  • Country: gb
Re: PIC32MX120F064H OSC2/CLKO/RC15 Input problem
« Reply #1 on: February 16, 2016, 07:29:54 pm »
POSCMOD=OFF

I'm out and about at the moment so can't try it for you directly.
 

Offline mikeselectricstuff

  • Super Contributor
  • ***
  • Posts: 13748
  • Country: gb
    • Mike's Electric Stuff
Re: PIC32MX120F064H OSC2/CLKO/RC15 Input problem
« Reply #2 on: February 16, 2016, 08:14:35 pm »
POSCMOD=OFF

I'm out and about at the moment so can't try it for you directly.
yeah that rings a bell...
Youtube channel:Taking wierd stuff apart. Very apart.
Mike's Electric Stuff: High voltage, vintage electronics etc.
Day Job: Mostly LEDs
 

Offline Howardlong

  • Super Contributor
  • ***
  • Posts: 5319
  • Country: gb
Re: PIC32MX120F064H OSC2/CLKO/RC15 Input problem
« Reply #3 on: February 16, 2016, 10:41:53 pm »
This code works. I switched to FRC rather than FRCPLL because the breakout board I hacked together just now had no local decoupling. The code simply reflects RC15 state on RF4. RF4 chosen as it was on the corner of the breakout board. The test signal on RC15 was the 50Hz from my finger  ;)

By the way, if you don't need to use CLKO, it's quite a nice test pin to have to check your oscillator's working.

Also, turn off the watchdog timer always when tinkering. #pragma config FWDTEN=OFF

(The device I used was the PIC32MX170F512H, the same device as yours, just more memory, I had that in stock).

Code: [Select]
#include <xc.h>

//#pragma config FNOSC = FRCPLL               //Clock source FRCPLL > Internal                                           
#pragma config FNOSC = FRC
#pragma config IESO = ON, POSCMOD = OFF, FSOSCEN = OFF //48 Mhz configuration
#pragma config FPLLMUL = MUL_24, FPLLIDIV = DIV_1, FPLLODIV = DIV_4
   //Peripheral Bus Clock Divisor Default Value bits (1,2,4,8)
#pragma   config FPBDIV = DIV_2  //PBCLK is SYSCLK divided by the number selected
#pragma config OSCIOFNC = OFF // clock out disabled!!!!!

#pragma config FWDTEN=OFF

void main(void)
{
    TRISCbits.TRISC15 = 1;
    TRISFbits.TRISF4=0;
   
    while (1)
    {
        LATFbits.LATF4=PORTCbits.RC15;
        Nop();
    }
    return;
}


 

Offline ale500

  • Frequent Contributor
  • **
  • Posts: 415
Re: PIC32MX120F064H OSC2/CLKO/RC15 Input problem
« Reply #4 on: February 17, 2016, 11:47:51 am »
I had the same problem a couple of days ago... another good one is:

Code: [Select]
#pragma config ICESEL = ICS_PGx2
Which pins are used for ICS ?, there are 3 pairs, at least in the package I use (DIP28).

Valid settings can be looked up in the configuration docs... (DIP28 Package):

Code: [Select]
file:///C:/Program%20Files%20(x86)/Microchip/xc32/v1.33/docs/config_docs/32mx170f256b.html
Now if I could understand how to measure the internal voltage reference with the ADC...
 

Offline Howardlong

  • Super Contributor
  • ***
  • Posts: 5319
  • Country: gb
Re: PIC32MX120F064H OSC2/CLKO/RC15 Input problem
« Reply #5 on: February 17, 2016, 11:56:23 am »
Judging from the screenshot the OP gave, it looks like they've been successful at programming and debugging the device.
 

Offline Bruce Abbott

  • Frequent Contributor
  • **
  • Posts: 627
  • Country: nz
    • Bruce Abbott's R/C Models and Electronics
Re: PIC32MX120F064H OSC2/CLKO/RC15 Input problem
« Reply #6 on: February 17, 2016, 06:59:05 pm »

I have already disabled the Oscillator output with:
...
#pragma config IESO = ON, POSCMOD = HS, FSOSCEN = OFF //48 Mhz configuration
...
#pragma config OSCIOFNC = OFF // clock out disabled!!!!!

POSCMOD = HS turns on the primary external oscillator in High Speed crystal mode. The output of this oscillator (OSC2) is connected directly to pin 40 (where the crystal would be connected) so it cannot be overridden by any other signal.

OSCIOFNC = OFF only disables sending the internal clock signal to pin 40.

In the pin names table in the datasheet (table 2 for your device), the priorities for each signal on a pin are shown from left to right. Pin 40 is named OSC2/CLKO/RC15, which means that OSC2 overrides CLK0 which overrides RC15. To enable RC15 you must disable both OSC2 and CLKO.
 
 
 

Offline Howardlong

  • Super Contributor
  • ***
  • Posts: 5319
  • Country: gb
Re: PIC32MX120F064H OSC2/CLKO/RC15 Input problem
« Reply #7 on: February 17, 2016, 07:08:46 pm »

I have already disabled the Oscillator output with:
...
#pragma config IESO = ON, POSCMOD = HS, FSOSCEN = OFF //48 Mhz configuration
...
#pragma config OSCIOFNC = OFF // clock out disabled!!!!!

POSCMOD = HS turns on the primary external oscillator in High Speed crystal mode. The output of this oscillator (OSC2) is connected directly to pin 40 (where the crystal would be connected) so it cannot be overridden by any other signal.

OSCIOFNC = OFF only disables sending the internal clock signal to pin 40.

In the pin names table in the datasheet (table 2 for your device), the priorities for each signal on a pin are shown from left to right. Pin 40 is named OSC2/CLKO/RC15, which means that OSC2 overrides CLK0 which overrides RC15. To enable RC15 you must disable both OSC2 and CLKO.
 
 

I think we already got there yesterday, but the OP doesn't seem to have been back since then.

Another option is to set POSCMOD=EC if the OP still wants to use POSC with CLKI.

As already mentioned, personally I like to keep CLKO either for a crystal or for a debug pin so it tends not to be assigned unless I really need it. Getting the oscillator to behave how you want is part of the 101s of any MCU design!
 

Offline Howardlong

  • Super Contributor
  • ***
  • Posts: 5319
  • Country: gb
Re: PIC32MX120F064H OSC2/CLKO/RC15 Input problem
« Reply #8 on: February 17, 2016, 10:37:20 pm »
Further, to the OP, your oscillator setup is wrong. The input of the PLL needs to see 3.92 to 5MHz. The only way to achieve this from the internal FRC is to divide it by two.

#pragma config FPLLMUL = MUL_24, FPLLIDIV = DIV_1, FPLLODIV = DIV_4

should be

#pragma config FPLLMUL = MUL_24, FPLLIDIV = DIV_2, FPLLODIV = DIV_2

In addition, do you need to run PBCLK at SYSCLK/2? Unlike some other PIC32s, it's not a requirement for these to run the PBCLK at less than SYSCLK.
 


Share me

Digg  Facebook  SlashDot  Delicious  Technorati  Twitter  Google  Yahoo
Smf