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

Please, help! (18F series)
Goto page 1, 2  Next
 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
otxoasound



Joined: 07 May 2013
Posts: 6

View user's profile Send private message

Please, help! (18F series)
PostPosted: Tue May 07, 2013 1:27 am     Reply with quote

Hello.

It is the first time I post here. I need help. It is the first time I am using a 18F26J53. The program is very simple. I am just trying to blink a led. I am using the internal oscillator with the PLL to get 48 MHz. The program works in Proteus, but not in the real circuit. Here is the code:


#include <18f26j53.h>
#fuses PLL2 //8 MHz internal oscillator divided by 2 to get 4 MHz to PLL.
#fuses PLLEN //Enables PLL.
#fuses NOCPUDIV //I want 48 MHz, so I don´t need to divide it.
#fuses NOPROTECT //Code not protected.
#fuses NOWDT //No Watchdog.
#fuses INTRC_PLL_IO //Internal oscillator with PLL. No CLKOUT in RA6.
#fuses SOSC_DIG //I want to use RC0 an RC1 as digital IO.
#fuses NOCLOCKOUT //No clockout in RA6.
#fuses NOFCMEN //Disables Fail-safe monitoring.
#fuses NOIESO //Disables switching between internal and external osc.
#fuses NODSWDT //Watchdog disabled in sleep mode.
#fuses IOL1WAY //Multiple remappable pin configurations disabled.
#fuses NOWPCFG //Configuration words not protected.
#fuses LS48MHZ //If we use low speed USB (48 MHz/8 = 6 MHz).
#fuses RTCOSC_INT //RTCC uses internal oscillator.
#use delay (clock=48000000)
#byte port_B=0xF81
//--------------------------------------------------------------------------------
void main (void)
{
set_tris_b(0x00);
while(TRUE)
{
port_B=0xFF;
delay_ms(1000);
port_B=0x00;
delay_ms(1000);
}
}


Thank you in advance for you help!!!
Ttelmah



Joined: 11 Mar 2010
Posts: 19546

View user's profile Send private message

PostPosted: Tue May 07, 2013 3:05 am     Reply with quote

Try disabling the ADC.
Normally the port wakes up set up for analog I/O.
So:
(use the code buttons...)
Code:

#include <18f26j53.h>
#fuses PLL2 //8 MHz internal oscillator divided by 2 to get 4 MHz to PLL.
#fuses PLLEN //Enables PLL.
#fuses NOCPUDIV //I want 48 MHz, so I don´t need to divide it.
#fuses NOPROTECT //Code not protected.
#fuses NOWDT //No Watchdog.
#fuses INTRC_PLL_IO //Internal oscillator with PLL. No CLKOUT in RA6.
//#fuses SOSC_DIG //This enables the secondary oscillator in digital mode...
#fuses NOCLOCKOUT //No clockout in RA6.
#fuses NOFCMEN //Disables Fail-safe monitoring.
#fuses NOIESO //Disables switching between internal and external osc.
#fuses NODSWDT //Watchdog disabled in sleep mode.
#fuses IOL1WAY //Multiple remappable pin configurations disabled.
#fuses NOWPCFG //Configuration words not protected.
#fuses LS48MHZ //If we use low speed USB (48 MHz/8 = 6 MHz).
#fuses RTCOSC_INT //RTCC uses internal oscillator.
#use delay (clock=48000000)
//--------------------------------------------------------------------------------
void main (void)
{
   //set_tris_b(0x00);
   setup_adc_ports(NO_ANALOGS);
   while(TRUE)
   {
      output_b(0xFF);
      delay_ms(1000);
      output_b(0x0);
      delay_ms(1000);
   }
}

I can confirm that with the original code, ADCON0, and ADCON1, are set to zero, which means that all pins are set as analog.

As a comment, if you do start using the USB, you need to set the value 'USB_USE_FULL_SPEED' to FALSE before loading the USB drivers.

