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

Program Conversion from PIC18F452 to PIC18F458 Problem

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








Program Conversion from PIC18F452 to PIC18F458 Problem
PostPosted: Thu Jan 29, 2004 11:10 pm     Reply with quote

Mabuhay!

I am converting my code from 18f452 to 18f458 but I notice my ccp1 & ccp2 interrupts are not working.. I don't know why?

I'd like to ask for your help such that I can use 18f458. My ccp1 and ccp2 are both working in 18f452 chip.

The code below is my initialization for the chip... I guess miss something!!!

Code:


#int_timer0           // Timer0 Interrupt Service Routine
timer0_isr() {
   seconds++;         // This interrupt occurs every second
   ticxf = 1;         // set timer flag
 //set_timer0(26474); // 26473.5 offset for 1.0s time in DIV_128

#if Clock_40MHz
   set_timer0(26478); // 26482 adjusted for late of 12 seconds per day
#else
   set_timer0(26475); // 26479 with overhead compensation in Div_128
#endif
}

#int_timer1  // Overflows in 104.8576mS for 20MHz DIV_8 for CP1/CCP2
timer1_isr() {
   if (bstrt==1) {bstrt=0; brend=1; } // barcode end? when timer1 times out
}


#int_timer3                     // Timer3 Interrupt Service Routine
timer3_isr() {                  // Overflows in 13.2mS for 20MHz DIV_1
  if (cmpnd != 1) {
  if (rstrt == 1) {cmdrd = 1 ;  // Command read from RS-232
      rstrt = 0; }              // reset rx start flag to trigger once only
      output_low(TX_ENA);       // always listen Rx, after speaking Tx
  }
}

#int_EXT
 EXT_isr() {
 if (inkey == 0) inkey = 1;      // set IN key flag
 else
   disable_interrupts(INT_EXT); // prevent multiple trigger
 }

#int_EXT1
 EXT1_isr() {
 if (outky == 0) outky = 1;  // set OUT key flag
 else disable_interrupts(INT_EXT1); // prevent multiple trigger
 }

#int_ccp1            // CCP_1 is the time the signal goes from high to low
void isr_ccp1() {    // Captures Falling Edge
   if (bstrt == 1) iBarTable[barctr++] = CCP_1 ; // get_timer1();
   else bstrt = 1;   // Set start when first time data arrives
   set_timer1(0); }  // start timer1 from zero

#int_ccp2   // CCP_2 is the time the signal goes from low to high
void isr_ccp2() {
   if(spcectr<MAXSPC_CNT && chrff) iSpaceTable[spcectr++] = CCP_2; //get_timer1();
   else chrff=TRUE;  // end of one char
   set_timer1(0); }  // reset timer 1 for next capture to start in zero

#int_rda
void serial_isr() {               // Serial Interrupt Service Routine
   int t,cmpar;                   // local data storage
   t=getc();                      // get rx data and save to buffer
   if (cmpnd != 1) {
     if (rstrt == 0) {            // if no header or start yet
       rstrt = 1;                 // set header byte flag
       rxdtn = 0;                 // index starts with zero
       }
     rxpacket[rxdtn]=t ;          // and save to buffer
     rxdtn++;                     // increment index

#if USB_COM
     set_timer3(65064);           // for USB devices, shorter time-out
#else
     set_timer3(55536);           // for 2.010ms timeout in 20MHz DIV_1
#endif

  }
}


#int_tbe
void serial_txr() {               // Routine for RS-232 data transmit
   putc(txpacket[txout]);         // put data to tx buffer
   txout++;                       // increment tx out index
   txout=(txout) % TXBUF_SIZE;    // limit to max buffer size

   set_timer3(64000);             // for about 160uS tx timeout

   if(txdin==txout) {             // if last in data
     disable_interrupts(int_tbe); // stop tx interrupt
     txpnd = 0 ; }  // reset tx pending flag, end of tx string of data
}


#int_SSP

