• AVR Freaks

AnsweredHot!Difference between capture and compare modes with examples

Page: << < ..678910.. > >> Showing page 8 of 13
Author
eagle1
Super Member
  • Total Posts : 341
  • Reward points : 0
  • Joined: 2014/11/02 03:04:06
  • Location: Saudi Arabia
  • Status: offline
Re: I want to know the difference between capture and compare modes with examples 2018/07/22 22:03:18 (permalink)
0
OK, for now I included the LCD .c and .h files in the project folder and the code compiles OK, but when I put the function of just testing the LCD in the main I get this error:
 
:0: error: (500) undefined symbols:
_LCD_Init(dist/default/production\CCP_modules_test.X.production.obj) _i2c_init(dist/default/production\CCP_modules_test.X.production.obj) _i2c_write(dist/default/production\CCP_modules_test.X.production.obj) _i2c_start(dist/default/production\CCP_modules_test.X.production.obj) _LCD_string(dist/default/production\CCP_modules_test.X.production.obj)
(908) exit status = 1
qɥb
Monolothic Member
  • Total Posts : 3332
  • Reward points : 0
  • Joined: 2017/09/09 05:07:30
  • Location: Jupiter
  • Status: offline
Re: I want to know the difference between capture and compare modes with examples 2018/07/22 22:33:34 (permalink)
0
Is your main.c #including lcd.h ?
It should.
 
Is lcd.c part of your project?
It should be.

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"
eagle1
Super Member
  • Total Posts : 341
  • Reward points : 0
  • Joined: 2014/11/02 03:04:06
  • Location: Saudi Arabia
  • Status: offline
Re: I want to know the difference between capture and compare modes with examples 2018/07/22 23:17:13 (permalink)
0
I did the LCD_I2C in another project, but it's also an error!
 
I have no much experience installing libraries for MPLAB, it's much easier with Arduino and AtmelStudio too.
 

qɥb
Monolothic Member
  • Total Posts : 3332
  • Reward points : 0
  • Joined: 2017/09/09 05:07:30
  • Location: Jupiter
  • Status: offline
Re: I want to know the difference between capture and compare modes with examples 2018/07/22 23:26:54 (permalink)
0
What you are doing is NOT a library, it's just some common source code.
To use it the way you have done it, the C file must appear in the "source files" list.

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"
eagle1
Super Member
  • Total Posts : 341
  • Reward points : 0
  • Joined: 2014/11/02 03:04:06
  • Location: Saudi Arabia
  • Status: offline
Re: I want to know the difference between capture and compare modes with examples 2018/07/22 23:31:40 (permalink)
0
Which one? Because I'm developing 2 projects.
 
First one "CCP_modules_test" is my main program.
Second one "LCD1602_I2C_PIC18" contains LCD and I2C functions.
 
Is there more simpler way to install libraries? Without including them in the same project folder?
qɥb
Monolothic Member
  • Total Posts : 3332
  • Reward points : 0
  • Joined: 2017/09/09 05:07:30
  • Location: Jupiter
  • Status: offline
Re: I want to know the difference between capture and compare modes with examples 2018/07/22 23:41:14 (permalink) ☄ Helpfulby eagle1 2018/07/22 23:42:02
+1 (1)
In XC8, you have to go through a defined procedure to build a "library".
It is NOT just creating C and H files.
Have a read of "3.3.6 How Do I Build Libraries?" in the XC8 User Guide.
 

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"
eagle1
Super Member
  • Total Posts : 341
  • Reward points : 0
  • Joined: 2014/11/02 03:04:06
  • Location: Saudi Arabia
  • Status: offline
Re: I want to know the difference between capture and compare modes with examples 2018/07/23 00:05:20 (permalink)
0
I couldn't solve the problem I had to copy the files into the project folder and compile success.
 
I read the XC user guide, it mentioned a note about the relative path but I didn't understand the syntax!
 

