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

[SOLVED] Problem 12f629 between internal osc and XT

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



Joined: 31 May 2012
Posts: 13

View user's profile Send private message

[SOLVED] Problem 12f629 between internal osc and XT
PostPosted: Thu May 31, 2012 12:34 pm     Reply with quote

Hi everybody. I have been working and reading this forum but i didnt found anything about my problem.

I have these fuses
WITH XT CRISTAL
Code:

#fuses NOWDT,NOPROTECT,NOCPD,NOMCLR,PUT,XT,NOBROWNOUT
#use delay(clock=4000000)
int16 tx=0;


WITH INTERNAL OSCILATOR
Code:

#fuses NOWDT,NOPROTECT,NOCPD,NOMCLR,PUT,INTRC_IO,NOBROWNOUT
#use delay(internal=4000000)
int16 tx=0;

and the problem is here
Code:

tnum = read_EEPROM (0 );
switch (tnum) {
case 1:
            tx=150;
            break;
   case 2:
            tx=300;
            break;
   case 3:
            tx=600;
            break;
   case 4:
            break;

   }

   while(1)
   {
      output_high(PIN_A0);
      delay_us(5);
      output_low(PIN_A0);
      delay_us(tx-7);
   }


IM using
Code:

PICKIT 2 v2.61 Logic tool
PCWHD v.4.093
33pf capacitors




My code is so simple, I take a number from the memory of the pic, I do the switch, and with it I select the "period" time. After that I do tx-7 because I have 2 outputs and a delay, that is I think 7us more.

Ok, till here everything works ok, but using the internal oscillator or using a XT (with 4mhz) my periods are different.

It looks like with crystal the pic works faster or something like that.

Anyone knows what could have happened?

regards


Last edited by Huriz on Fri Jun 01, 2012 6:52 pm; edited 4 times in total
Huriz



Joined: 31 May 2012
Posts: 13

View user's profile Send private message

PostPosted: Thu May 31, 2012 12:41 pm     Reply with quote

if i put this

delay_us(600-7);

instead of

delay_us(tx-7);

works fine but why this?
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Thu May 31, 2012 2:06 pm     Reply with quote

What is the current problem ?

Is it a different delay when you change oscillator fuses between
INTRC_IO and XT ?

Or, is it a different delay for each of these statements:
delay_us(600-7);
and
delay_us(tx-7);


What is the difference in delay times ? How are you measuring it ?
Are you using an oscilloscope or logic analyzer ?

Also
1. Is this a Proteus project ?
2. What is your CCS compiler version ?
temtronic



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

View user's profile Send private message

PostPosted: Thu May 31, 2012 6:26 pm     Reply with quote

The internal oscillator will never be the same frequency as an external crystal. Changes in Vss, temperature,etc. will affect it. Check the datasheet on the specs and range the int.osc. will run at.
You should use a 'scope and compare the PIC running using both configurations.
Ttelmah



Joined: 11 Mar 2010
Posts: 19338

View user's profile Send private message

PostPosted: Fri Jun 01, 2012 1:24 am     Reply with quote

Simplify first. Just test with a basic pin toggle, no calculated delays etc..
Then post (as PCM programmer asks), your compiler version. We can't test and see if their are any oddities with the compiler in certain circumstances, without knowing this.
Then show the code you are using to setup with the internal oscillator.

Though as Temtronic says, there will be a difference between the internal, and external oscillators (a few percent possibly), it won't be large.

Other possibility is that the crystal is not actually running at 4MHz. What loading capacitors are you using?. What is the actual crystal part number?. Though relatively 'rare', there are occasions, when the oscillator can lock onto an overtone, especially with some crystals designed for low power drive, without a series resistor being fitted.

Best Wishes
Huriz



Joined: 31 May 2012
Posts: 13

View user's profile Send private message

PostPosted: Fri Jun 01, 2012 4:12 am     Reply with quote

