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

CCS C + PIC18F26K22 UART + PROTEUS

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



Joined: 14 Aug 2011
Posts: 36
Location: Somerset, UK

View user's profile Send private message

CCS C + PIC18F26K22 UART + PROTEUS
PostPosted: Sun Aug 14, 2011 7:12 am     Reply with quote

Hi,

I created a simple test program for the PIC18F26K22 which is supposed to receive characters from the first UART and put them onto the second UART, however, I keep getting "logic contentions on net" displayed in Proteus (7.8) I took out the code for reading and writing chars and it still says the same, similar code in C18 doesn't give me the errors, the CCS C compiler is version 4.120, I have heard that there are numerous bugs with CCS C and the newer PIC chips, I want to simulate on Proteus first, before buying the chips etc.

Here is the code:
main.h
Code:

#include <18F26K22.h>

#device adc=16

#FUSES NOWDT                    //No Watch Dog Timer
#FUSES WDT128                   //Watch Dog Timer uses 1:128 Postscale
#FUSES NOPLLEN                  //PLL Enable
#FUSES INTRC_IO                 //Internal RC Osc, no CLKOUT
#FUSES NOBROWNOUT               //No brownout reset
#FUSES WDT_NOSLEEP              //Watch Dog Timer, disabled during SLEEP
#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)
#fuses NODEBUG

#use delay(int=4000000)
//#use delay(int=64000000)
#use rs232(baud=38400,parity=N, xmit=PIN_C6, rcv=PIN_C7, bits=8,stream=ILIGHT_PC)
#use rs232(baud=38400,parity=N, xmit=PIN_B6, rcv=PIN_B7, bits=8,stream=ILIGHT_TFU)

main.c
Code:

#include <main.h>
void main()
{
   setup_timer_0(T0_OFF);
   setup_timer_1(T1_DISABLED);
   setup_timer_2(T2_DISABLED,0,1);
   setup_timer_3(T3_DISABLED|T3_DIV_BY_1);
   setup_timer_4(T4_DISABLED,0,1);
   setup_comparator(NC_NC_NC_NC);
   setup_ccp1(CCP_OFF);
   setup_ccp2(CCP_OFF);
   setup_ccp3(CCP_OFF);
   setup_ccp4(CCP_OFF);
   setup_ccp5(CCP_OFF);
   setup_dac(DAC_OFF);
   setup_adc(ADC_OFF | NO_ANALOGS);
   setup_oscillator(OSC_4MHZ|OSC_INTRC|OSC_PLL_OFF);
   while(1)
   {
 
   }
}


My questions are:
1) Am I doing something silly with regards to multiplexing pins etc, I'm sure i've turned everything unneccesary off, I have tried setting tris and setup_uart, none make any difference.
2) Is there any known issues between the HEX code and Proteus, surely they would produce a very similar output HEX wise?
3)It is the first time i've tried using this particular chip, am I missing any fuses etc? Although this is from the wizard and I just added a few bits to turn various peripherals off.

Any help appreciated!

Regards

Wilksey[/b]
dyeatman



Joined: 06 Sep 2003
Posts: 1930
Location: Norman, OK

View user's profile Send private message

PostPosted: Sun Aug 14, 2011 7:18 am     Reply with quote

In this forum we see numerous problems with Proteus on a regular basis.
Some members here advise against using Proteus at all because of all the
problems. You might try in the Proteus forum.
_________________
Google and Forum Search are some of your best tools!!!!
Wilksey



Joined: 14 Aug 2011
Posts: 36
Location: Somerset, UK

View user's profile Send private message

PostPosted: Sun Aug 14, 2011 7:28 am     Reply with quote

Hi,
Thanks for the reply,

It only appears that code compiled with CCS C has issues with Proteus. So i'm thinking it not to be a Proteus issue, 99% of my C18 code has worked with Proteus, including Ethernet and USB code, surely something as simple as UART should work out of the box?