Best Wishes
otxoasound



Joined: 07 May 2013
Posts: 6

View user's profile Send private message

PostPosted: Tue May 07, 2013 4:11 am     Reply with quote

Hello.

Thanks for your help. When I simulate the code in MPLAB, the ADCON registers does not change. I add setup_adc(adc_off) too and nothing changes. Also, when I try to write FF to port A, in MPLAB, the register adquires the value EF. I can put FF in port A, only EF.

Thank you again.
ckielstra



Joined: 18 Mar 2004
Posts: 3680
Location: The Netherlands

View user's profile Send private message

PostPosted: Tue May 07, 2013 6:55 am     Reply with quote

Quote:
when I try to write FF to port A, in MPLAB, the register adquires the value EF. I can put FF in port A, only EF.
Only one answer: RTFM

If you can only set 0xEF then it means there is a problem with RA4.
Chapter 10.2 wrote:
PORTA is a 7-bit wide, bidirectional port.
7 bit, not 8 bit. Now, check the tables 10-3 and 10-4... Surprise RA4 is missing! It is not implemented in the hardware for this chip.

Also, always post your compiler version number (4.xxx), just in case it is a known compiler problem.
otxoasound



Joined: 07 May 2013
Posts: 6

View user's profile Send private message

PostPosted: Tue May 07, 2013 7:47 am     Reply with quote

Hello.

Yes, I forgot that port A was a 7 bit port. Thank you. The problem is that it does not work. The leds does not blink (always off). There is a voltage of 0,3 V in the port pins. I noticed that I forgot enable PLL. But it has not solved the problem. The new code (using port B) is:
Code:

#include <18f26j53.h>
#fuses PLL2     
#fuses PLLEN       
#fuses NOCPUDIV     
#fuses NOPROTECT     
#fuses NOWDT         
#fuses INTRC_PLL_IO
#fuses SOSC_DIG     
#fuses NOCLOCKOUT   
#fuses NOFCMEN     
#fuses NOIESO         
#use delay(internal=48MHZ)   
//***********************************************************
void main (void)
{
setup_oscillator(OSC_PLL_ON);
set_tris_b(0x00);
while(TRUE)
   {
   output_b(0xFF);
   delay_ms(1000);
   output_b(0x00);
   delay_ms(1000);
   }
}
Thanks!!!!
ckielstra



Joined: 18 Mar 2004
Posts: 3680
Location: The Netherlands

View user's profile Send private message

PostPosted: Tue May 07, 2013 8:14 am     Reply with quote

You are not a quick learner, aren't you?
- Ttelmah said to disable the ADC as this is enabled by default. PortB pins 0 to 3 all have analog inputs...
- I asked you to post your compiler version number, you didn't post it.
Ttelmah



Joined: 11 Mar 2010
Posts: 19546

View user's profile Send private message

PostPosted: Tue May 07, 2013 8:51 am     Reply with quote

otxoasound wrote:
Hello.

Thanks for your help. When I simulate the code in MPLAB, the ADCON registers does not change. I add setup_adc(adc_off) too and nothing changes. Also, when I try to write FF to port A, in MPLAB, the register adquires the value EF. I can put FF in port A, only EF.

Thank you again.


Mistype.
ANCON, not ADCON.

Read the data sheet. Quote:
"The ANCON0 and ANCON1 registers are used to
configure the operation of the I/O pin associated with
each analog channel. Setting any one of the PCFG bits
configures the corresponding pin to operate as a digital
only I/O. Clearing a bit configures the pin to operate as
an analog input for either the A/D Converter or the
comparator module. All digital peripherals are disabled
and digital inputs read as ‘0’. As a rule, I/O pins that are
multiplexed with analog inputs default to analog
operation on device Resets."

The pins will _never_ work as digital I/O, till they are deselected from being analog. The line:

setup_adc_ports(NO_ANALOGS);

Does this.

