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

pic16f strange problem with code please help..

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







pic16f strange problem with code please help..
PostPosted: Thu Jan 07, 2010 5:49 am     Reply with quote

hi
i need to make this code work (i want my job ! Smile )

i wrote the next program using pic16f690 and pickit2, and problems are

1. the condition on pin c6 and c7 is to work in low but even that they have a pull-up resistor they some how considered as low and operate their FOR loop ? why ?

2. why are pins a0 a1 and a5 are allways on low when they should be on high ? why i allways having problem with port A to be output??

Thanks for answers.

Code:

#include<16f690.h>
#fuses HS,NOWDT,NOPROTECT,PUT,BROWNOUT,MCLR,NOCPD
#USE DELAY(CLOCK=31000)



#define step11 (output_high(pin_a0)) ,delay_ms(10) ;  //steps
#define step12 (output_high(pin_a1)) ,delay_ms(10) ;
#define step13 (output_high(pin_a2)) ,delay_ms(10) ;
#define step14 (output_high(pin_a5)) ,delay_ms(10) ;

#define step21 (output_high(pin_c0)) ,delay_ms(10) ;
#define step22 (output_high(pin_c1)) ,delay_ms(10) ;
#define step23 (output_high(pin_c2)) ,delay_ms(10) ;
#define step24 (output_high(pin_c3)) ,delay_ms(10) ;

#define step31 (output_high(pin_b4)) ,delay_ms(10) ;
#define step32 (output_high(pin_b4)) ,delay_ms(10) ;
#define step33 (output_high(pin_b4)) ,delay_ms(10) ;
#define step34 (output_high(pin_b4)) ,delay_ms(10) ;

int i ;


VOID MAIN()

{

setup_adc_ports(NO_ANALOGS|VSS_VDD);
setup_adc(ADC_OFF);
setup_spi(SPI_SS_DISABLED);
setup_comparator(NC_NC_NC_NC);//  currently not supported by the PICWizard


SETUP_CCP1(CCP_PWM);
SETUP_TIMER_2(T2_DIV_BY_16,100,1); //set to xhz
setup_oscillator(OSC_31KHZ);


WHILE(1)

{

// ########### condition for pwm operation

if (input(pin_a3)==0) 

   set_pwm1_duty(50);
   
   
//############# conditions for steps motors.



if (input(pin_c4)==0 ) 
{
  for(i=0;i<41;i++)
    {
      step11;
      step12;
      step13;
      step14;
    }
   output_high(pin_a4);
   delay_ms(250);
   output_low(pin_a4);
   i=0;
}




if (input(pin_c6)==0 ) 
{
  for(i=0;i<41;i++)
    {
      step21;
      step22;
      step23;
      step24;
    }
   output_high(pin_a4);
   delay_ms(250);
   output_low(pin_a4);
   i=0;
}


if (input(pin_c7)==0 ) 
{
  for(i=0;i<41;i++)
    {
      step31;
      step32;
      step33;
      step34;
    }
   output_high(pin_a4);
   delay_ms(250);
   output_low(pin_a4);
   i=0;
}


}  // to while1

} // to end
Ttelmah
Guest







PostPosted: Thu Jan 07, 2010 6:41 am     Reply with quote

Some comments:
1) Select the right clock fuse. INT_RC, or INTRC_IO. The only reason it is running at all, is either that you have a crystal attached, or that it is doing a 'fail safe' clock switch. Youu are telling it to start, using the HS oscillator....

2) Get rid of the trailing ';' on your defines. You are adding ';'s after the instructions, so these are redundant.

3) Look at what options do?. Does disabling the 'slave select', look like an instruction to turn off the SPI?. Easiest thing just to remove the line entirely. For most peripherals, the defualt is to wake up deselected...

4) Are you sure that your compiler version does turn off the comparator properly?. The comment that the wizard does not know about the disable comparator line, suggests it may not. Simply try manually turning the comparator off. PCM_programmer has posted code for doing this in the past.

Best Wishes
jenn
Guest







thanks a lot
PostPosted: Thu Jan 07, 2010 8:46 am     Reply with quote

thanks a lot.
I did what you said but the port A is just not working, while other ports are ok.

why i always having a problems with A ?

maybe its because he is interrupt port ???

I didn't find how to disable comparators handly ..
Ttelmah
Guest







PostPosted: Thu Jan 07, 2010 10:18 am     Reply with quote

Further comments then.
Pin A3, is the MCLR input. You have MCLR enabled in your fuses. How is this going to work.....
Pin A4, and A5, are the oscillator pins, and will _only_ become available, with INTRC_IO selected.
Add 'NOLVP' to your fuses. Pins A0, and A1, are the LVP programming pins. Should default to off, but make sure.
Basically, you _must_ read the data sheet, and ensure that your settings match what you want to do.

Best Wishes
mkuang



Joined: 14 Dec 2007
Posts: 257

View user's profile Send private message Send e-mail

PostPosted: Thu Jan 07, 2010 10:25 am     Reply with quote

Ttelmah wrote:
Further comments then.

Pin A4, and A5, are the oscillator pins, and will _only_ become available, with INTRC_IO selected.
Best Wishes


Do you mean pins A4 and A5 will only become available with INTRC selected? Selecting INTRC_IO will put the internal oscillator signals on those two pins, no? In other words if you select INTRC_IO you will see a 32Khz signal on these pins when measured with a scope.
ckielstra



Joined: 18 Mar 2004
Posts: 3680
Location: The Netherlands

View user's profile Send private message

PostPosted: Thu Jan 07, 2010 3:49 pm     Reply with quote

Chapter 3.1 of the PIC16F690 datasheet:
INTRC = Internal oscillator with FOSC/4 output on A4 and I/O on A5.
INTRC_IO = Internal oscillator with I/O on both A4 and A5.
LP = external 32kHz crystal inputs on A4 and A5
XT = external 0.1 - 4MHz crystal inputs on A4 and A5
HS = external 4 - 20MHz crystal inputs on A4 and A5
EC_IO = External clock input on A5 with I/O on A4.
RC – External Resistor-Capacitor (RC) on A5 with FOSC/4 output on A4.

Quote:
In other words if you select INTRC_IO you will see a 32Khz signal on these pins when measured with a scope.
No, you only get clock frequency outputs with the INTRC and RC selections. The frequency of the clock output is internal_clock / 4, so for 32kHz you would have to use a 128kHz clock source and the closest available internal clock frequency is 125kHz.
JENN
Guest







THANK YOU
PostPosted: Mon Jan 11, 2010 3:00 am     Reply with quote

Thanks I have done this changes its now better, BUT

pin A0 A1 refuse to work.

I have tried to add a fuse called NOLVP and compiler says its eror ???
WHY CANT I ADD THIS FUSE ? HE SAYS "UNKNOWN KEYWORD" .
WHAT ELSE CAN CAUSE A0 A1 NOT BEING OUTPUT PORTS ?

TX.
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Mon Jan 11, 2010 12:48 pm     Reply with quote

Look near the top of this file. It lists all available fuses for the 16F690.
If you can't set a fuse, then it's because its not available.
Quote:
c:\program files\picc\devices\16f690.h


Pins A0 and A1 are used by the ICD to program or debug the 16F690.
Do you have an ICD connected to those pins ?


If that doesn't help, then post your compiler version.
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