++++++++++++++
Informatino updated in the main post, with the compiler verison and more things
++++++++++++++


my problem is when i put the variable in the delay, it doesnt work, i dont know why.

If i put a number in the delay it works fine with both systems(internal and external oscilator), but when i put the variable in the delay it doesnt work fine with both system.

right now, i have solved the problem with this "bad" system, but is just what i dont want.



Code:

switch (tnum) {
   case 1:
            loop_1();
            break;
   case 2:
            loop_2();
            break;
   case 3:
            loop_3();
            break;
   case 4:
            break;
}


and after i have put some functions like these

Code:

void loop_1()
{
   while(1)
   {
      output_high(PIN_A0);
      delay_us(3);
      output_low(PIN_A0);
      delay_us(150-7);
   }
}
void loop_2()
{
   while(1)
   {
      output_high(PIN_A0);
      delay_us(3);
      output_low(PIN_A0);
      delay_us(300-7);
   }
}
void loop_1()
{
   while(1)
   {
      output_high(PIN_A0);
      delay_us(3);
      output_low(PIN_A0);
      delay_us(600-7);
   }
}


with this system it works, but...i dont like the space of rom that is using in the pic (is just a example i have 29 fuctions like these, all of them are the same functions with different delay times.
temtronic



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

View user's profile Send private message

PostPosted: Fri Jun 01, 2012 5:23 am     Reply with quote

generally speaking...

The early versions of the compiler did not allow for a variable to be the delay value....others will know when CCS changed this.
You might not be able to use a 16bit value ?

Also I'd just used fixed numbers(ie. delay_ms(143) not delay_ms(150-7)).
There _might_ be a problem doing the 'math' inside the delay..

Others that use that compiler will know the answers !
Huriz



Joined: 31 May 2012
Posts: 13

View user's profile Send private message

PostPosted: Fri Jun 01, 2012 5:31 am     Reply with quote

what do you mean with
Quote:
You might not be able to use a 16bit value ?


so, you mean that the problems could come from
- the early version of my compiler
- for do a math operation inside the delay
temtronic



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

View user's profile Send private message

PostPosted: Fri Jun 01, 2012 5:59 am     Reply with quote

You'll have to read the manual for your version of the compiler but ..
in the beginning..

you could only pass an 8 bit value for the delay_xx(nnn) function.Over the years CCS upgraded and allows 16 bit values to be used. I think they always allowed a fixed 16 bit value ie: delay_ms(12345) but NOT nnn=12345; delay_ms(nnn);

To prove is easy.

just try delay_ms(250), delay_ms(1000), nnn=250 delay_ms(nnn), nnn=1000 delay_ms(nnn)

in a small program and see what happens.

I don't have your version of the compiler so I can't test, it should take you 5-10 minutes to see what's happening.

Jay
Ttelmah



Joined: 11 Mar 2010
Posts: 19338

View user's profile Send private message

PostPosted: Fri Jun 01, 2012 7:35 am     Reply with quote

As a comment though, there are several things that are rather silly if trying to keep the size small.
Why not:
Code:

   tnum = read_EEPROM (0 );
   do {
      output_high(PIN_A0);
      delay_us(5);
      output_low(PIN_A0);
      switch (tnum) {
      case 1:
            delay_us(143);;
            break;
      case 2:
            delay_us(293);
            break;
      case 3:
            delay_us(593);
            break;
      case 4:
            break;
      }
   } while (TRUE);


Do a search here. I remember there being some problem with the delay code, on PIC12 chips, around your compiler version.

Best Wishes
Huriz



Joined: 31 May 2012
Posts: 13

View user's profile Send private message

PostPosted: Fri Jun 01, 2012 8:26 am     Reply with quote

Hi again, I have been doing more test around the int16, and yes, delay_us(int16) doesn't work fine.

I have solved it, thank to all people for help me and for give me new ideas about how solve my problem.

cheers!

Wink
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