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 support@ccsinfo.com

what is the problem?

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
biomed12



Joined: 05 Feb 2016
Posts: 33

View user's profile Send private message

what is the problem?
PostPosted: Sun Apr 17, 2016 5:46 am     Reply with quote

Hello everyone,

I have been working with p16f877 until now. I tried to compile similar code for 18f4550. But there should be a problem. What is the problem, uart module doesn't work properly. code for adc and sending it to rs232 and works perfect for 16f877a
Code:

#include <18F4550.h>
#device ADC=10


#fuses HSPLL,NODEBUG,NOCPD,NOPROTECT,NOPUT
#fuses pll4
#FUSES NOWDT                    //No Watch Dog Timer
#FUSES WDT128                   //Watch Dog Timer uses 1:128 Postscale
#FUSES NOBROWNOUT               //No brownout reset
#FUSES NOLVP                    //No low voltage prgming, B3(PIC16) or B5(PIC18) used for I/O
#FUSES NOXINST                  //Extended set extension and Indexed Addressing mode disabled (Legacy mode)

#use delay(crystal=10MHz)
#use delay(clock=40MHz)

#define LED PIN_B0
#define DELAY 1000
#use rs232(baud=57600,xmit=pin_c1,rcv=pin_c7,parity=N,stop=1)

#include <main.h>
unsigned long int adcdeger;
unsigned char veri[8];

void main()
{
    setup_psp(psp_disabled);
    setup_spi(spi_ss_disabled);
    setup_timer_1(t1_disabled);
    setup_timer_2(t2_disabled,0,1);
    setup_timer_3(t3_disabled);
    setup_ccp1(ccp_off);
    setup_ccp2(ccp_off);
    setup_adc(adc_clock_internal);
    setup_adc_ports(an0);
    set_adc_channel(0);
    delay_ms(1);
   
   //Example blinking LED program
   while(true)
   {
      adcdeger=read_adc();
      //delay_us(10);
      sprintf(veri,"%ld",adcdeger);
      puts(veri);
      output_b(0x01);
      delay_ms(100);
      output_b(0x00);
      delay_ms(100);
     
     
     
   }

}
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Sun Apr 17, 2016 9:39 am     Reply with quote

The basic problem is you didn't read the oscillator section of the 18F4550
data sheet.

You can't run the PLL from a 10 MHz crystal. The crystal must be a
4 MHz, or a multiple of 4 MHz (reduced to 4 MHz by a PLLx prescaler fuse).

The CPU clock from the PLL is not 40 MHz. It's 48 MHz or a lower value
created by a divisor (specified by a CPUDIVx fuse).

This post shows how to run the 18F4550 in non-PLL mode and in PLL mode
with a 20 MHz crystal:
http://www.ccsinfo.com/forum/viewtopic.php?t=42223&start=1
biomed12



Joined: 05 Feb 2016
Posts: 33

View user's profile Send private message

PostPosted: Sun Apr 17, 2016 1:20 pm     Reply with quote

PCM programmer wrote:
The basic problem is you didn't read the oscillator section of the 18F4550
data sheet.

You can't run the PLL from a 10 MHz crystal. The crystal must be a
4 MHz, or a multiple of 4 MHz (reduced to 4 MHz by a PLLx prescaler fuse).

The CPU clock from the PLL is not 40 MHz. It's 48 MHz or a lower value
created by a divisor (specified by a CPUDIVx fuse).

This post shows how to run the 18F4550 in non-PLL mode and in PLL mode
with a 20 MHz crystal:
http://www.ccsinfo.com/forum/viewtopic.php?t=42223&start=1



Thanks sir, i almost left using of the ccs because of this reason. I am student and have been working for 6 months with 16f877 and 16f628. 18 series has lots of differences from 16 series, even banks mapping. Everything is ok and works properly now. Thanks again.
temtronic



Joined: 01 Jul 2010
Posts: 9164
Location: Greensville,Ontario

View user's profile Send private message

PostPosted: Sun Apr 17, 2016 3:57 pm     Reply with quote

If you've chosen the 4550 for USB use, be aware that 1/3 of the code space will be taken up by the USB 'driver' ! Once I discovered that few years ago, I then chose the 18F46K22, 40 pin DIP, and a TTL<>USB module.
Benefits include faster, more powerful PIC with LOTs of memory and peripherals (2 HW UARTS, 2SPI, etc....). NO space required for USB (it's all in the TTL<>USB module. Cost is only $1 more when you consider you need USB connector, 2-4 Rs, 2-3 Cs, an LED or 2,... and hoping you don't connect D+ to D-, D- to D+ on your PCB layout ! Also the 18F46K22 works at 3V or 5V, so it easily interfaces to 3V devices like GPS, RFID, RFUARTs, etc.


Just something to consider.

Jay
biomed12



Joined: 05 Feb 2016
Posts: 33

View user's profile Send private message

PostPosted: Sun Apr 17, 2016 5:17 pm     Reply with quote

temtronic wrote:
If you've chosen the 4550 for USB use, be aware that 1/3 of the code space will be taken up by the USB 'driver' ! Once I discovered that few years ago, I then chose the 18F46K22, 40 pin DIP, and a TTL<>USB module.
Benefits include faster, more powerful PIC with LOTs of memory and peripherals (2 HW UARTS, 2SPI, etc....). NO space required for USB (it's all in the TTL<>USB module. Cost is only $1 more when you consider you need USB connector, 2-4 Rs, 2-3 Cs, an LED or 2,... and hoping you don't connect D+ to D-, D- to D+ on your PCB layout ! Also the 18F46K22 works at 3V or 5V, so it easily interfaces to 3V devices like GPS, RFID, RFUARTs, etc.


Just something to consider.

Jay


These considers are unvaluable for me. I have been working with serial communication module for my little projects. One of the big reasons for starting to use p18 series is definetely its USB properties. I saved your suggestion to use when i need.

Thanks very much.
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Page 1 of 1

 
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