PIC32MX120F064H OSC2/CLKO/RC15 Input problem - Page 1
Forum section: electronics / general

author: peperoca116@gmail.com
author_rank: Newbie
timestamp: February 16, 2016, 05:40:03 pm
content: 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 portif(PORTCbits.RC15)Although the pin input is high (> 2.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

author: Howardlong
author_rank: Super Contributor
timestamp: February 16, 2016, 07:29:54 pm
content: POSCMOD=OFFI'm out and about at the moment so can't try it for you directly.

author: mikeselectricstuff
author_rank: Super Contributor
timestamp: February 16, 2016, 08:14:35 pm
content: Quote from: Howardlong on February 16, 2016, 07:29:54 pmyeah that rings a bell...

author: Howardlong
author_rank: Super Contributor
timestamp: February 16, 2016, 10:41:53 pm
content: 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 fingerBy 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:#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=OFFvoid main(void){TRISCbits.TRISC15 = 1;TRISFbits.TRISF4=0;while (1){LATFbits.LATF4=PORTCbits.RC15;Nop();}return;}

author: ale500
author_rank: Frequent Contributor
timestamp: February 17, 2016, 11:47:51 am
content: I had the same problem a couple of days ago... another good one is:Code:#pragma config ICESEL = ICS_PGx2Which 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:file:///C:/Program%20Files%20(x86)/Microchip/xc32/v1.33/docs/config_docs/32mx170f256b.htmlNow if I could understand how to measure the internal voltage reference with the ADC...

author: Howardlong
author_rank: Super Contributor
timestamp: February 17, 2016, 11:56:23 am
content: Judging from the screenshot the OP gave, it looks like they've been successful at programming and debugging the device.

author: Bruce Abbott
author_rank: Frequent Contributor
timestamp: February 17, 2016, 06:59:05 pm
content: Quote from: peperoca116@gmail.com on February 16, 2016, 05:40:03 pmPOSCMOD = 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 theinternalclock 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 disablebothOSC2 and CLKO.

author: Howardlong
author_rank: Super Contributor
timestamp: February 17, 2016, 07:08:46 pm
content: Quote from: Bruce Abbott on February 17, 2016, 06:59:05 pmI 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!

author: Howardlong
author_rank: Super Contributor
timestamp: February 17, 2016, 10:37:20 pm
content: 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_4should be#pragma config FPLLMUL = MUL_24, FPLLIDIV = DIV_2, FPLLODIV = DIV_2In 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.