• AVR Freaks

20MHz crystal configuration

Author
Sunil4u
New Member
  • Total Posts : 17
  • Reward points : 0
  • Joined: 2016/12/10 11:37:57
  • Location: 0
  • Status: offline
2018/05/03 22:50:43 (permalink)
0

20MHz crystal configuration

Hello friends,
I am using PIC18F4550, I am trying to use timer to generate a pulse of 200kHz. I am using 20MHz crystal and use TIMER1. I use configuration as below, and initialize TMR1L = 200; but still the output at RA5 where I generate the pulse, is very low. Can some one please help me to configure the clock and timer to generate 200MHz ?
#pragma config PLLDIV = 5 
#pragma config CPUDIV = OSC2_PLL3
#pragma config USBDIV = 1 
#pragma config FOSC = HSPLL_HS
Thanks
#1

11 Replies Related Threads

    qɥb
    Monolothic Member
    • Total Posts : 3332
    • Reward points : 0
    • Joined: 2017/09/09 05:07:30
    • Location: Jupiter
    • Status: offline
    Re: 20MHz crystal configuration 2018/05/05 03:28:31 (permalink)
    +1 (1)
    You can't set a rate by writing a value to TMR1L once.
    You either need to use TIMER2, which has a PR register, or you need an interrupt service routine which reinitialises the timer value after every rollover.
    We would need to see ALL your code to see of you are doing enough.
     
    post edited by qɥb - 2018/05/05 03:30:13

    This forum is mis-configured so it only works correctly if you access it via https protocol.
    The Microchip website links to it using http protocol. Will they ever catch on?
    PicForum "it just works"
    #2
    Sunil4u
    New Member
    • Total Posts : 17
    • Reward points : 0
    • Joined: 2016/12/10 11:37:57
    • Location: 0
    • Status: offline
    Re: 20MHz crystal configuration 2018/05/05 04:04:12 (permalink)
    0
    Thanks brother. I tried as you suggested. It works but there is no room to run other functions. Whole time controller is busy with the interrupt. Here is the code,
    #define _XTAL_FREQ 20000000
    int count =0 ;
    void toggle(void);
      void interrupt ISR(void) {
        if(PIR1bits.TMR2IF == 1) {
        PIR1bits.TMR2IF = 0;
        toggle();
      }
    }
    void main(void) {
      T2CONbits.TMR2ON = 1;
      TRISAbits.RA5 = 0;
      LATAbits.LA5 = 0;
      RCONbits.IPEN = 1; 
      IPR1bits.TMR2IP = 1;
      INTCONbits.GIE = 1;
      INTCONbits.PEIE = 1;
      INTCONbits.TMR0IE = 1;
      INTCON2bits.TMR0IP = 1;
      PIE1bits.TMR2IE = 1;
      IPR1bits.TMR2IP = 1;
      T2CON = 0b00000100; 
      PR2 = 0b00111011;
      CCPR1L = 0b00011110; 
      CCP1CON = 0b00001100;
      T2CONbits.TMR2ON = 1;
      int i;
      while(1) {
        count = count + 1;
        for (i=0;i!=50;i++)   {
          ;
        }
      LATBbits.LB0 = ~LATBbits.LB0 ;
      }
    }
    void toggle(void) {
    LATAbits.LA5 = ~LATAbits.LA5;
    }
    #3
    Sunil4u
    New Member
    • Total Posts : 17
    • Reward points : 0
    • Joined: 2016/12/10 11:37:57
    • Location: 0
    • Status: offline
    Re: 20MHz crystal configuration 2018/05/05 04:05:54 (permalink)
    0
    you can ignore timer 0 config bits. 
    #4
    qɥb
    Monolothic Member
    • Total Posts : 3332
    • Reward points : 0
    • Joined: 2017/09/09 05:07:30
    • Location: Jupiter
    • Status: offline
    Re: 20MHz crystal configuration 2018/05/07 13:15:30 (permalink)
    +1 (1)
    Sunil4u
    you can ignore timer 0 config bits. 


    What does this mean?
    Why are you enabling Timer0 interrupts when your interrupt service is not handling them?
    Why are you enabling interrupt priorities when you only have a single interrupt service?

    This forum is mis-configured so it only works correctly if you access it via https protocol.
    The Microchip website links to it using http protocol. Will they ever catch on?
    PicForum "it just works"
    #5
    Sunil4u
    New Member
    • Total Posts : 17
    • Reward points : 0
    • Joined: 2016/12/10 11:37:57
    • Location: 0
    • Status: offline
    Re: 20MHz crystal configuration 2018/05/07 21:42:26 (permalink)
    0
    In our application, I want to use this pulse to drive a servo motor, with speed control (frequency of the pulse) and rotation control (number of pulses). Which I believe not possible with PWM generation, So I was trying to figure out a combination of PWM and interrupt. At the same time, our max pulse frequency requirement is 200KHz, which is not possible with timer interrupt. Please correct me. And if you have any solution, May I request you to share ? Thanks
    #6
    qɥb
    Monolothic Member
    • Total Posts : 3332
    • Reward points : 0
    • Joined: 2017/09/09 05:07:30
    • Location: Jupiter
    • Status: offline
    Re: 20MHz crystal configuration 2018/05/07 21:50:39 (permalink)
    +1 (1)
    If you just ignore my questions there's no point trying to help.
     

    This forum is mis-configured so it only works correctly if you access it via https protocol.
    The Microchip website links to it using http protocol. Will they ever catch on?
    PicForum "it just works"
    #7
    Sunil4u
    New Member
    • Total Posts : 17
    • Reward points : 0
    • Joined: 2016/12/10 11:37:57
    • Location: 0
    • Status: offline
    Re: 20MHz crystal configuration 2018/05/08 03:26:49 (permalink)
    0
    I am not ignoring, I am trying to answer your question only.
    I was trying to use Timer 0 to generate pulse, but those config bits were not commented while send you the code. that is why I said, ignore Timer 0 config bits. 
    #8
    qɥb
    Monolothic Member
    • Total Posts : 3332
    • Reward points : 0
    • Joined: 2017/09/09 05:07:30
    • Location: Jupiter
    • Status: offline
    Re: 20MHz crystal configuration 2018/05/08 03:59:59 (permalink)
    +1 (1)
    That's one question. I asked three.
     

    This forum is mis-configured so it only works correctly if you access it via https protocol.
    The Microchip website links to it using http protocol. Will they ever catch on?
    PicForum "it just works"
    #9
    Sunil4u
    New Member
    • Total Posts : 17
    • Reward points : 0
    • Joined: 2016/12/10 11:37:57
    • Location: 0
    • Status: offline
    Re: 20MHz crystal configuration 2018/05/09 05:54:59 (permalink)
    0
    Can I generate 200KHz pulse with PIC18F4550 with 20MHz crystal,  With counting the number of pulse?
    #10
    mbrowning
    Just a Member
    • Total Posts : 1500
    • Reward points : 0
    • Joined: 2005/03/16 14:32:56
    • Location: Melbourne, FL
    • Status: offline
    Re: 20MHz crystal configuration 2018/05/09 06:53:22 (permalink)
    0
    I think you are running at 32MHz Fosc, so 8MHz instruction cycle. 8M/200K = 40 instructions per pulse, so using a timer to generate 200KHz pulses is going to use pretty much all of the processor cycles.
     
    Probably you should consider using a CCP module in PWM mode to generate the pulses without software involvement.
     

    Oh well - there's always next year
    #11
    Sunil4u
    New Member
    • Total Posts : 17
    • Reward points : 0
    • Joined: 2016/12/10 11:37:57
    • Location: 0
    • Status: offline
    Re: 20MHz crystal configuration 2018/08/12 21:55:50 (permalink)
    0
    Thanks mbrowning. I convince myself that 200K is difficult with PIC18F4550. 
    #12
    Jump to:
    © 2019 APG vNext Commercial Version 4.5