Note that if you intend to step through your library code at a C level in MPLAB X IDE,
you will need to place the library source files so that the relative path between their
location and the project that is using them is the same as the relative path between
where the library build command was executed and where the source files were
located when they were built.

 
I didn't understand the point of this, does it mean the same arrangement I have, which is that the folders should be in the same folder, or all the files in one project folder!
qɥb
Monolothic Member
  • Total Posts : 3332
  • Reward points : 0
  • Joined: 2017/09/09 05:07:30
  • Location: Jupiter
  • Status: offline
Re: I want to know the difference between capture and compare modes with examples 2018/07/23 00:10:44 (permalink)
0
Building libraries is an advanced topic in XC8.
I've been using Hitech C / XC8 for many years, and I've never bothered doing it.
Are you sure you want to get bogged down in this?
 
Also note, once you put it into a library, the port pins are fixed. You can't just edit a ".h" file to change pins.
 

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"
eagle1
Super Member
  • Total Posts : 341
  • Reward points : 0
  • Joined: 2014/11/02 03:04:06
  • Location: Saudi Arabia
  • Status: offline
Re: I want to know the difference between capture and compare modes with examples 2018/07/23 00:17:53 (permalink)
0
Hmmm, ok, first I have to fix the LCD I2C code because it's not working right now, it's working with my AVR implementation. But I don't know I have to check the I2C for PIC programming aspect! It could be different than AVR.
eagle1
Super Member
  • Total Posts : 341
  • Reward points : 0
  • Joined: 2014/11/02 03:04:06
  • Location: Saudi Arabia
  • Status: offline
Re: I want to know the difference between capture and compare modes with examples 2018/07/23 00:24:08 (permalink)
0
qɥb
Also note, once you put it into a library, the port pins are fixed. You can't just edit a ".h" file to change pins.
 

 
You mean the definitions? wow that's serious problem. With Arduino IDE, I can do anything in the library while it's open in the code editor, e.g. CodeBlocks, and compile the code application on Arduino IDE right away :) That's really easy.
 
qɥb
Monolothic Member
  • Total Posts : 3332
  • Reward points : 0
  • Joined: 2017/09/09 05:07:30
  • Location: Jupiter
  • Status: offline
Re: I want to know the difference between capture and compare modes with examples 2018/07/23 00:53:42 (permalink)
+1 (1)
Arduino is an "interpreted environment, so it's a lot more configurable, but much slower.
In PIC, you have direct access to the hardware, so it's much quicker, but has more limitations.

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"
eagle1
Super Member
  • Total Posts : 341
  • Reward points : 0
  • Joined: 2014/11/02 03:04:06
  • Location: Saudi Arabia
  • Status: offline
Re: I want to know the difference between capture and compare modes with examples 2018/07/23 07:12:28 (permalink)
0
I'm confused right now about the SSPIF how to check and clear it in the PIC programming.
 
Should the function this way:
Note: I put a blink loop for debugging purposes.
void i2c_start(void)
{
    SSPCON1bits.SSPEN=1; //Initiate start condition
    while(!PIR1bits.SPPIF);
    for (i=0;i<5;i++)blink_RC2();
}

In this case, the code never get passed the while loop.
 
But in this case:
void i2c_start(void)
{
    SSPCON1bits.SSPEN=1; //Initiate start condition
    while(PIR1bits.SPPIF);
    for (i=0;i<5;i++)blink_RC2();
}

 
It works!
 
My interpretation about the SSPIF is that it's set for different actions. And I have to wait until it's cleared.
Do I have to clear it? Or it get cleared by itself?
 
I found different code files for I2C that check for SSPIF and others don't; like this one I found the plib which should be guaranteed by microchip to include it in the official xc files.
#if defined (I2C_V4)
signed char WriteI2C( unsigned char data_out )
{
  SSPBUF = data_out; // write single byte to SSPBUF
  if ( SSPCONbits.WCOL ) // test if write collision occurred
   return ( -1 ); // if WCOL bit is set return negative #
  else
  {
    while( SSPSTATbits.BF ); // wait until write cycle is complete
 
 // if ( PIR1bits.SSPIF ) // test for ACK condition received
 // return ( -2 );
// else
 return ( 0 ); // if WCOL bit is not set return non-negative #
  }
}

 
Clearly not checking for SSPIF.
qɥb
Monolothic Member
  • Total Posts : 3332
  • Reward points : 0
  • Joined: 2017/09/09 05:07:30
  • Location: Jupiter
  • Status: offline
