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

Switch from PCI16F1938 to PIC16F18857 not working

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



Joined: 18 Jul 2006
Posts: 103

View user's profile Send private message

Switch from PCI16F1938 to PIC16F18857 not working
PostPosted: Mon Oct 28, 2024 5:57 am     Reply with quote

Hello all,
Accidentally posted this is the wrong forum yesterday. Sorry about that.

I have a project that requires more memory, so I switched from a PIC16F1938 to a PIC16F18857.
Before I added the new code I wanted to make sure that the processor change would work.

I am using MPLAB X Ver 6.20 and CCS PCM Version 5.118.

Like I said before the only change I made to my existing program that works was the Header File. Everything else is the same.

It looks like the program is running extremely slow.

Here are the only changes I have made to the program. I simply remarked out the header file for the old processor and added the new header.

Any help would be appreciated.

Code:
#include <16F18857.H>
//#include <16f1938.H>
#include <24L16.c>

#fuses XT, NOWDT, NOPROTECT, NOPUT
#use delay(clock = 4000000)
#use I2C(master, SDA=PIN_A5,  SCL=PIN_A4, fast=100000)
temtronic



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

View user's profile Send private message

PostPosted: Mon Oct 28, 2024 6:02 am     Reply with quote

my 'gut' is telling me the new PIC's clock(4MHz) may not be running so it's using the 'secondary' RC clock( low speed)

You should cut a '1Hz LED' program and confirm the new PIC is operational.

Also see if the new PIC has PPS pins. If so, you'll need more code to set them up properly.
Ttelmah



Joined: 11 Mar 2010
Posts: 19509

View user's profile Send private message

PostPosted: Mon Oct 28, 2024 7:21 am     Reply with quote

Key absolutely huge difference.

The new chip is a PPS chip. You _have_ to _PIN_SELECT_ the pins for
the peripherals.
Look at the sticky at the top of the forum for how to use PIN_SELECT.
However your I2C looks to be software so not using the peripheral. What
other peripherals do you use???

CCS needs you to tell it where the peripherals are connected on PPS chips.
It won't correctly handle the TRIS settings for the peripherals without
this.
This also depends a little on what compiler version you have On some
chips with recent compilers the compiler will infer the PPS settings,
however it is always safer to do them yourself

This chip also has programmable slew rate control, which will cause
issues with the I2C, unless you set the pins to support fast operation.
Same sticky has details about this.
edbfmi1



Joined: 18 Jul 2006
Posts: 103

View user's profile Send private message

PostPosted: Mon Oct 28, 2024 10:43 am     Reply with quote

Thank you all for the input.
I understand what you are saying regarding the PIN_SELECT.

The reading and writing of the External EEprom is working.
It is just the clocking of the pic that is running extremely slow.

I think I am setting up the external oscillator incorrectly and am not sure what I need to do to tell it to use an external 4Mhz oscillator.
gaugeguy



Joined: 05 Apr 2011
Posts: 303

View user's profile Send private message

PostPosted: Mon Oct 28, 2024 11:38 am     Reply with quote

#fuses is processor specific. You must manually change it to match the new processor.

#use delay can be used to set up the clock input without needing the #fuse directive.

#use delay(clock=4M, type=crystal)
edbfmi1



Joined: 18 Jul 2006
Posts: 103

View user's profile Send private message

PostPosted: Mon Oct 28, 2024 2:51 pm     Reply with quote

Hello again,
I am still struggling with getting the Oscillator to work properly.
I am using an external 4Mhz Ceramic Resonator
Trying to set it up to give me a 1msec interrupt on TMIMER_0.
Everything that has worked in the past does not work now since this is a PPS chip.
Am I missing something with setting up the PIN_SELECT to use the external processor?
Thanks
temtronic



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

View user's profile Send private message

PostPosted: Mon Oct 28, 2024 3:56 pm     Reply with quote

hmm, ceramic resonator is not the same as a crystal with 2 caps. That may be your problem. You'll need to read the mfr spec for how to get it working with the PIC.

Just cut SIMPLE code ,like the 1Hz flashing LED program, post it here so others can see what you're doing.

edited...
looked at datasheet. that PIC does have internal oscillators, so you could use one of them,at least for basic testing purposes.If your project needs super accurate timing, then an external xtal/2caps is best.
edbfmi1



Joined: 18 Jul 2006
Posts: 103

View user's profile Send private message

PostPosted: Tue Oct 29, 2024 12:16 pm     Reply with quote

