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

Max Frequency on a 18F2420 @ 4MHz ??

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



Joined: 25 Oct 2004
Posts: 136

View user's profile Send private message

Max Frequency on a 18F2420 @ 4MHz ??
PostPosted: Mon Oct 20, 2008 3:11 am     Reply with quote

Hi Friends,

I am using a 18F2420 with a 4MHz Crystal, can somebody tell me what the maximum frequency on a timer1 overflow can be ?

I use the following test programm where I get max 23,26kHz output Frequency


Can somebody point me to my error ??

best regards

ANdreas

Code:

#include <18F2420.h>
#device adc=8

#FUSES NOWDT                    //No Watch Dog Timer
#FUSES WDT128                   //Watch Dog Timer uses 1:128 Postscale
#FUSES H4                       //High speed osc with HW enabled 4X PLL
#FUSES NOPROTECT                //Code not protected from reading
#FUSES NOBROWNOUT               //No brownout reset
#FUSES BORV20                   //Brownout reset at 2.0V
#FUSES PUT                      //Power Up Timer
#FUSES NOCPD                    //No EE protection
#FUSES STVREN                   //Stack full/underflow will cause reset
#FUSES NODEBUG                  //No Debug mode for ICD
#FUSES NOLVP                    //No low voltage prgming, B3(PIC16) or B5(PIC18) used for I/O
#FUSES NOWRT                    //Program memory not write protected
#FUSES NOWRTD                   //Data EEPROM not write protected
#FUSES IESO                     //Internal External Switch Over mode enabled
#FUSES FCMEN                    //Fail-safe clock monitor enabled
#FUSES NOPBADEN                 //PORTB pins are configured as digital I/O on RESET
#FUSES NOWRTC                   //configuration not registers write protected
#FUSES NOWRTB                   //Boot block not write protected
#FUSES NOEBTR                   //Memory not protected from table reads
#FUSES NOEBTRB                  //Boot block not protected from table reads
#FUSES NOCPB                    //No Boot Block code protection
#FUSES NOLPT1OSC                //Timer1 configured for higher power operation
#FUSES MCLR                     //Master Clear pin enabled
#FUSES NOXINST                  //Extended set extension and Indexed Addressing mode disabled (Legacy mode)

#use delay(clock=16000000)

#int_TIMER1
void  TIMER1_isr(void)
{
set_timer1(0xFFFF);
output_toggle(PIN_A3);
}



void main()
{

   setup_adc_ports(NO_ANALOGS|VSS_VDD);
   setup_adc(ADC_OFF|ADC_TAD_MUL_0);
   setup_spi(SPI_SS_DISABLED);
   setup_wdt(WDT_OFF);
   setup_timer_0(RTCC_OFF);
   setup_timer_1(T1_INTERNAL|T1_DIV_BY_1);
   setup_timer_2(T2_DISABLED,0,1);
   setup_timer_3(T3_DISABLED|T3_DIV_BY_1);
   setup_comparator(NC_NC_NC_NC);
   setup_vref(FALSE);
   enable_interrupts(INT_TIMER1);
   enable_interrupts(GLOBAL);


while(TRUE)
{
}
}
RLScott



Joined: 10 Jul 2007
Posts: 465

View user's profile Send private message

Re: Max Frequency on a 18F2420 @ 4MHz ??
PostPosted: Mon Oct 20, 2008 6:59 am     Reply with quote

The timer interrupt frequency in your code is determined by the time it takes for the CCS interrupt dispatcher to determine which interrupt source caused the interrupt plus the time it takes your TIMER1_isr to toggle the output pin. If you want to speed that up, and if you know that TIMER 1 is going to be the only interrupt enabled, then you can skip the CCS interrupt dispatcher code and write your own global interrupt handler. I should point out that Timer 1 really has no purpose in this code. In your interrupt code you load Timer 1 with 0xffff, so it is going to overflow on the very next instruction. So the interrupt flag will be set before you ever get back to the main program. Your main program does not get any time at all. You might as well write a busy-loop in main, like:

Code:

  while(TRUE)
  {
      output_toggle(PIN_A3);
  }

It will do the same thing as your code, but much faster.
_________________
Robert Scott
Real-Time Specialties
Embedded Systems Consulting
Andreas



Joined: 25 Oct 2004
Posts: 136

View user's profile Send private message

PostPosted: Mon Oct 20, 2008 7:05 am     Reply with quote

Hi Scott,

The reason for this code, was to test what frequency i can generate with the timer interrupt.

My project is to make a replacement for IR Remotes with different Carrierfrequencies.

I want to send e.g. 32kHz bursts, so in Your opinion whats a good way to to it ?

Also I need to measure the burst frequency in an range of 24kHz up to 44kHz.
Any Idea ?

Thanks
and bestregards
Andreas
RLScott



Joined: 10 Jul 2007
Posts: 465

View user's profile Send private message

PostPosted: Mon Oct 20, 2008 7:34 am     Reply with quote

Andreas wrote:
Hi Scott,
...I want to send e.g. 32kHz bursts, so in Your opinion whats a good way to to it ?

I would use Timer 2 and PWM. Set the duty cycle to 50% to turn on the 32kHz signal, and then set it to 0% to turn it off. To get 32kHz, you need a Timer 2 period of 31 uSec. Then set CCPR1L = 15 to turn on the signal and set it to 0 to turn off the signal.

Quote:

Also I need to measure the burst frequency in an range of 24kHz up to 44kHz.

Do you mean you need to measure what that frequency is in kHz? Or do you only have to detect the presence or absence of this signal to decode IR transmissions?
_________________
Robert Scott
Real-Time Specialties
Embedded Systems Consulting
Andreas



Joined: 25 Oct 2004
Posts: 136

View user's profile Send private message

PostPosted: Mon Oct 20, 2008 2:49 pm     Reply with quote

Hi Robert,

Thanks for your explanations, I will try it now with Timer2.

Yes I need to measure the frequency in KHz of the incoming signal.

best regards
Andreas
RLScott



Joined: 10 Jul 2007
Posts: 465

View user's profile Send private message

PostPosted: Mon Oct 20, 2008 5:44 pm     Reply with quote

Andreas wrote:
Hi Robert,
Yes I need to measure the frequency in KHz of the incoming signal.
Andreas

How accurately and how often?
_________________
Robert Scott
Real-Time Specialties
Embedded Systems Consulting
Andreas



Joined: 25 Oct 2004
Posts: 136

View user's profile Send private message

PostPosted: Mon Oct 20, 2008 11:41 pm     Reply with quote

Hi Robert,

I need the measurement to determine which output Frequency a certain IR Remote Control has, so I think it has quite a tolerance.

Actually I need to measure it only once:

Function:
1. Press the learning button on the Remote transmitter
2. Get the IR Remote Control near to the fototransistor and measure the Burst frequency
3. Release the learning button
4. Out of this result, set the output Burst frequency

Thats it

I took already your considerations into my design. I have to free now the PWM Output Pins and will try it again. Thanks for Your help.


best regards
Andreas
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