---
+ Post New Thread
Page 1 of 2 12 LastLast
Results 1 to 20 of 29
  1. #1
    Advanced Member level 1
    Points: 2,345, Level: 11
    imranahmed's Avatar
    Join Date
    Dec 2011
    Location
    Karachi,Pakistan
    Posts
    479
    Helped
    2 / 2
    Points
    2,345
    Level
    11

    Learning CCP register of PIC12F683

    Please let me know that about the CCP (Capture,Compare and PWM).
    My question is that what and which condition we use Capture or Compare or (PWM slightly know).
    And what thing the CCP register Capture or Compare or (PWM slightly know).
    What is prescaler and postscaler?
    Last edited by imranahmed; 25th November 2012 at 20:50.
    IMRAN

    •   Alt25th November 2012, 20:43

      advertising

        
       

  2. #2
    Advanced Member level 5
    Points: 20,224, Level: 34

    Join Date
    May 2009
    Location
    Prime Meridian
    Posts
    3,056
    Helped
    885 / 885
    Points
    20,224
    Level
    34

    Re: Learning CCP register of PIC12F683



    1 members found this post helpful.

  3. #3
    Advanced Member level 4
    Points: 8,758, Level: 22
    ALERTLINKS's Avatar
    Join Date
    Dec 2003
    Location
    Pakistan
    Posts
    1,203
    Helped
    354 / 354
    Points
    8,758
    Level
    22

    Re: Learning CCP register of PIC12F683

    Once you know something, the documentation then becomes very clear...



  4. #4
    Advanced Member level 5
    Points: 35,749, Level: 46
    Tahmid's Avatar
    Join Date
    Jun 2008
    Location
    Cornell University, Ithaca, New York, USA (from Dhaka, Bangladesh)
    Posts
    4,730
    Helped
    1697 / 1697
    Points
    35,749
    Level
    46
    Blog Entries
    19

    Re: Learning CCP register of PIC12F683

    You should go through the datasheet at first. Here's the datasheet: http://ww1.microchip.com/downloads/e...oc/41211d_.pdf

    I have attached only the CCP chapter of the datasheet. Check the attachment.

    Here is the CCP control register (taken from the datasheet):



    Make sure you go through the CCP portion of the reference manual:
    http://ww1.microchip.com/downloads/e...doc/31014a.pdf

    You may also want to go through this:
    http://www.mikroe.com/chapters/view/...5-ccp-modules/

    Whenever you come across something related to the PIC CCP module, read it. Even if it might not be directly applicable to the 12F683 due to eg different pins, etc, you can easily adapt the idea and technique to the 12F683.

    Hope this helps.
    Tahmid.



  5. #5
    Advanced Member level 1
    Points: 2,345, Level: 11
    imranahmed's Avatar
    Join Date
    Dec 2011
    Location
    Karachi,Pakistan
    Posts
    479
    Helped
    2 / 2
    Points
    2,345
    Level
    11

    Re: Learning CCP register of PIC12F683

    Please let me know about Timer0 or 1 Interrupt procedure in PIC12F683 example and please describe with example.
    IMRAN



  6. #6
    Advanced Member level 5
    Points: 35,749, Level: 46
    Tahmid's Avatar
    Join Date
    Jun 2008
    Location
    Cornell University, Ithaca, New York, USA (from Dhaka, Bangladesh)
    Posts
    4,730
    Helped
    1697 / 1697
    Points
    35,749
    Level
    46
    Blog Entries
    19

    Re: Learning CCP register of PIC12F683

    You need to enable the corresponding interrupts. Enable global interrupt and peripheral interrupt for TMR1. Then you just need to serve the interrupt.

    Here's a sample code that should be self-explanatory (written in mikroC):

    Code:
    //Programmer: Syed Tahmid Mahbub
    //Compiler: mikroC PRO for PIC
    //Target Device: PIC12F683
    //Date: 7th January 2013
    
    
    void interrupt(){  //ISR
         if (TMR1IF_bit == 1){  //TMR1 interrupt flag raised
            GPIO = ~ GPIO;
            TMR1IF_bit = 0;
         }
    }
    
    void main() {
         CMCON0 = 7;        //Disable comparator
         ANSEL = 0;         //Disable ADC
         GPIO = 0;
         TRISIO = 8;
         TMR1IF_bit = 0;
         TMR1IE_bit = 1;    //Enable TMR1 interrupt
         GIE_bit = 1;       //Enable global interrupt
         PEIE_bit = 1;      //Enable peripheral interrupt
         
         
    /*****    Initialize Timer 1   *****/
         T1CON = 0x31;
    /*
    
      -  Prescale 1:8
            - 4MHz oscillator
            - 1 increment takes 1 us * 8
            - So, 65536 increments take
                   65536 * 8 * 1us = 524.288 ms
      -  Timer 1 clock source:
            - Internal clock (Fosc/4)
      -  Timer 1 on
      
    */
    
    /*****    Initialization done  *****/
    
         while(1);
    
    }
    GPIO is toggled every TMR1 interrupt. So, just check the output at GP0 or any other (except GP3).

    Hope this helps.
    Tahmid.
    Last edited by Tahmid; 7th January 2013 at 00:19.
    The blissful feeling of helping others is a unique reward that cannot be gotten from anything else.


    1 members found this post helpful.

    •   Alt6th January 2013, 20:42

      advertising

        
       

  7. #7
    Advanced Member level 1
    Points: 2,345, Level: 11
    imranahmed's Avatar
    Join Date
    Dec 2011
    Location
    Karachi,Pakistan
    Posts
    479
    Helped
    2 / 2
    Points
    2,345
    Level
    11

    Re: Learning CCP register of PIC12F683

    Prescale 1:8
    - 4MHz oscillator
    - 1 increment takes 1 us
    - So, 65536 increments take
    65536 * 8 * 1us = 524.288 ms
    - Timer 1 clock source:
    - Internal clock (Fosc/4)
    - Timer 1 on


    Please let me know that how you take 65535 and 8 i think prescaler and what is 1us is here?
    IMRAN



  8. #8
    Advanced Member level 5
    Points: 35,749, Level: 46
    Tahmid's Avatar
    Join Date
    Jun 2008
    Location
    Cornell University, Ithaca, New York, USA (from Dhaka, Bangladesh)
    Posts
    4,730
    Helped
    1697 / 1697
    Points
    35,749
    Level
    46
    Blog Entries
    19

    Re: Learning CCP register of PIC12F683

    I set the prescaler to 8 by writing 1 to both T1CKPS0 and T1CKPS1 as I assigned 0x31 to T1CON.

    T1CON register:


    I used a 4MHz oscillator. So instruction time = 1us (1 micro second). So, one increment takes 8 * 1us (as prescaler = 1:8). Since TMR1 is a 16-bit timer there are 65536 steps that cause an interrupt which takes 65536 * 8 *1us.

    Hope this helps.
    Tahmid.
    The blissful feeling of helping others is a unique reward that cannot be gotten from anything else.


    1 members found this post helpful.

  9. #9
    Administrator
    Points: 58,273, Level: 58
    Awards:
    3rd Helpful Member
    bigdogguru's Avatar
    Join Date
    Mar 2010
    Location
    Southwest, USA
    Posts
    8,284
    Helped
    2152 / 2152
    Points
    58,273
    Level
    58
    Blog Entries
    3

    Re: Learning CCP register of PIC12F683

    The attached zip archive contains tutorials which cover both Timer1 and Timer2, Lessons 9 and 10, quite well.

    I hope you find them helpful.

    BigDog
    The Edge... there is no honest way to explain it, because the only people who really know where it is are the ones who have gone over.
    -- Hunter S. Thompson


    2 members found this post helpful.

    •   Alt7th January 2013, 04:34

      advertising

        
       

  10. #10
    Advanced Member level 1
    Points: 2,345, Level: 11
    imranahmed's Avatar
    Join Date
    Dec 2011
    Location
    Karachi,Pakistan
    Posts
    479
    Helped
    2 / 2
    Points
    2,345
    Level
    11

    Re: Learning CCP register of PIC12F683

    1) Please let me know about that how we can easily to understand and apply (n<<0x55) or (GPIO>>0x44) or GPIO|=a.
    (e&0x33)=n>>0x76 , this type of logics.

    2) Please tell me any application of timer0 or 1 interrupt.And one think I think is that when interrupt function calls the flag bit automatically goes to 1,is right ,ok, otherwise please comment.


    3) And please let me know why we add 48 , i saw in many codes that 48 is added in conversion of digits to numbers.
    Code:
    temp[0] = new_count/10 + 48;          // Convert count digits into characters
    temp[1] = new_count%10 + 48
    4)Please let me know that how configure MCLR bit in the MPLAB,code is given and error is "Error [800] C:\DOCUME~1\IMRANA~1\LOCALS~1\Temp\s2as.; 45. undefined symbol "MCLRDIS"
    "
    Code:
    #include<htc.h> 
    #define _XTAL_FREQ 8000000
    __CONFIG(MCLRDIS);
    void main()
    {
        TRISIO = 0x01;
        GPIO=0;
    while(1)
        {
    GPIObits.GP0=1;
          if(GPIObits.GP0==0)
    {  
       GPIObits.GP2=1;    
       __delay_ms(500);       
       GPIObits.GP2=0;        
       __delay_ms(500);
    }
        }
    
    }
    Last edited by bigdogguru; 8th January 2013 at 22:52. Reason: Added Code or Syntax Tags
    IMRAN



  11. #11
    Advanced Member level 5
    Points: 35,749, Level: 46
    Tahmid's Avatar
    Join Date
    Jun 2008
    Location
    Cornell University, Ithaca, New York, USA (from Dhaka, Bangladesh)
    Posts
    4,730
    Helped
    1697 / 1697
    Points
    35,749
    Level
    46
    Blog Entries
    19

    Re: Learning CCP register of PIC12F683

    Quote Originally Posted by imranahmed View Post
    1) Please let me know about that how we can easily to understand and apply (n<<0x55) or (GPIO>>0x44) or GPIO|=a.
    (e&0x33)=n>>0x76 , this type of logics.
    You should read up on bitwise and logical operators.

    http://en.wikipedia.org/wiki/Operato...ical_operators
    http://www.mikroe.com/download/eng/d..._operators.htm
    http://www.mikroe.com/download/eng/d..._operators.htm

    2) Please tell me any application of timer0 or 1 interrupt.And one think I think is that when interrupt function calls the flag bit automatically goes to 1,is right ,ok, otherwise please comment.
    See post #6 above for code.
    After the flag is set whenever some event occurs, the interrupt is "called" if the corresponding interrupt and global interrupt are enabled. Some interrupts (peripheral interrupts) will require the peripheral interrupt to be enabled (PEIE = 1).

    3) And please let me know why we add 48 , i saw in many codes that 48 is added in conversion of digits to numbers.

    temp[0] = new_count/10 + 48; // Convert count digits into characters
    temp[1] = new_count%10 + 48
    Take a look at the ASCII table/chart: http://www.asciitable.com/

    Notice how the ASCII code for 0 is 48, for 1 is 49, for 2 is 50, for 3 is 51, .... for 9 is 57.
    So, the ASCII code for the single digit numerals is 48 greater than their numeric value. So, 48 is added to convert from a numeric data type to ASCII.

    4)Please let me know that how configure MCLR bit in the MPLAB,code is given and error is "Error [800] C:\DOCUME~1\IMRANA~1\LOCALS~1\Temp\s2as.; 45. undefined symbol "MCLRDIS"
    "

    #include<htc.h>
    #define _XTAL_FREQ 8000000
    __CONFIG(MCLRDIS);
    void main()
    {
    TRISIO = 0x01;
    GPIO=0;
    while(1)
    {
    GPIObits.GP0=1;
    if(GPIObits.GP0==0)
    {
    GPIObits.GP2=1;
    __delay_ms(500);
    GPIObits.GP2=0;
    __delay_ms(500);
    }
    }

    }
    Check the header file for the corresponding PIC and see what you must write to disable MCLR. Check in your Hi-Tech C program directory.

    Hope this helps.
    Tahmid.
    The blissful feeling of helping others is a unique reward that cannot be gotten from anything else.


    1 members found this post helpful.

  12. #12
    Advanced Member level 1
    Points: 2,345, Level: 11
    imranahmed's Avatar
    Join Date
    Dec 2011
    Location
    Karachi,Pakistan
    Posts
    479
    Helped
    2 / 2
    Points
    2,345
    Level
    11

    Re: Learning CCP register of PIC12F683

    Thank you Tahmid for knowledgeable reply.
    IMRAN



  13. #13
    Advanced Member level 1
    Points: 2,345, Level: 11
    imranahmed's Avatar
    Join Date
    Dec 2011
    Location
    Karachi,Pakistan
    Posts
    479
    Helped
    2 / 2
    Points
    2,345
    Level
    11

    Re: Learning CCP register of PIC12F683

    Please let me know that I found MCLRE_ON or MCLRE_OFF, but in simulation the microcontroller bits all were off except
    GP1 and GP2.And please check code "if" condition could not execute,without "if condition",program runs successfully.

    CODE:
    Code:
    #include<pic.h> 
    __CONFIG(MCLRE_OFF);
    #define _XTAL_FREQ 8000000
    void main()
    {   
        CMCON0=0;
        ANSEL=0;
        TRISIO = 0x01;
        GPIO=0x00;
    while(1)
        {
         if(GPIObits.GP0==1)
    {  
       GPIObits.GP5=1;    
       __delay_ms(500);       
       GPIObits.GP5=0;        
       __delay_ms(500);
    }
        }
    
    }
    Last edited by bigdogguru; 9th January 2013 at 19:09. Reason: Added Code or Syntax Tags
    IMRAN



  14. #14
    Advanced Member level 5
    Points: 35,749, Level: 46
    Tahmid's Avatar
    Join Date
    Jun 2008
    Location
    Cornell University, Ithaca, New York, USA (from Dhaka, Bangladesh)
    Posts
    4,730
    Helped
    1697 / 1697
    Points
    35,749
    Level
    46
    Blog Entries
    19

    Re: Learning CCP register of PIC12F683

    To disable the comparator and make the associated pins digital, you have to use
    Code:
    CMCON0 = 0x07;


    You also need to define in the configuration settings the oscillator setting. If it's in HS or XT, an external crystal is to be connected to GP4 and GP5. That's why you can't use those as IO lines. So, set oscillator to internal oscillator with GP4 as IO.

    Hope this helps.
    Tahmid.
    Last edited by Tahmid; 9th January 2013 at 19:15.
    The blissful feeling of helping others is a unique reward that cannot be gotten from anything else.


    1 members found this post helpful.

  15. #15
    Advanced Member level 1
    Points: 2,345, Level: 11
    imranahmed's Avatar
    Join Date
    Dec 2011
    Location
    Karachi,Pakistan
    Posts
    479
    Helped
    2 / 2
    Points
    2,345
    Level
    11

    Re: Learning CCP register of PIC12F683

    In Mikro C, how we recognise that how much long program can we write in Mikro C?
    IMRAN



  16. #16
    Advanced Member level 5
    Points: 35,749, Level: 46
    Tahmid's Avatar
    Join Date
    Jun 2008
    Location
    Cornell University, Ithaca, New York, USA (from Dhaka, Bangladesh)
    Posts
    4,730
    Helped
    1697 / 1697
    Points
    35,749
    Level
    46
    Blog Entries
    19

    Re: Learning CCP register of PIC12F683

    The largest program you can write is that which takes all the available program memory of the target PIC. This you can get from the datasheet.
    The demo version is limited to 2k word. The licensed version has no limit compiler-wise.

    To check the amount of memory used, you can go to View > Statistics or press Ctrl + Alt + S on your keyboard. On the windows that pops up, select "ROM Memory Usage" or "Summary" from the left-hand menu.

    Alternately, you can view it by enabling Messages by selecting View > Messages if it isn't already enabled. If enabled you can view it in the messages window. Scroll up a little and you can see used ROM and free ROM.

    Hope this helps.
    Tahmid.
    The blissful feeling of helping others is a unique reward that cannot be gotten from anything else.



  17. #17
    Advanced Member level 1
    Points: 2,345, Level: 11
    imranahmed's Avatar
    Join Date
    Dec 2011
    Location
    Karachi,Pakistan
    Posts
    479
    Helped
    2 / 2
    Points
    2,345
    Level
    11

    Re: Learning CCP register of PIC12F683

    Please let me know that 2k word program of how many lines?

    Please send me any sample program of max. size in Mikro C.
    IMRAN



  18. #18
    Advanced Member level 5
    Points: 35,749, Level: 46
    Tahmid's Avatar
    Join Date
    Jun 2008
    Location
    Cornell University, Ithaca, New York, USA (from Dhaka, Bangladesh)
    Posts
    4,730
    Helped
    1697 / 1697
    Points
    35,749
    Level
    46
    Blog Entries
    19

    Re: Learning CCP register of PIC12F683

    How many lines will depend on the code itself, on what functions have been used.

    What exactly do you mean be max size?

    For a large program "demo", open Help and copy the code for the USB HID. Use that code and build it for the 18F4550. That will be a large program - greater than the demo limit, less than max for 18F4550.

    Hope this helps.
    Tahmid.
    The blissful feeling of helping others is a unique reward that cannot be gotten from anything else.


    1 members found this post helpful.

  19. #19
    Advanced Member level 1
    Points: 2,345, Level: 11
    imranahmed's Avatar
    Join Date
    Dec 2011
    Location
    Karachi,Pakistan
    Posts
    479
    Helped
    2 / 2
    Points
    2,345
    Level
    11

    Re: Learning CCP register of PIC12F683

    If anybody say to me that write code for any project,so, how i can imagine that this project longer than 2k word?


    I wrote USB HID code but it was not compile.What?????
    Last edited by imranahmed; 10th January 2013 at 18:48.
    IMRAN



  20. #20
    Advanced Member level 5
    Points: 35,749, Level: 46
    Tahmid's Avatar
    Join Date
    Jun 2008
    Location
    Cornell University, Ithaca, New York, USA (from Dhaka, Bangladesh)
    Posts
    4,730
    Helped
    1697 / 1697
    Points
    35,749
    Level
    46
    Blog Entries
    19

    Re: Learning CCP register of PIC12F683

    You have to weigh in your head the peripherals you will need to use, some library functions you may use and have a hunch of the code flow.

    eg. If you're going to make a DC-AC inverter, you may use the CCP module, the ADC module, the comparator module, mikroC delay functions. This will be less than 2k (unless coded poorly). Now if you add an LCD display, USB communications, RS-232 communications, data logging, use of trigonometric functions and floating point calculations among other things (for example), the 2k limit will be crossed (unless coded brilliantly). As you program more and more, you will have a better hunch with increasing experience and practice.

    Hope this helps.
    Tahmid.
    The blissful feeling of helping others is a unique reward that cannot be gotten from anything else.


    1 members found this post helpful.

+ Post New Thread
Please login
Page 1 of 2 12 LastLast