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

Interrupt problem in pic 18f2550 with usb bootloader

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



Joined: 08 Jun 2010
Posts: 9

View user's profile Send private message

Interrupt problem in pic 18f2550 with usb bootloader
PostPosted: Wed Jun 09, 2010 2:29 pm     Reply with quote

Hi .. I'm trying to fire an interrupt with timer 0 in my PIC 18f2550 but I'm not being successful.
I'm trying initial to flash an led with 1 second delay. I'm using an bootloader to program the pic with the c code and I'm using an external crystal with 20MHz.

I do the following calculations: Tout=1 sec, so Fout=1Hz
(20000000/4)/128 =39062/256 =152,58 approx = 153

I'm using this code:
Code:

#include <18f2550.h>
 
#fuses HSPLL,NOWDT,NOBROWNOUT,NOPROTECT,NOLVP,NODEBUG,USBDIV,PLL5,CPUDIV1,VREGEN,MCLR,NOPBADEN,WRTB,CPB

#use delay(clock=48000000)

#use  RS232(baud=9600, parity=N, bits=8, xmit=PIN_C6,rcv=PIN_C7) // configura serial
 // serial configurada para velocidade de 9600 bps
 // sem paridade, 8 bits


#build(reset=0x800, interrupt=0x808)
#org 0x000, 0x7ff { }


#define LED1 PIN_C0
#define LED2 PIN_C1
#define LED3 PIN_C2

#define HIGH_START 153
byte seconds, high_count;

#int_timer0


clock_isr() {
   if(--high_count==0) {
//   printf("test2");
      output_high(LED1);
      delay_us(5);
      output_low(LED1);
      high_count=HIGH_START;
   }
}

main() {
   high_count=HIGH_START;
   set_timer0(0);
   setup_timer_0(RTCC_EXT_H_TO_L | RTCC_DIV_128 | RTCC_8_BIT);   
   enable_interrupts(INT_TIMER0);
   enable_interrupts(GLOBAL);
//output_high(LED1);
printf("test2");
   while(TRUE);
}


Anyone have an idea where is the problem? Thanks in advance.
mkuang



Joined: 14 Dec 2007
Posts: 257

View user's profile Send private message Send e-mail

PostPosted: Wed Jun 09, 2010 2:32 pm     Reply with quote

How do you get 48Mhz from an external crystal of 20 Mhz? Make sure you are setting the right pre-scaler values for the external clock (page 31 of the datasheet).
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Wed Jun 09, 2010 2:45 pm     Reply with quote

The PIC will be running at 48 MHz, due to the PLL being used.
The PLL5 fuse divides the 20 MHz down to 4 MHz, which is required
by the PLL. The PLL then generates 96 MHz, which is divided down
to 48 MHz to run the PIC.

See the sample programs in this thread below, which show how to run
the PIC at 20 MHz, and at 48 MHz. For USB, you should use 48 MHz.
http://www.ccsinfo.com/forum/viewtopic.php?t=42223&start=1
Note: You are already running it at 48 MHz in your posted code.
zeronix



Joined: 08 Jun 2010
Posts: 9

View user's profile Send private message

PostPosted: Wed Jun 09, 2010 3:09 pm     Reply with quote

PCM programmer wrote:
The PIC will be running at 48 MHz, due to the PLL being used.
The PLL5 fuse divides the 20 MHz down to 4 MHz, which is required
by the PLL. The PLL then generates 96 MHz, which is divided down
to 48 MHz to run the PIC.

See the sample programs in this thread below, which show how to run
the PIC at 20 MHz, and at 48 MHz. For USB, you should use 48 MHz.
http://www.ccsinfo.com/forum/viewtopic.php?t=42223&start=1
Note: You are already running it at 48 MHz in your posted code.


hi PCM , but im in setup_timer_0(RTCC_EXT_H_TO_L | RTCC_DIV_128 | RTCC_8_BIT); use the 20mhz external oscilator.. isnt that fine for my counts?
zeronix



Joined: 08 Jun 2010
Posts: 9

View user's profile Send private message

PostPosted: Wed Jun 09, 2010 3:13 pm     Reply with quote

mkuang wrote:
How do you get 48Mhz from an external crystal of 20 Mhz? Make sure you are setting the right pre-scaler values for the external clock (page 31 of the datasheet).


Hi, I think I'm using the correct pll and cpudiv for 20 mhz input oscillator. I already use this pic to obtain x,y,z accelerometer values but with no timer, only with a simple function with no accuracy in time. I already verify that in page 32.
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