Regards

Wilksey
dyeatman



Joined: 06 Sep 2003
Posts: 1930
Location: Norman, OK

View user's profile Send private message

PostPosted: Sun Aug 14, 2011 7:35 am     Reply with quote

Unfortunately, that just means Proteus has problems with CCS code, not
necessarily that CCS has problems. It looks and compiles OK for me. It
runs on the 46K22 which is the only one I have but is virtually identical.
_________________
Google and Forum Search are some of your best tools!!!!
Wilksey



Joined: 14 Aug 2011
Posts: 36
Location: Somerset, UK

View user's profile Send private message

PostPosted: Sun Aug 14, 2011 7:43 am     Reply with quote

You have tried running on Proteus or the real chip?

The code compiles without errors, it just wont run in Proteus, I used a 4MHZ clock speed so that it would run in real time and Proteus uses around 38% CPU.

If I run it as is, it complains about logic contention on nets when I try and type anything into the serial port.

If I run it with the receive and send code in, it doesn't send / receive anything.

I can run it on the hardware once I have ordered it, but I wanted to simulate it first to iron out any initial silly bugs.

The end .HEX file should be almost the same, so you think that CCS C is adding some extra stuff into the HEX?

Wilksey
dyeatman



Joined: 06 Sep 2003
Posts: 1930
Location: Norman, OK

View user's profile Send private message

PostPosted: Sun Aug 14, 2011 7:47 am     Reply with quote

I always use hardware. I don't use any simulators. What they might be
adding I don't know.

I haven't examined the hex. Unfortunately I am in the middle of a big
project with a 18F4520 and don't have the time to look.
_________________
Google and Forum Search are some of your best tools!!!!


Last edited by dyeatman on Sun Aug 14, 2011 7:50 am; edited 1 time in total
temtronic



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

View user's profile Send private message

PostPosted: Sun Aug 14, 2011 7:50 am     Reply with quote

Sorry, but if you think Proteus is great as it works 99% of the time you're kidding yourself! The fact that some C18 code works and some CCS doesn't can easily be that the Proteus programmers did more testing for C18.
Frankly there isn't any 'simulator' that truly simulates the real world even after 30+ years of'playing with chips'.
Chips these days are cheap,it's YOUR time that really costs the money.It's better to use a 'bigger, more features' chip than to try to shoehorn code into a smaller one.Saving a buck or two on a smaller PIC or a slightly smaller pcb will actually cost more in the end.
Using a 'common, overkill' PIC will actually cut costs down.I typically use a 40pin device even though an 18 or 28 might do as the customer always wants another 'feature' which means another i/o pin, more ROM,etc.
Wilksey



Joined: 14 Aug 2011
Posts: 36
Location: Somerset, UK

View user's profile Send private message

PostPosted: Sun Aug 14, 2011 8:10 am     Reply with quote

dyeatman - Ok, so you ran it on the "real" chip? Thats cool, i may just go ahead and order the chip.

temtronic - I never said it was "great" I just stated that it ran 99% of code compiled with C18, and seeing as everything, even the routines built into C18 and im guessing CCS, compile down to register level, essentially the code should work the same way, albeit one may be optimised over the other slightly differently.

I know that Proteus isn't 100% perfect, and that no 1 simulator can do everything, I just expected it to work with something so simple.

I usually prototype with 28/40 pin and production with TQFP 100's where I can to give maximum I/O capability and future expansion, so I am with you on that one!

I've only been PICing (correct term?!) for about 4 - 5 years, and the modern chips are just mind blowing! I also use Atmel and CPLD/FPGA where necessary, but mainly just use PIC's, so I dont have anywhere near the experience of someone like yourself.

My main aim was to determine if I had actually made a mistake in the code or if there was an anomaly between CCS C and Proteus, I can deduct that this is the latter from dyeatman's reply.

Typically I would test on the real hardware, but I dont have that particular chip at the moment and thought it would be nice to simulate as I was using Proteus for circuit design.

