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

PIC18F4620 configuration

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







PIC18F4620 configuration
PostPosted: Thu Nov 06, 2008 3:22 am     Reply with quote

i'm having problems getting PIC18F4620 to work.
I've ran a test program using internal oscillator set for 8MHz with PLL enabled.
I set up Timer2 to interrupt every 100µs.
just to test it, i've set RB0, RC0, RD0 to toggle. It worked on the first power up but failed on subsequent tries.

i think configuration setting is wrong. even MPLAB simulator failed citing 'CORE-E0001: Stack over flow error occurred from instruction at 0x00004e'


register configuration using CCS
Code:



INTRC_IO, NOFCMEN, NOIESO, PUT, BROWNOUT, BORV43, NOWDT, WDT1, CCP2C1, NOPBADEN, LPT1OSC, NOMCLR, STVREN, NOLVP, NOXINST, NODEBUG, NOPROTECT, NOCPB, NOCPD, NOWRT, NOWRTC, NOWRTB, NOWRTD, NOEBTR, NOEBTRB



   OSCTUNE = 0b01000000;   //internal PLL
   //OSCCON  = 0b01110000;   //internal osc select, 8MHz
      IRCF2 = 1;
      IRCF1 = 1;
      IRCF0 = 1;
   //RCON    = 0b11011100;   //interrupt priority, BOR enabled
      IPEN = 1;
      SBOREN = 1;
   //STKPTR   = 0b00000000;
   //STATUS   = 0b00000000;
   //EECON1   = 0b00000000;


   ADCON0   = 0b00000000;
   ADCON1   = 0b00001111;   //all A/D port set as digital
   ADCON2   = 0b00000000;
   TRISA   = 0b00000000;   //all output
   TRISB   = 0b00000000;   //all output
   TRISC   = 0b00000000;   //all output
   TRISD   = 0b00000000;   //all output
   TRISE   = 0b00000000;   //all output
        PORTA      = 0b00000000;   //Initialize port default output state
   PORTB      = 0b00000000;
   PORTC      = 0b00000000;
   PORTD      = 0b11111111;
   PORTE       = 0b00000111;   

   T0CON   = 0b01001000;   //prescale not assigned, TMRO stop, 8-bit
   T1CON   = 0b01000000;
   T2CON   = 0b00000000;
   T3CON   = 0b00000000;

   CCP2CON   = 0b00000000;
   CCP1CON   = 0b00000000;
   //PWM1CON   = 0b00000000;//
   //ECCP1AS   = 0b00000000;
   //SSPSTAT   = 0b00000000;
   SSPCON1   = 0b00000000;
   //SSPCON2   = 0b00000000;
   TXSTA   = 0b00000000;
   RCSTA   = 0b00000000;
   BAUDCON   = 0b00000000;
   //CMCON   = 0b00000111;
   //CVRCON   = 0b00000000;
   //HLVDCON   = 0b00000101;
   //WDTCON   = 0b00000000;


   INTCON    = 0b10000000;   //enable high & disable low priority interrupt, disable TMR0 interrupt
   INTCON2   = 0b10000000;   //PORTB pullups disable, TMR0 set low priority
   INTCON3 = 0b00000000;
   //PIR1   = 0b00000000;
   //PIR2   = 0b00000000;
   PIE1   = 0b00000010;   //enable TMR2 interrupt
   //PIE2   = 0b00000000;
   IPR1   = 0b00000010;   //TMR2 interrupt high priority
   //IPR2   = 0b00000000;



   PR2      = 199;         //Initialize for 1000µs
   T2CON   = 0b00000001;   //1:1 postscale, 1:4 prescale
      TMR2ON = 1;
Ttelmah
Guest







PostPosted: Thu Nov 06, 2008 4:15 am     Reply with quote

The PLL enable, will depend on your clock setting. CCS, combines this with the fuse data, to select the right combination. You don't show this.

The configuration of the registers, is not 'CCS dependent', but how the chip wakes up in general.

Try something really simple:
Code:

#include <18F4620.h>
#device adc=8
#FUSES NOWDT, WDT128, INTRC_IO, NOPROTECT, NOIESO, BROWNOUT, BORV21, PUT, NOCPD, STVREN, NODEBUG, NOLVP, NOWRT, NOWRTD, NOEBTR, NOCPB, NOEBTRB, NOWRTC, NOWRTB, FCMEN, NOXINST, PBADEN, LPT1OSC, NOMCLR
#use delay(clock=32000000)

void main(void) {
   setup_adc_ports(NO_ANALOGS|VSS_VDD);
   setup_adc(ADC_OFF|ADC_TAD_MUL_0);
   setup_psp(PSP_DISABLED);
   setup_spi(SPI_SS_DISABLED);
   setup_wdt(WDT_OFF);
   setup_comparator(NC_NC_NC_NC);
   while (TRUE) {
      output_high(PIN_B0);
      output_high(PIN_C0);
      output_high(PIN_D0);
      delay_ms(1);
      output_low(PIN_B0);
      output_low(PIN_C0);
      output_low(PIN_D0);
      delay_ms(1);
   }
}

If this doesn't toggle the pins, at just under 500Hz, you have a hardware problem.

However your fault message, sounds like a code problem, _not_ a fuse problem. It is what you would expect if you have a lot of routines being called, and not returning properly, or somthing corrupting the stack.

Best Wishes
guestplanet
Guest







PostPosted: Fri Nov 07, 2008 8:52 am     Reply with quote

thanks. your reply actually reminded myself of going back to basics.
i reviewed the program again and found that i've excluded an 'include' file.
silly me. wasted a whole day.
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