Re: I want to know the difference between capture and compare modes with examples 2018/07/23 13:18:54 (permalink) ☄ Helpfulby eagle1 2018/07/23 17:31:48
+1 (1)
You're twiddling the wrong bit!
 SSPCON1bits.SSPEN=1; //Initiate start condition 

"SSPEN" is the "SSP enable" bit. You really meant "SEN", which is the "START enable" bit.



My interpretation about the SSPIF is that it's set for different actions. And I have to wait until it's cleared.
Do I have to clear it? Or it get cleared by itself?

Various SSP operations completing will set SSPIF. It never clears by itself, you have to do that.
Most of those operations have a second way to determine if they have completed.
e.g. when you set SEN to trigger a START condition being transmitted, the SEN bit will be cleared when it completes.
You can test either SEN or SSPIF, personally I prefer testing SEN in that instance.
 
 
 
 

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"
PStechPaul
Super Member
  • Total Posts : 2206
  • Reward points : 0
  • Joined: 2006/06/27 16:11:32
  • Location: Cockeysville, MD, USA
  • Status: offline
Re: I want to know the difference between capture and compare modes with examples 2018/07/23 13:50:22 (permalink)
+2 (2)
I would suggest starting a new thread for discussion of I2C and LCD display.  I had lots of problems with I2C, which was discussed in another thread a few months ago. I had it working for an I2C display, but had problems reading back an I2C EEPROM. I used bits and pieces from various libraries, and I used several different PICs.
 
https://www.microchip.com/forums/m1044807.aspx
post edited by PStechPaul - 2018/07/23 14:00:44

 
eagle1
Super Member
  • Total Posts : 341
  • Reward points : 0
  • Joined: 2014/11/02 03:04:06
  • Location: Saudi Arabia
  • Status: offline
Re: I want to know the difference between capture and compare modes with examples 2018/07/24 20:56:02 (permalink)
0
PStechPaul
I would suggest starting a new thread for discussion of I2C and LCD display.  I had lots of problems with I2C, which was discussed in another thread a few months ago. I had it working for an I2C display, but had problems reading back an I2C EEPROM. I used bits and pieces from various libraries, and I used several different PICs.
 
https://www.microchip.com/forums/m1044807.aspx


I appreciate it thank you, OK, I'm having problems with my set it works perfectly with my Arduino AVR-GCC code. The library isn't a prebuilt Arduino for one professional programmer, it's mine written in C.
 
I'm posting my code in your thread, in case you figure out something not correct.
 
The code is working and my I2C finally worked, I had to disable the interrupts. But the LCD is initialized, and I can't show characters on it.
PStechPaul
Super Member
  • Total Posts : 2206
  • Reward points : 0
  • Joined: 2006/06/27 16:11:32
  • Location: Cockeysville, MD, USA
  • Status: offline
Re: I want to know the difference between capture and compare modes with examples 2018/07/24 21:49:14 (permalink)
+1 (1)
From a brief look, it seems you may need more delay between some commands during initialization. Also, as a matter of style, I suggest using upper case for #defines, and make them descriptive. Best to continue discussion there, or in a separate thread.

 
eagle1
Super Member
  • Total Posts : 341
  • Reward points : 0
  • Joined: 2014/11/02 03:04:06
  • Location: Saudi Arabia
  • Status: offline
Re: I want to know the difference between capture and compare modes with examples 2018/07/25 06:31:09 (permalink)
0
I want a source for input capture to my PIC184550.
 
Can I drive a pin HIGH/LOW for like 100 ms from; e.g. LATD2 and take the signal to the CPP1 input? I'm trying but it's not working.
 
I think the problem is the capture function is stuck for something I don't know what it is?
 
This is the main:
void trigger_pin(void);

