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

Issue with internal oscillator on PIC12F675

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



Joined: 14 Dec 2010
Posts: 10

View user's profile Send private message

Issue with internal oscillator on PIC12F675
PostPosted: Wed Dec 15, 2010 3:41 am     Reply with quote

Hello guys,

I'm trying to create a blink led program for a 12f675 using CCS. Problem is i can only get the led's to register to the first state in the program, thus, no blinking, just on/off depending on the first state of the pin declared in the main loop.

I tested this with a blinkled program in MPLAB and it works fine so the issue is with CCS, not the PIC. The code is below. Any ideas would be much apreciated.

Code:
#include "D:\Pic\test2.h"
void main()
{
   port_a_pullups(TRUE);
   setup_adc_ports(NO_ANALOGS|VSS_VDD);
   setup_adc(ADC_CLOCK_DIV_2);
   setup_timer_0(RTCC_INTERNAL|RTCC_DIV_1);
   setup_timer_1(T1_DISABLED);
   setup_comparator(NC_NC);
   setup_vref(FALSE);

   #use delay(clock=20000000)

int foo;
  foo=1;
   while (foo==1)
  {
         
          output_high(PIN_A5);
          output_low(PIN_A4);
          output_high(PIN_A3);
          output_low(PIN_A2);
          output_high(PIN_A1);
          output_low(PIN_A0);
          delay_ms(500);     
         
          output_low(PIN_A5);
          output_high(PIN_A4);
          output_low(PIN_A3);
          output_high(PIN_A2);
          output_low(PIN_A1);
          output_high(PIN_A0);
          delay_ms(500);       
  }
}



Below is the header file
Code:

#include <12F675.h>
#device adc=8

#FUSES NOWDT                    //No Watch Dog Timer
#FUSES INTRC_IO                 //Internal RC Osc, no CLKOUT
#FUSES NOCPD                    //No EE protection
#FUSES NOPROTECT                //Code not protected from reading
#FUSES MCLR                     //Master Clear pin enabled
#FUSES NOPUT                    //No Power Up Timer
#FUSES NOBROWNOUT               //No brownout reset
#FUSES BANDGAP_HIGH         
#FUSES RESERVED                 //Used to set the reserved FUSE bits

#use delay(clock=20000000)


I couldn't really find anything to solve this on the forum, please point me in the right direction if there is a thread i missed that could help.
Wayne_



Joined: 10 Oct 2007
Posts: 681

View user's profile Send private message

PostPosted: Wed Dec 15, 2010 5:30 am     Reply with quote

I expect your 500ms delay is more like 500 seconds! (exageration)

You are using INTRC (internal rc clock) and you have #use delay(clock=20000000)

I doubt very much the internal clock on that pic can run at 20MHz!

I am having trouble accessing the datasheet at the moment so someone else will have to confirm this.
victor_constantin



Joined: 14 Dec 2010
Posts: 10

View user's profile Send private message

PostPosted: Wed Dec 15, 2010 5:38 am     Reply with quote

Yes, you are right, it's a 4Mhz oscillator. However, i now changed that setting to #use delay(clock=4M) but to no avail.
Geps



Joined: 05 Jul 2010
Posts: 129

View user's profile Send private message

PostPosted: Wed Dec 15, 2010 6:41 am     Reply with quote

Code:
int foo;
  foo=1;
   while (foo==1)
  {


What's the purpose of this? It looks messy and overcomplicates the program.

Code:

   while (TRUE)
  {


Try changing
Code:
#FUSES MCLR 
to
Code:
#FUSES NOMCLR 
Geps



Joined: 05 Jul 2010
Posts: 129

View user's profile Send private message

PostPosted: Wed Dec 15, 2010 6:42 am     Reply with quote

Another point, you don't need

Quote:
#use delay(clock=20000000)
in both header and source file - unless using two sets of delays. Since you're not, just delete one.
victor_constantin



Joined: 14 Dec 2010
Posts: 10

View user's profile Send private message

PostPosted: Wed Dec 15, 2010 5:09 pm     Reply with quote

Sorry for the late reply and thanks for the answers. However, i wasn't able to solve the issue, the program still runs in the same way. Any other ideas?

From what i've gathered so far, the problem is with the internal clock, the PIC seems to get hung as soon as it hits the delay instruction.
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Wed Dec 15, 2010 5:20 pm     Reply with quote

1. What is your CCS compiler version ? It's a 4-digit number (only)
and is given at the top of your .LST file, which will be in your project
directory after a succesful compilation of your project.

2. Do you have a pull-up resistor on the MCLR pin of the PIC ?
What is the value of the resistor ?

3. What is the Vdd voltage of the PIC ?

4. Do you have a series resistor in your LED circuit ?
Example:
Code:

pin      330 ohms      LED       
GP2  ----/\/\/\/------->|----
                            |
                            |
                          -----  Ground 
                           ---
                            -


My advice is, don't try to to light up 5 LEDs. Disconnect all, except one.
victor_constantin



Joined: 14 Dec 2010
Posts: 10

View user's profile Send private message

PostPosted: Wed Dec 15, 2010 5:27 pm     Reply with quote

Hello,

1. Version is 4.104

2. No resistor in series with the MCRL pin. What would be the correct value? What would be the correct way to wire it?

3. Vdd voltage is 5.5V

4. Yes, there is a resistor. As i've stated in the first post, the circuit is functional, tested with another program in MPLAB. Only two LED"s connected at the current time but it works with all connected.
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Wed Dec 15, 2010 5:39 pm     Reply with quote

If you're using the NOMCLR fuse, you don't need the MCLR resistor.

What pins do you have LEDs attached to on the PIC ? What pin numbers ?

Why is your Vdd set at +5.5v ? Why not use the usual voltage of +5.0v ?
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Wed Dec 15, 2010 6:20 pm     Reply with quote

I don't have time to wait for your reponse on the LED pins.
I just want to get this done.

I installed vs. 4.104 of the compiler. I used a Pickit2 Low Pin Count
board for this test. I removed the 16F690 from the board's socket and
installed a 12F675 in the upper portion of the socket. I added a jumper
wire from pin RA2 on the board (GP2) to an LED on the board.
I then compiled and loaded this program with the Pickit2. It works.
It blinks the LED:
Code:

#include <12F675.h>
#fuses INTRC_IO, NOWDT, PUT, BROWNOUT, NOMCLR
#use delay(clock=4000000)

#define GP0   PIN_A0
#define GP1   PIN_A1
#define GP2   PIN_A2
#define GP3   PIN_A3
#define GP4   PIN_A4
#define GP5   PIN_A5

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

while(1)
  {
   output_high(GP2);  // Blink LED on pin GP2
   delay_ms(500);
   output_low(GP2);
   delay_ms(500);

  }

}
victor_constantin



Joined: 14 Dec 2010
Posts: 10

View user's profile Send private message

PostPosted: Thu Dec 16, 2010 3:18 am     Reply with quote

Hello, sorry for the late response. I managed to fix it after all, the problem was indeed with the NOMCLR. Thanks alot guys.
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