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

PIC16F688 oscillator, portc issues

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



Joined: 28 Jul 2006
Posts: 4

View user's profile Send private message

PIC16F688 oscillator, portc issues
PostPosted: Fri Jul 28, 2006 12:51 pm     Reply with quote

Hello,

I am trying to program my PIC16F688 with the PCM compiler. However I am encoutering a few issues :

1. I can configure the PIC to run on the internal clock but the frequency of the clock does not seem to change no matter what value is set in the "setup_oscillator()" function (it stays at 4Mhz apparently)

2. I cannot get my portC to output anything even though I turn the ADC off and set all the ports to no_analog. I also have the "setup_comparator()" to NC_NC

I tried to program the PIC with MPLAB in assembly language and it seems to work fine there. So I am wondering if I am doing something wrong or if it has to do with the header file (I am using PCM ver. 3.184)

Thank you for your help.
rnielsen



Joined: 23 Sep 2003
Posts: 852
Location: Utah

View user's profile Send private message

PostPosted: Fri Jul 28, 2006 1:00 pm     Reply with quote

Post a complete, but _small_, test program so we can see what you are trying to do. Include the .h file that has your Fuse statements as well.
Flo



Joined: 28 Jul 2006
Posts: 4

View user's profile Send private message

PostPosted: Fri Jul 28, 2006 1:14 pm     Reply with quote

Hi,

Here it is my test program:

Code:

#include <16f688.h>
#device adc=16
#use delay(clock=8000000)
#fuses INTRC,NOWDT,PUT,NOPROTECT

void main()
{
 
   setup_oscillator(OSC_8MHZ);
   setup_adc(ADC_OFF);
   setup_adc_ports(no_analogs);
   setup_comparator(NC_NC_NC_NC);

   while(true)
   {
      delay_ms(1000);
      output_high(PIN_C1);
      delay_ms(1000);
      output_low(PIN_C1);

   }

}


Is there anything wrong with it ?
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Fri Jul 28, 2006 3:24 pm     Reply with quote

Minor problems in your code:
1. The #use delay() statement should be placed on the line after
the #fuses statement. If you do that, the compiler will automatically
put in code to setup the internal oscillator, when the INTRC or
INTRC_IO fuse is used.
2. The #device adc=16 will left-justify the 10-bit A/D result in a 16-bit
word. It won't make the A/D into a 16-bit A/D. (Just in case you
didn't know that).

None of the above problems will affect your program, in terms of
operation. It should run. I don't have a 16F688. I modified the
program slightly and compiled it with vs. 3.184 for the 16F88 and
it ran OK.

I looked at the .LST file for vs. 3.184 with a 16F688. There's a little
problem in the start-up code. It doesn't turn off the comparators
correctly. It write to ADCON0 by mistake. However, your subsequent
code fixes that, and the .LST file looks good for that code. All analog
pins in ANSEL are configured for digitial i/o and the comparators are
shut off and configured as digital pins.

There's a contradiction in your post. You say that you can't change
to 8 MHz speed, but then you say toggling of Pin C1 doesn't work.
If it doesn't work, then how can you check the toggle speed and then
determine that you're stuck at 4 MHz mode ? Maybe you tested it
on a Port A pin. My opinion is that your program should work.
I wonder if you have a pull-up resistor on the MCLR pin. You need one.
Also, if you don't have a series resistor with LED on pin C1, then the
program might not work. Use 270 to 470 ohms.
Flo



Joined: 28 Jul 2006
Posts: 4

View user's profile Send private message

PostPosted: Fri Jul 28, 2006 3:48 pm     Reply with quote

Thank you for your reply,

The way I check the speed of the oscillator is by looking at PIN_A4 (FOSC/4)

I don't have any LED, I am using an oscilloscope to check the output (output is not connected to anything).

As for the pull up resistor on MCLR, I am using a 47k resistor.

I was wondering if I could write a portion in assembly language and insert it in the program, or if I could target a specific address in memory using a C command (Does this compiler handles pointers ?).

That way I could make sure of what is going in the registers.

Does anyone know how to do that ?
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Fri Jul 28, 2006 4:26 pm     Reply with quote

You can use #byte statements to specify the addresses of PIC registers,
and then write lines of C code to write directly to the registers.

My opinion is, your problem is something else. I don't think it's the code.

What programmer are you using ? Do you guarantee that it's
programming the code and the Config bits correctly ?

Also, are you sure you're programming the PIC with the proper HEX file ?
Are you loading the HEX file from the CCS project folder ?
Flo



Joined: 28 Jul 2006
Posts: 4

View user's profile Send private message

PostPosted: Mon Jul 31, 2006 7:49 am     Reply with quote

I am using I am using IDE ver. 3.41 and PCM ver. 3.184 for the compiler and the ICD-U40 programmer with the version 1.39 of the firmware for PIC16 and PIC18 targets.

The fact is that I successfuly programmed the microcontroller with the same programmer and with hex files generated from Mplab and that the programmer does not give me any writing error after programming the chip.

What it does tell me though is that the programming mode I am using is too fast (5v only). However I do not have the option of changing the speed for that specific microcontroller.
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