You always need to ensure that everything else that uses pins is turned off, before they will run as normal I/O.
On port B:
Comparator.
SPI
CCP
otxoasound



Joined: 07 May 2013
Posts: 6

View user's profile Send private message

PostPosted: Tue May 07, 2013 9:12 am     Reply with quote

This is for ckielstra: Maybe I am not a quick learner, but you should read before write. In previous posts I wrote that I disabled all analog inputs (turning off the ad converter and disabling all analog inputs) so this is not the problem.
This is for the pollite people (not ckielstra, of course): the compiler version is 4.114

Thanks
ckielstra



Joined: 18 Mar 2004
Posts: 3680
Location: The Netherlands

View user's profile Send private message

PostPosted: Tue May 07, 2013 12:28 pm     Reply with quote

Maybe I'm not nice (I admit it is not my best day today), but all we have is your posted code and in the last version you didn't disable the analog ports.

I don't have v4.110. Can you post the full list file (*.lst) so we can compare the generated code to a newer compiler version?
otxoasound



Joined: 07 May 2013
Posts: 6

View user's profile Send private message

PostPosted: Wed May 08, 2013 1:43 am     Reply with quote

Hello.

Here is the .lst file:

Code:

CCS PCH C Compiler, Version 4.114, xxxxx      07-may-13 15:14

               Filename: C:\Documents and Settings\Otxoa\Escritorio\parpadeo\parpadeo.lst

               ROM used: 150 bytes (0%)
                         Largest free fragment is 65378
               RAM used: 5 (0%) at main() level
                         6 (0%) worst case
               Stack:    1 locations

*
0000:  GOTO   002C
.................... #include <18f26j53.h>
.................... //////// Standard Header file for the PIC18F26J53 device ////////////////
.................... #device PIC18F26J53
.................... #list
.................... 
.................... #fuses PLL2         
.................... #fuses PLLEN         
.................... #fuses NOCPUDIV   
.................... #fuses NOPROTECT     
.................... #fuses NOWDT         
.................... #fuses INTRC_PLL_IO
.................... #fuses SOSC_DIG     
.................... #fuses NOCLOCKOUT   
.................... #fuses NOFCMEN     
.................... #fuses NOIESO       
.................... #use delay(internal=48MHZ)   
0004:  CLRF   FEA
0006:  MOVLW  06
0008:  MOVWF  FE9
000A:  MOVF   FEF,W
000C:  BZ    002A
000E:  MOVLW  0F
0010:  MOVWF  01
0012:  CLRF   00
0014:  DECFSZ 00,F
0016:  BRA    0014
0018:  DECFSZ 01,F
001A:  BRA    0012
001C:  MOVLW  8F
001E:  MOVWF  00
0020:  DECFSZ 00,F
0022:  BRA    0020
0024:  NOP   
0026:  DECFSZ FEF,F
0028:  BRA    000E
002A:  RETLW  00
....................
.................... void main (void)
.................... {
002C:  CLRF   FF8
002E:  BCF    FD0.7
0030:  CLRF   FEA
0032:  CLRF   FE9
0034:  MOVLW  40
0036:  MOVWF  F9B
0038:  MOVLW  70
003A:  MOVWF  FD3
003C:  MOVF   FD3,W
003E:  MOVLW  FF
0040:  MOVLB  F
0042:  MOVWF  x48
0044:  BCF    FC2.6
0046:  BCF    FC2.7
0048:  MOVF   x49,W
004A:  ANDLW  E0
004C:  IORLW  1F
004E:  MOVWF  x49
0050:  CLRF   x25
0052:  CLRF   FD1
0054:  CLRF   FD2
.................... setup_oscillator(OSC_PLL_ON);
0056:  MOVLW  40
0058:  MOVWF  F9B
005A:  CLRF   FD3
005C:  MOVF   FD3,W
.................... set_tris_b(0x00);
005E:  MOVLW  00
0060:  MOVWF  F93
.................... while(TRUE)
....................    {
....................    output_b(0xFF);
0062:  CLRF   F93
0064:  MOVLW  FF
0066:  MOVWF  F8A
....................    delay_ms(1000);
0068:  MOVLW  04
006A:  MOVWF  05
006C:  MOVLW  FA
006E:  MOVWF  06
0070:  MOVLB  0
0072:  RCALL  0004
0074:  DECFSZ 05,F
0076:  BRA    007A
0078:  BRA    007E
007A:  MOVLB  F
007C:  BRA    006C
....................    output_b(0x00);
007E:  CLRF   F93
0080:  CLRF   F8A
....................    delay_ms(1000);
0082:  MOVLW  04
0084:  MOVWF  05
0086:  MOVLW  FA
0088:  MOVWF  06
008A:  RCALL  0004
008C:  DECFSZ 05,F
008E:  BRA    0086
....................    }
0090:  MOVLB  F
0092:  BRA    0062
.................... }
....................     
0094:  BRA    0094

