Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

Learning CCP register of PIC12F683

Status
Not open for further replies.

imranahmed

Advanced Member level 3
Advanced Member level 3
Joined
Dec 4, 2011
Messages
822
Helped
3
Reputation
6
Reaction score
3
Trophy points
1,298
Location
Karachi,Pakistan
Visit site
Activity points
6,533
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:

You should go through the datasheet at first. Here's the datasheet: ww1.microchip.com/downloads/en/devicedoc/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):

2027081100_1353917355.png


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

You may also want to go through this:


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.
 

Attachments

  • 12f683 CCP.pdf
    401.3 KB · Views: 182

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

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:
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?
 

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

T1CON register:
7040310200_1357514361.png


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 attached zip archive contains tutorials which cover both Timer1 and Timer2, Lessons 9 and 10, quite well.

I hope you find them helpful.

BigDog
 

Attachments

  • PIC_Midrange_C.zip
    3 MB · Views: 183
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 a moderator:

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.

https://en.wikipedia.org/wiki/Operators_in_C_and_C++#Logical_operators
https://www.mikroe.com/download/eng/documents/compilers/mikroc/pro/pic/help/logical_operators.htm
https://www.mikroe.com/download/eng/documents/compilers/mikroc/pro/pic/help/bitwise_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: https://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.
 
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);
}
    }

}
 

Attachments

  • picmp.bmp
    769.1 KB · Views: 115
Last edited by a moderator:

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

7433379800_1357751822.png


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:
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.
 

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.
 
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:

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.
 
Status
Not open for further replies.

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top