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

PIC 16F1827 not running

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



Joined: 09 Sep 2010
Posts: 11
Location: Ely, UK

View user's profile Send private message Visit poster's website

PIC 16F1827 not running
PostPosted: Thu Apr 14, 2011 7:07 am     Reply with quote

Hi,

I am working on a project using a PIC 16F1827, using it's internal oscillator
running at 8MHz. I can download firmware into the micro and verify that the code
has successfully been programmed. However the code does not appear to be
running. I have verified this by writing code to toggle a pin and have viewed
this pin on an oscilloscope. I have pasted my code below. Could someone
enlighten me as to what I may be doing wrong.

I am using the CCS PCM C compiler from MPLAB 8.63.

Thanks in advance

Andrew Ellis

Code:

// main.c
// Set up the processor

#include <16F1827.h>
#fuses INTRC_IO,PLL,PUT,BROWNOUT,NOMCLR
#fuses NOIESO,NOFCMEN,NOCLKOUT,NOLVP,NODEBUG,BORV25,NOSTVREN

#use delay(clock=8000000)

void main()
{
    setup_oscillator(OSC_8MHZ | OSC_INTRC | OSC_PLL_ON);
    // Setup port B; 0 - output, 1 - input
   set_tris_b(0xC6);

   while (1)
   {
       output_bit(PIN_B3, ~input(PIN_B3));
   }
}

_________________
Kind regards

Andrew Ellis
AJEFenConsultancy



Joined: 09 Sep 2010
Posts: 11
Location: Ely, UK

View user's profile Send private message Visit poster's website

PostPosted: Thu Apr 14, 2011 7:09 am     Reply with quote

I forgot to add that I haves ensured that /MCLR is pulled high with a 1k resistor.
_________________
Kind regards

Andrew Ellis
gaugeguy



Joined: 05 Apr 2011
Posts: 303

View user's profile Send private message

PostPosted: Thu Apr 14, 2011 8:03 am     Reply with quote

B3 is an analog pin by default, so it will always read as a 1 and the output will always be a 0. You need to disable all analog modules associated with this pin to use it as a digitial I/O.
Wayne_



Joined: 10 Oct 2007
Posts: 681

View user's profile Send private message

PostPosted: Thu Apr 14, 2011 8:08 am     Reply with quote

also
output_toggle(PIN_B3);

should work just as well Smile

And set_tris should not be required in this situation.
AJEFenConsultancy



Joined: 09 Sep 2010
Posts: 11
Location: Ely, UK

View user's profile Send private message Visit poster's website

PostPosted: Thu Apr 14, 2011 10:46 am     Reply with quote

Hi guys,

thank you very much for your replies.

Unfortunately I'm no further forward.

My code now reads:
Code:

// main.c
// Set up the processor

#include <16F1827.h>
#fuses INTRC_IO,PLL,PUT,BROWNOUT,NOMCLR
#fuses NOIESO,NOFCMEN,NOCLKOUT,NOLVP,NODEBUG,BORV25,NOSTVREN

#use delay(clock=8000000)

void main()
{
    setup_oscillator(OSC_8MHZ | OSC_INTRC | OSC_PLL_ON);
    SETUP_ADC_PORTS(NO_ANALOGS);

   while (1)
   {
      output_toggle(PIN_B3);
   }
}


Interestingly if I run the code through the debugger it works fine, and I can observe pin B3 toggling. Is there a subtle option I have missed?

Regards

Andrew
_________________
Kind regards

Andrew Ellis
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Thu Apr 14, 2011 11:48 am     Reply with quote

Quote:
I am using the CCS PCM C compiler from MPLAB 8.63.

That's the MPLAB version. What's the compiler version ?

It's given at the top of the .LST file, which will be in your project directory
after a successful compilation. Example of compiler version numbers:
http://www.ccsinfo.com/devices.php?page=versioninfo
jeremiah