SSP_isr()  {                       // routine for I2C read or write

   if (t3sta == 0) {output_high(REDLED); t3sta = 1; }
   else {output_low(REDLED); t3sta = 0; }


void init_chip() { // Initialize the MCU Chip

  setup_adc_ports(NO_ANALOGS);

#if Clock_40MHz
  setup_timer_0(RTCC_INTERNAL | RTCC_DIV_256);
  setup_timer_1(T1_INTERNAL | T1_DIV_BY_8);
  setup_timer_2(T2_DISABLED,0,1);
  setup_timer_3(T3_INTERNAL | T3_DIV_BY_2);

#else
  setup_timer_0(RTCC_INTERNAL | RTCC_DIV_128);
  setup_timer_1(T1_INTERNAL | T1_DIV_BY_8);
  setup_timer_2(T2_DISABLED,0,1);
  setup_timer_3(T3_INTERNAL | T3_DIV_BY_1);
#endif

  ext_int_edge(H_TO_L);          // setup EXT int   High to Low edge
  ext_int_edge(1,H_TO_L);        // setup EXT int#1 High to Low edge

  enable_interrupts(int_timer0); // Enable timer0 interrupt
  enable_interrupts(int_timer1); // Enable timer1 interrupt
  enable_interrupts(int_timer3); // Enable timer3 interrupt

  enable_interrupts(int_rda);    // Rx serial receive interrupt

  setup_ccp1(CCP_CAPTURE_FE);    // Configure CCP1 to capture fall
  setup_ccp2(CCP_CAPTURE_RE);    // Configure CCP2 to capture rise

  enable_interrupts(INT_CCP1);   // Setup interrupt on falling edge
  enable_interrupts(INT_CCP2);   // Setup interrupt on falling edge

  enable_interrupts(INT_EXT);    // Enable external interrupt #0
  enable_interrupts(INT_EXT1);   // Enable external interrupt #1

  enable_interrupts(GLOBAL);     // Enable global interrupts
}



Need help or any relevant information such that my code will be ported to 18f458.

Thanx
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Fri Jan 30, 2004 3:00 pm     Reply with quote

Quote:
I am converting my code from 18f452 to 18f458 but I notice my ccp1 & ccp2 interrupts are not working.. I don't know why?

Look at the Microchip Line Card for the PIC microcontrollers
to quickly decide if one PIC is roughly compatible with another.
In your case, look at the "CCP/ECCP" column to find the answer.
http://www.microchip.com/download/lit/rlit/00148h4.pdf
ritchie



Joined: 13 Sep 2003
Posts: 87

View user's profile Send private message

PostPosted: Sun Feb 01, 2004 5:57 pm     Reply with quote

PCM programmer wrote:
Quote:
I am converting my code from 18f452 to 18f458 but I notice my ccp1 & ccp2 interrupts are not working.. I don't know why?

Look at the Microchip Line Card for the PIC microcontrollers
to quickly decide if one PIC is roughly compatible with another.
In your case, look at the "CCP/ECCP" column to find the answer.
http://www.microchip.com/download/lit/rlit/00148h4.pdf


With the PDF documents.. I found out that 18F458 has one(1) CCP and one(1) ECCP. Is there a difference in the coding of this two modules? would it be possible that anyone can share snippet in using this two module?

Thanx
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Sun Feb 01, 2004 7:09 pm     Reply with quote

Quote:
With the PDF documents I found out that 18F458 has one(1) CCP
and one(1) ECCP. Is there a difference in the coding of this two modules?
would it be possible that anyone can share snippet in using this two module?


With the 18F458, the 2nd CCP module is called "ECCP" and it's on
pin D4 (ie, it's on Port D).

But with the 18F452, the 2nd CCP is called "CCP2", and it's on either
pin C1 or B3 (it's selectable).

I don't have the latest version of PCH. I have vs. 3.178.
I compiled this sample program, as a test:

#include "18F458.h"
#fuses XT, NOWDT, NOPROTECT, BROWNOUT, PUT, NOLVP
#use delay(clock = 4000000)

//======================================
void main()
{
setup_ccp1(CCP_CAPTURE_RE);

setup_ccp2(CCP_CAPTURE_RE);

while(1);
}

Here is the ASM code produced by the compiler:
Code:
0000                00350 .................... setup_ccp1(CCP_CAPTURE_RE); 
0016 0EB7           00351 MOVLW  B7
0018 16B1           00352 ANDWF  FB1,F
001A 8494           00353 BSF    F94.2
001C 6ABD           00354 CLRF   FBD
001E 0E05           00355 MOVLW  05
0020 6EBD           00356 MOVWF  FBD
0000                00357 ....................   
0000                00358 .................... setup_ccp2(CCP_CAPTURE_RE); 
0022 0EB7           00359 MOVLW  B7
0024 16B1           00360 ANDWF  FB1,F
0026 8294           00361 BSF    F94.1
0028 6ABA           00362 CLRF   FBA
002A 0E05           00363 MOVLW  05
002C 6EBA           00364 MOVWF  FBA


Address 0xF94 is the TRISC register. Notice how it's setting bits 1 and 2
of TRISC to become inputs ? On a 18F452, that would be correct, but
on a 18F458 it's not correct. That's because there is no CCP module
on pin C1 of the 18F458. It's on pin D4 of the 18F458.

So at least with PCH vs. 3.178, the compiler is not setting up the ECCP
correctly. You would likely have to write your own routines to setup
and use the ECCP. I don't have such routines.
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