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

18F46k, 26k Gotcha - Got me ......

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



Joined: 20 Nov 2007
Posts: 2128
Location: albany ny

View user's profile Send private message AIM Address

18F46k, 26k Gotcha - Got me ......
PostPosted: Tue Jul 10, 2012 12:12 pm     Reply with quote

COMP VER 4.134

THe t1sosc SETUP WORKS IN A MYSTERIOUS WAY.

There is no fuse on these parts to force digital operation
and with fast_io() , if you set trisC(0xff) for all inputs
the default becomes to enable SOSC on RC0 as output.

The SAME as if you did a setup_timer_1() with SOSC ENABLED.

The only way to explicitly beat this weirdness is to do setup_timer_1(0);

But what is SO very weird is that Power on and cpu reset
seem to already shut OFF the T1OSCS pin feature by default.

After discovering this the hard way - I was hoping a more knowledgeable programmer could help me with the logic of it being this way ?

After all - if a feature is OFF by reset default - why would the compiler turn it ON - if I had made no ref to the T1 functions ???
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Tue Jul 10, 2012 2:37 pm     Reply with quote

Post a compilable test program that shows what you are trying to do
and explain how it fails.
asmboy



Joined: 20 Nov 2007
Posts: 2128
Location: albany ny

View user's profile Send private message AIM Address

PostPosted: Tue Jul 10, 2012 4:51 pm     Reply with quote

I am trying to use RC0 as an input.
Unless i disable or otherwise setup timer1,
it is clearly enabled as an OUTPUT by default.
VTVM answers that resoundingly.

Code:

// i have a 20 k pullup to 5V resistor on RC0
// if  PIC  is in SOSC mode, the pin is forced LOW as active OUTPUT
// however when it really IS an input it goes high
// my VTVM is the judge  ;-))

#include <18f26k22.h>
#Fuses  INTRC_IO,PLLEN,PRIMARY,NOFCMEN,NOIESO,PUT,
#Fuses  BROWNOUT,BORV29,NOWDT,
#Fuses  CCP2C1,NOPBADEN,CCP3B5
#Fuses  NOHFOFST,TIMER3B5,NOMCLR,
#Fuses  NOSTVREN,NOLVP,NOXINST,NODEBUG
#Fuses  NOPROTECT,NOCPB,NOCPD,NOWRT,NOWRTC
#Fuses  NOWRTB,NOWRTD,NOEBTR,NOEBTRB

#use fast_io(A)
#use fast_io(B)
#use fast_io(C)
#use fast_io(E)
#use delay( clock=64000000,INTERNAL )
#include <stdlib.h>

void HDW_init(void){
     output_a (0); output_b (0);  output_c (0); output_e (0);
     set_tris_a (0x3F); set_tris_b (0); 
     set_tris_c (0b11110011);  // RC0=INPUT , i wish .........
     set_tris_e (0xFF);  // all input - in reality RE3 = input for spill detect
     setup_timer_0(T0_INTERNAL|T0_DIV_256 );  // set for rollovers 1.05 secs
// EITHER one of the following two lines ADDED to the program fixes my  problem
//      setup_timer_1(T1_DISABLED);
//      setup_timer_1(T1_EXTERNAL|T1_DIV_BY_1);
     setup_timer_2( T2_DIV_BY_1, 255, 1 );       
     set_pwm1_duty(0);                      // 0% duty cycle on pin C2
     setup_ccp1(CCP_PWM);
     setup_adc_ports( NO_ANALOGS );
     setup_adc( ADC_OFF );
}
//******
MAIN() {
//******
  hdw_init();
  while (1){}
} // main end
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Tue Jul 10, 2012 5:40 pm     Reply with quote

I don't have your exact PIC but I have one in the same family. I compiled
the following program with vs. 4.134 and ran it on a PicDem2-Plus board.
I jumpered pin C0 to a 4.7K pullup resistor. I looked at Pin C0 with a
scope and it's at a high level (+5v). If I touch pin C0 with a 4.7K pull-
down resistor, the pin goes to 2.5v so it's definitely an input.
Code:

#include <18F45K22.h>
#fuses INTRC_IO,NOWDT,PUT,BROWNOUT,NOLVP
#use delay(clock=4M)

//======================================
void main(void)
{

while(1);
}
asmboy



Joined: 20 Nov 2007
Posts: 2128
Location: albany ny

View user's profile Send private message AIM Address

PostPosted: Tue Jul 10, 2012 5:48 pm     Reply with quote

with awareness of what bit me - and how to avoid it - no problem here either.

I was just curious if other fastio() users of this part had had my experience.

and willing to warn that there might be an issue if somebody in future searched on the part number
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Tue Jul 10, 2012 5:53 pm     Reply with quote

I apologize for missing the fast i/o part. I re-did the test with fast i/o
and got the same results. Pin C0 still comes up as an input for me. From
your text, I get that it's not a problem anymore so I'll leave it at that.
Code:

#include <18F45K22.h>
#fuses INTRC_IO,NOWDT,PUT,BROWNOUT,NOLVP
#use delay(clock=4M)

#use fast_io(C)

//======================================
void main(void)
{


while(1);
}
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