Hello again.
Per temtronic's suggestion I wrote a simple LED flashing program.
It uses Timer0 setup for a 1ms interrupt and TimerCounterPreset to set how often the LED output is toggled.
The first program was with the PIC16F1938 and it works.
When TimerCounterPreset is set to 1000 I get a 1secong LED pulse.
Here is the code.
Code:
//  ---------------------   LEDTEST   ---------------------------------------
#include <16f1938.H>
#fuses XT, NOWDT, NOPROTECT, NOPUT
#use delay(clock = 4000000)
int8 Timer0Preset;      // Preset for the 1ms interupt
int16 TimerCounter;     // Counter for 1Hz
int16 TimerCounterPreset; // Preset for 1Hz flash rate
#define LED PIN_C0
#int_TIMER0
void TIMER0_Interrupt_Servicing(void)
{
   delay_cycles(1);
   SET_TIMER0(Timer0Preset);
   delay_cycles(1);
   if (TimerCounter >= TimerCounterPreset)
   {
      delay_cycles(1);
      OUTPUT_TOGGLE(LED);   // Toggle LED output
      TimerCounter = 0; // Reset Timer Counter
   }
   else
   {
      TimerCounter++;
   }
}
void main()
{
    TimerCounter = 0;
    Timer0Preset = 131;
    TimerCounterPreset = 1000;   
    SETUP_TIMER_0(RTCC_DIV_32|RTCC_INTERNAL);   // 4MHz Setting
    enable_interrupts(INT_TIMER0);
    enable_interrupts(GLOBAL);   
}


When I change the program to use the PIC16F18857 it looks like the program locks up. But when I set the TimerCounterPreset = 1 the LED pulses every 4 seconds.
I am obviuosly setting up the timer incorrectly for the new IC but am at a loss as to what I am doing wrong.
Here is the code using the PIC16F18857.
Code:
//  ---------------------   LEDTEST   ---------------------------------------
#include <16f18857.H>
#fuses XT, NOWDT, NOPROTECT, NOPUT
#use delay(clock = 4000000)
int8 Timer0Preset;      // Preset for the 1ms interupt
int16 TimerCounter;     // Counter for 1Hz
int16 TimerCounterPreset; // Preset for 1Hz flash rate
#define LED PIN_C0
#int_TIMER0
void TIMER0_Interrupt_Servicing(void)
{
   delay_cycles(1);
   SET_TIMER0(Timer0Preset);
   delay_cycles(1);
   if (TimerCounter >= TimerCounterPreset)
   {
      delay_cycles(1);
      OUTPUT_TOGGLE(LED);   // Toggle LED output
      TimerCounter = 0; // Reset Timer Counter
   }
   else
   {
      TimerCounter++;
   }
}
void main()
{
    TimerCounter = 0;
    Timer0Preset = 131;
    TimerCounterPreset = 1;   
    SETUP_TIMER_0(RTCC_DIV_32|RTCC_INTERNAL);   // 4MHz Setting
    enable_interrupts(INT_TIMER0);
    enable_interrupts(GLOBAL);   
}


Any help would be greatly appriciatied.
temtronic



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

View user's profile Send private message

PostPosted: Tue Oct 29, 2024 12:31 pm     Reply with quote

by simple 1Hz LED program
I mean,something like this....


main()
do
output_toggle(LED);
delay_ms(500);
while(true)

...
it should flash the LED at 1Hz rate, forever.

I 'think' both your programs require a 'delay_cycles(5)' or similar as the last line in main() otherwise the PIC automatically goes to sleep ?
To me, In effect there is no real 'main' program... you set some bits then ????
Pretty sure Mr. T or others will reply soon, well, depending on where Mr. Sun is in their part of the World.
gaugeguy



Joined: 05 Apr 2011
Posts: 303

View user's profile Send private message

PostPosted: Tue Oct 29, 2024 12:33 pm     Reply with quote

In the PIC16F1938 Timer0 is 8 bit.
In the PIC16F18857 Timer0 is 16 bit.
edbfmi1



Joined: 18 Jul 2006
Posts: 103

View user's profile Send private message

PostPosted: Tue Oct 29, 2024 2:59 pm     Reply with quote

Ok,
Super simple program.
Code:
#include <16f18857.H>
#fuses XT, NOWDT, NOPROTECT, NOPUT
#use delay(clock = 4000000)
#define LED PIN_C0
main()
{
    while(true)
    {
        output_toggle(LED);
        delay_ms(500);
    }
}


And it works.
But I still dont understan how to setup Timer0 interrupt for 1ms
temtronic



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

View user's profile Send private message

PostPosted: Tue Oct 29, 2024 4:20 pm     Reply with quote

Great, now you know why the dinosaur likes 'super simple'. You've proved it's NOT a 'clock' issue, that the hardware attached to the PIC works and the compiler is 'happy' with your code......

Since the Timer0 can be either 8 or 16 bits, you'll have to configure for that and there's an 'enable' bit that needs to be 'set'. have a look at the PIC.HDR file to see what's involved.....
Ttelmah



Joined: 11 Mar 2010
Posts: 19509

View user's profile Send private message

PostPosted: Wed Oct 30, 2024 6:06 am     Reply with quote

SETUP_TIMER_0(T0_DIV_32|T0_INTERNAL|T0_8_BIT); // 4MHz Setting

General comment, don't use the RTCC settings. these are for reverse
compatibility only. They say:

// The following are provided for compatibility
// with older compiler versions

Use the T0 settings instead. The timer0 on the older chip was only an
8bit timer. Timer0 on the newer chip can be programmed to be 8bit or 16bit.
The above T0 setting sets it to 8bit.
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