Joined: 20 Jul 2010
Posts: 1349

View user's profile Send private message

PostPosted: Thu Apr 14, 2011 11:50 am     Reply with quote

try putting a delay in your loop with the toggle statement:

delay_ms(1000);

for example:

Code:

while (1)
   {
      output_toggle(PIN_B3);
      delay_ms(1000);
   }
temtronic



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

View user's profile Send private message

PostPosted: Thu Apr 14, 2011 6:14 pm     Reply with quote

Did you set the 'build configuration' to 'release' from 'debug' then recompile (F10) BEFORE burning the PIC ?
AJEFenConsultancy



Joined: 09 Sep 2010
Posts: 11
Location: Ely, UK

View user's profile Send private message Visit poster's website

PostPosted: Fri Apr 15, 2011 3:14 am     Reply with quote

Hi,

Thank you for your replies.

The version of the compiler I'm using is 4.108.

I have tried changing the build from "Debug" to "Release", but that hasn't helped, I have also tried putting a delay in my loop, but these didn't work.

I have added the line:

#fuse CLKOUT

and observed pin 15 with a scope, but there is no clock pulse on that pin.

Does anyone have any further ideas please.

Thanks

Andrew
_________________
Kind regards

Andrew Ellis
Ttelmah



Joined: 11 Mar 2010
Posts: 19520

View user's profile Send private message

PostPosted: Fri Apr 15, 2011 4:30 am     Reply with quote

Start by 'stepping back'. Since you are working 'through' MPLAB, start with the basic program:
Code:

#include <16F1827.h>
#device adc=8
#FUSES NOWDT, INTRC_IO, PUT, NOPROTECT, NOMCLR, NOCPD, BROWNOUT, IESO, FCMEN,
#FUSES CLKOUT, NOWRT, NOVCAP, STVREN, BORV25, NODEBUG, NOLVP, RESERVED
#use delay(clock=8000000)

void main()
{
   setup_adc_ports(NO_ANALOGS);
   setup_spi(FALSE);
   setup_comparator(NC_NC_NC_NC);
   setup_vref(FALSE);
   do {
      output_toggle(PIN_B3);
      delay_ms(1);
   } while(TRUE);
}

Now some comments about the changes here:
CLKOUT, to give a test output - good idea.
You cannot have clock=8MHz, and PLL_EN. If you enable the PLL, your clock becomes 32MHz.
You always want STRVEN. If the stack overflows, the code _will_ crash. STRVEN, at least gives some chance of recovery....

Compile this.
Then go into the 'Configure', 'Configuration bits' window, and verify that the tick box 'Configuration bits set in code' is made. Then look at how the fuses _are_ set. They should show:

INTOSC oscillator, I/O function on RA7/OSC1/CLKI
WDT disabled
PWRT enabled
RA5/MCLR/Vpp pin function is digital input
Program memory code protection is disabled
Data memory code protection is disabled
Brown-out Reset enabled
CLKOUT function is enabled on RA6/CLKOUT pin
Internal/External switchover mode is disabled
Fail-safe Clock Monitor is disabled
Write protection off
4x PLL disabled
Stack overflow or underflow will cause a reset
Brown-out Reset Voltage (VBOR) sert to 2.7v
High voltage on MCLR/VPP must be used for programming.

Now, if these are _not_ set like this, then this is the heart of your problem. Turn off the 'set in code' tick box, and correct them.

Now I have compiled this with your compiler version, and the fuses are set correctly, and the chip merrily gives a 500Hz output on B3.

Best Wishes
AJEFenConsultancy



Joined: 09 Sep 2010
Posts: 11
Location: Ely, UK

View user's profile Send private message Visit poster's website

PostPosted: Fri Apr 15, 2011 7:42 am     Reply with quote

Hi Ttelmah,

Thank you for your help.

My code is up and running now Very Happy

Andrew
_________________
Kind regards

Andrew Ellis
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