void main(void) {
    ADCON0=0x00;ADCON1=0x0f;CMCON=0x07; // disable ADC, comparators
    OSCCON=0x66; // internal oscillator 4MHz
    INTCON=0x00; // compare settings & disable all interrupts
    i2c_init();
    i2c_start();
    LCD_Init();
    
    uint8_t val_arr[20];
    uint16_t capture_val;
    while(1){
        trigger_pin();
        capture_val = capture();
        sprintf(val_arr,"%d",capture_val);
        LCD_string("capture value:");
        move_cursor(2,0);
        LCD_string(val_arr);
        __delay_ms(10);
        sendCMD(clear_display);
    }
}

void trigger_pin(void)
{
    TRISDbits.RD2=0;
    LATDbits.LATD2=1;
    __delay_ms(100);
    LATDbits.LATD2=0;
    __delay_ms(100);
}

 
And this is the capture function:
uint16_t capture(void)
{
    uint16_t data1=0,data2=0,period;
    TRISCbits.RC2=1; // CCP1 at port C as input
    T1CON=0x80; // timer1 16-bits
    CCP1CON=0x05;INTCON=0x00; // Capture settings & disable all interrupts
    T1CONbits.TMR1ON=1; // turn on timer1
   while (1)
   {
        while(!PIR1bits.CCP1IF); // wait for capture input signal
        PIR1bits.CCP1IF=0; // clear the capture flag bit
        data1 = CCPR1; // copy the 1st data of capture data register
        while(!PIR1bits.CCP1IF); // wait for another capture input signal
        PIR1bits.CCP1IF=0; // clear the capture flag bit
        data2 = CCPR1; // copy the 2nd data of capture data register
        period = data2 - data1;
   }
}

 
Which is true?
This:
while(!PIR1bits.CCP1IF);

Or this:
while(PIR1bits.CCP1IF==0);

 
 
jack@kksound
code tags!
  • Total Posts : 3183
  • Reward points : 0
  • Joined: 2014/05/14 10:03:19
  • Location: 0
  • Status: offline
Re: I want to know the difference between capture and compare modes with examples 2018/07/25 07:39:41 (permalink) ☄ Helpfulby eagle1 2018/07/25 07:57:43
+2 (2)
How do you expect your program to work when your capture() function has an infinite loop (while(1) ) in it? It will never return to the main() function.
eagle1
Super Member
  • Total Posts : 341
  • Reward points : 0
  • Joined: 2014/11/02 03:04:06
  • Location: Saudi Arabia
  • Status: offline
Re: I want to know the difference between capture and compare modes with examples 2018/07/25 08:01:51 (permalink)
0
Thank you, what a mistake, because I copied the functions from earlier source code :)
 
uint16_t capture(void)
{
    uint16_t data1=0,data2=0,period;
    TRISCbits.RC2=1; // CCP1 at port C as input
    T1CON=0x80; // timer1 16-bits
    CCP1CON=0x05;INTCON=0x00; // Capture settings & disable all interrupts
    T1CONbits.TMR1ON=1; // turn on timer1
        while(!PIR1bits.CCP1IF); // wait for capture input signal
        PIR1bits.CCP1IF=0; // clear the capture flag bit
        data1 = CCPR1; // copy the 1st data of capture data register
        while(!PIR1bits.CCP1IF); // wait for another capture input signal
        PIR1bits.CCP1IF=0; // clear the capture flag bit
        data2 = CCPR1; // copy the 2nd data of capture data register
        //period = data2 - data1;
        return data2 - data1;
}

 
The signal from the same PIC didn't work.
 
It needs a signal from an external source. In my case it's my Arduino board :) It's really nice.
 
The value is around 2970:
1. The signal from the Arduino is 100ms high 100ms low.
2. The PIC is running at 4MHz, so it's 1us instruction cycle.
3. The compare mode returns this value on the LCD which is 2970.
4. That is around 3ms, but the period is 100ms! What I'm missing here?
post edited by eagle1 - 2018/07/25 08:17:13
eagle1
Super Member
  • Total Posts : 341
  • Reward points : 0
  • Joined: 2014/11/02 03:04:06
  • Location: Saudi Arabia
  • Status: offline
Re: I want to know the difference between capture and compare modes with examples 2018/07/25 08:11:43 (permalink)
0

Page: << < ..678910.. > >> Showing page 8 of 13
Jump to:
© 2019 APG vNext Commercial Version 4.5