Configuration Fuses:
   Word  1: F70C   NOWDT PLL2 PLLEN NOSTVREN NOXINST DEBUG NOCPUDIV NOPROTECT
   Word  2: FF12   INTRC_PLL_IO SOSC_DIG NOCLOCKOUT NOFCMEN NOIESO WDT32768
   Word  3: FBFF   DSWDTOSC_INT RTCOSC_T1 DSBOR DSWDT DSWDT2147483648 IOL1WAY ADC10 MSSPMSK7
   Word  4: FBBF   WPFP NOWPCFG WPDIS WPBEG LS48MHZ

   Some fuses have been forced to be compatible with the ICD debugger.
Mike Walne



Joined: 19 Feb 2004
Posts: 1785
Location: Boston Spa UK

View user's profile Send private message

PostPosted: Wed May 08, 2013 5:05 am     Reply with quote

You're still not disabling analogue, and there is no need in CCS for the TRIS.
Ttelmah showed you both of these with a rewritten code sample in his first response.

Mike
ckielstra



Joined: 18 Mar 2004
Posts: 3680
Location: The Netherlands

View user's profile Send private message

PostPosted: Wed May 08, 2013 6:04 am     Reply with quote

I don't have the time now to check everything, but it turns out the CCS compiler adds code for disabling the analog ports by default:
Code:
003E:  MOVLW  FF
0040:  MOVLB  F
0042:  MOVWF  x48
0044:  BCF    FC2.6
0046:  BCF    FC2.7
0048:  MOVF   x49,W


CCP is also disabled by the compiler on startup.
If the analog port and CCP aren't the problem then perhaps it is a problem with the clock circuit?
Like I said, I don't have time to look into it so perhaps someone else can have a look?
kaem1189



Joined: 27 Dec 2011
Posts: 12

View user's profile Send private message

PostPosted: Wed May 08, 2013 7:27 pm     Reply with quote

Hello,

Have you tried disabling spi, i2c and uart as well as ccp? I see that port B is multiplexed with these features.
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Thu May 09, 2013 2:02 am     Reply with quote

I don't have an 18F26J53, but I do have an 18F27J53 and they are in
the same PIC family. This code works. It was tested in hardware with
vs. 4.114.
Code:

#include <18F27J53.h>
#fuses INTRC_PLL_IO, PLL2, PLLEN 
#use delay(clock=48M)

//=================================
void main()
{
setup_oscillator(OSC_8MHZ);

while(1)
  {
   output_b(0xFF);
   delay_ms(500);
   output_b(0x00);
   delay_ms(500);
  }

}
Ttelmah



Joined: 11 Mar 2010
Posts: 19546

View user's profile Send private message

PostPosted: Thu May 09, 2013 4:07 am     Reply with quote

Yes. The code I posted, worked for me on 4.110, which didn't automatically set the bits for digital I/O. I gave up at that point....

Best Wishes
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Goto page 1, 2  Next
Page 1 of 2

 
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