Wilksey
dyeatman



Joined: 06 Sep 2003
Posts: 1930
Location: Norman, OK

View user's profile Send private message

PostPosted: Sun Aug 14, 2011 9:35 am     Reply with quote

One caveat I just noticed when I reread your initial post... The latest version
I have is 4.114 and you are running 4.120. There may be a bug in 4.120 I
can't test, maybe someone else here can?
_________________
Google and Forum Search are some of your best tools!!!!
dyeatman



Joined: 06 Sep 2003
Posts: 1930
Location: Norman, OK

View user's profile Send private message

PostPosted: Sun Aug 14, 2011 9:46 am     Reply with quote

BTW, I am a diehard PIC fan... I started in the Motorola 6800/68000 series
years ago and moved to PICs about 10 years ago. I have completed
dozens of designs since then. ATMEL has been tempting with the additional
features but the 18 series PIC usually has everything I need.

One thing I have learned is to always suspect your "tools and test
equipment". CCS has had it's share of bugs but nothing I couldn't work
around. C18, Hitech etc all have their share of problems. However, in spite
of the numerous bugs that crop up, CCS has been the easiest to use and
has the flexibility to code around the ones that do appear.
_________________
Google and Forum Search are some of your best tools!!!!
Wilksey



Joined: 14 Aug 2011
Posts: 36
Location: Somerset, UK

View user's profile Send private message

PostPosted: Sun Aug 14, 2011 12:22 pm     Reply with quote

Thank you for your help and replies.

I am too a die hard PIC fan, I will use others if the need arises, but most of the time the PIC's have all the functionality I could ever need for a project.

One reason for using CCS over C18, although C18 is free, is that it is easier to code with and it has a great support base!

I also have Mikro C, but rarely use that.

I will try the code on the actual chip and see what the results are!

Thanks again!

Wilksey
dyeatman



Joined: 06 Sep 2003
Posts: 1930
Location: Norman, OK

View user's profile Send private message

PostPosted: Sun Aug 14, 2011 3:16 pm     Reply with quote

Actually I have FED, Mikro C and an older version of C18 and still prefer CCS...

You're right this forum is one of the BIG selling points thanks to PCM, TTelmah and many others!

Good Luck!
_________________
Google and Forum Search are some of your best tools!!!!
Wilksey



Joined: 14 Aug 2011
Posts: 36
Location: Somerset, UK

View user's profile Send private message

PostPosted: Sun Aug 14, 2011 4:30 pm     Reply with quote

I am not familiar with FED.

So, question, if Proteus is not very good at working with CCS C code, is there a simulator that is? I have a license for Oshonsoft simulators as well, but never really used them, so I am not sure if the 18F26K22 chip is included in the latest version, maybe I will check it out.

I understand that it is better to run on the real chip, and on this occasion I may well have to, but for future reference, I dont always have immediate access to the hardware but I would like to carry on testing software whilst I wait for it to arrive / build it up.

Wilksey
dyeatman



Joined: 06 Sep 2003
Posts: 1930
Location: Norman, OK

View user's profile Send private message

PostPosted: Sun Aug 14, 2011 6:02 pm     Reply with quote

The only one that people seem to have good luck with is MPLAB SIM and it also has some issues...

FED is Forrest Electronics
http://www.fored.co.uk/

IMHO they make a good compiler but take a somewhat different approach from CCS
_________________
Google and Forum Search are some of your best tools!!!!
Wilksey



Joined: 14 Aug 2011
Posts: 36
Location: Somerset, UK

View user's profile Send private message

PostPosted: Mon Aug 15, 2011 2:50 pm     Reply with quote

Hi,

Unfortunately MPLAB SIM doesn't quite do what I want it to, I have used it to check registers and variables etc, and yes, it is very good at what it does!

I have never heard of FED before, I will have a look, seems they have a trial version for testing.

Wilksey
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