Configuring PIC18F27J53 - Page 1
Forum section: electronics / beginners

author: ProAce
author_rank: Contributor
timestamp: July 19, 2016, 10:19:45 am
content: I was looking for a PIC with 7xCCP/PWM channels so I found this micro mentioned above. Before I was using 18F2523 and was quite familiar with it. Using MikroC for PIC I tried to get it up working. I made a test board, wrote a simple program, but it wouldn't work at all.Code:void main() {TRISA = 0;LATA = 0;TRISB = 0;LATB = 0;TRISC = 0;LATC = 0;Delay_ms(150);while(1) {PORTC.B4 = 1;Delay_ms(500);PORTC.B4 = 0;Delay_ms(500);}}Reading datasheet and troubleshooting with my limited knowledge I assumed that it has separate MCU frequency. So I played with configuration bits. Attached below are schematic and config bits. I still can't get it working. So what am I overlooking? It's my first time using 18FJ series PICs. I hope you can give me some tips for further troubleshooting.

author: JPortici
author_rank: Super Contributor
timestamp: July 19, 2016, 10:49:25 am
content: start by using the internal 8 MHz oscillator.have you built the minimum recommended circuit? (page 31)*i don't understand what you mean by "separate mcu frequency"

author: Wilksey
author_rank: Super Contributor
timestamp: July 19, 2016, 10:53:45 am
content: The first thing I would look at is pin multiplexing.QuoteFrom the datasheet, RB4 (as an I/O pin) is the lowest in the scale, so the peripherals after will take priority.RP7 is just a remap-able I/O function, so you can ignore this.SCL / SCK are clock lines for the I2C / SPI (MSSP), so you can try turning these off explicitly (Not tested, but it gives you the idea).Code:SSP1CON1bits.SSPEN = 0;The next is KBI0 (zero not 'O'), this is odd naming, but it's Interrupt On Change, disable Port B IOC bit.Code:INTCONbits.RBIE = 0;Last is the Capture Compare module, try disabling this.Code:CCP4CONbits.CCPM4M = 0;I must re-iterate this is not tested code, so if it doesn't recognise some of the registers then it might be you need to look at the naming, registers taken from the datasheet, and i'm used to the Microchip C compilers, not sure how it's addressed under MikroC.Also make sure your Configuration bits are set correctly and the WDT is not enabled!

author: ProAce
author_rank: Contributor
timestamp: July 19, 2016, 11:18:13 am
content: A tried using internal oscillator and it also doesn't work. I have built a circuit you can see on an attached image. On page 41 of the datasheet you can see MCU clock division bits. I don't recall seeing them on PIC18F2523.I checked PORTC I/O summary (page 153) and it doesn't seem that you can configure PORTC.B4 as output. So now I tried it with PORTC.B2 and it works! Thank you both. Next step is setting up UART. I will get back to you if I encounter more problems. At least something is working now!

author: Wilksey
author_rank: Super Contributor
timestamp: July 19, 2016, 03:22:39 pm
content: The standard saying if your PIC supports it (18F+) read from the PORT and write to the LAT(CH).So you should be writing to LATBbits.LATB4 for example.

author: The Chump
author_rank: Contributor
timestamp: July 20, 2016, 12:05:36 am
content: Seems you missed this in the datasheet, p.152"Unlike other PORTC pins, RC4 and RC5 do not haveTRISC bits associated with them. As digital ports, theycan only function as digital inputs. "btw using PORT should work fine for blinking an LED slowly

author: ProAce
author_rank: Contributor
timestamp: July 20, 2016, 05:04:39 am
content: Thanks Wilksey, didn't know that. Yeah I have totally missed that.Update: I have managed to get UART working, now i'm trying to use PWM. Thing is I always used libraries for that kind of stuff. I don't seem to find them for this PIC with 7 PWMs so I'll try to write them myself.