gnupic: Thread: CCP in compare mode problem with PIC16F877


[<<] [<] Page 1 of 1 [>] [>>]
Subject: CCP in compare mode problem with PIC16F877
From: massimiliano ruggeri ####@####.####
Date: 8 May 2002 09:16:01 -0000
Message-Id: <3CD8EA12.3EAD7E44@cemoter.bo.cnr.it>

Hi All,
I have a question related to CCP modules in PIC 16F877.

There is someone that use CCP modules in compare mode?

I have tried to use CCP1 and CCP2 in compare mode, using
TIMER1.
My problem is to generate a PWM with a low period,
impossible to reach using PWM mode and prescaler, also with a 4 MHz
clock (and also I have a 5 K flash program, and dynamics at 1ms, then I
would
use a 20 MHz clock!!!).
The frequency would be approximately 100  Hz or less.
Then, fantastic compare mode feature, perfect for me!

My problem is that if I set RC2/CCP1 = 1 and RC1/CCP2 = 1, when TIMER 1
goes in overflow,
after this I try to reset CCP1 pin and CCP2 pin when TIMER1 match
respectively with
(CCPR1H and CCPR1L) and (CCPR2H and CCPR2L) using compare mode feature,
following the PIC16F877 manual.

OK, I'm sure that:
CCP1 and CCP2 are output (TRISC is OK).
but:
CCP1CON and CCP2CON are = 0x09 then (1001 - reset pin on match)
but the pin is always 0.

Note that if I use CCPxCON = 0x0A (1010 - generate interrupt on match
and pin remain
unchanged), and if I add in the interrput management procedure:

if (CCP1IF)
{
    CCP1IF = 0;
    RC2 = 0;
}

if (CCP2IF)
{
    CCP2IF = 0;
    RC1 = 0;
}

then it runs, the pins switch high and low!!!!!
No other changes in my code!!!!
Then the match is OK and also the interrpt is OK, then the module it
runs.
But in this way I will use 2 interrupt more than in the previous way,
using CCPxCON = 0x09 .........

I tried also the opposite way: set pin on match and reset the pin when
TIMER1 goes in
overflow (inside an interrupt procedure), with CCPxCON = 0x08 set output
on match.

There is something that I don't know about CCP?
I've read the 16F877 manual (only 1 page for CCP) and the AN594 from
microchip site, but this don't
helped me.

Someone can help me?

Thank you very much in advance.

Max

P.S. I have some problem in receiving the messages from the list in
these last days......

--------------
Massimiliano Ruggeri
CEMOTER - C.N.R.
National Research Council Of Italy
Fluid Power Group
www.cemoter.bo.cnr.it





Subject: Re: CCP in compare mode problem with PIC16F877
From: Stefano ####@####.####
Date: 8 May 2002 17:49:17 -0000
Message-Id: <Pine.LNX.4.40.0205081339490.4772-100000@nietzsche.mit.edu>

Can you update to 18F252 ???
Then you might push the clock speed up to 60Mhz.


Sincerely,

Stefano Curtarolo
Massachusetts Institute of Technology
Dep. Materials Science and Engineering
MIT - Room 13-4069
77 Massachusetts Avenue
Cambridge, MA 02139-4307, USA


On Wed, 8 May 2002, massimiliano ruggeri wrote:

> Hi All,
> I have a question related to CCP modules in PIC 16F877.
>
> There is someone that use CCP modules in compare mode?
>
> I have tried to use CCP1 and CCP2 in compare mode, using
> TIMER1.
> My problem is to generate a PWM with a low period,
> impossible to reach using PWM mode and prescaler, also with a 4 MHz
> clock (and also I have a 5 K flash program, and dynamics at 1ms, then I
> would
> use a 20 MHz clock!!!).
> The frequency would be approximately 100  Hz or less.
> Then, fantastic compare mode feature, perfect for me!
>
> My problem is that if I set RC2/CCP1 = 1 and RC1/CCP2 = 1, when TIMER 1
> goes in overflow,
> after this I try to reset CCP1 pin and CCP2 pin when TIMER1 match
> respectively with
> (CCPR1H and CCPR1L) and (CCPR2H and CCPR2L) using compare mode feature,
> following the PIC16F877 manual.
>
> OK, I'm sure that:
> CCP1 and CCP2 are output (TRISC is OK).
> but:
> CCP1CON and CCP2CON are = 0x09 then (1001 - reset pin on match)
> but the pin is always 0.
>
> Note that if I use CCPxCON = 0x0A (1010 - generate interrupt on match
> and pin remain
> unchanged), and if I add in the interrput management procedure:
>
> if (CCP1IF)
> {
>     CCP1IF = 0;
>     RC2 = 0;
> }
>
> if (CCP2IF)
> {
>     CCP2IF = 0;
>     RC1 = 0;
> }
>
> then it runs, the pins switch high and low!!!!!
> No other changes in my code!!!!
> Then the match is OK and also the interrpt is OK, then the module it
> runs.
> But in this way I will use 2 interrupt more than in the previous way,
> using CCPxCON = 0x09 .........
>
> I tried also the opposite way: set pin on match and reset the pin when
> TIMER1 goes in
> overflow (inside an interrupt procedure), with CCPxCON = 0x08 set output
> on match.
>
> There is something that I don't know about CCP?
> I've read the 16F877 manual (only 1 page for CCP) and the AN594 from
> microchip site, but this don't
> helped me.
>
> Someone can help me?
>
> Thank you very much in advance.
>
> Max
>
> P.S. I have some problem in receiving the messages from the list in
> these last days......
>
> --------------
> Massimiliano Ruggeri
> CEMOTER - C.N.R.
> National Research Council Of Italy
> Fluid Power Group
> www.cemoter.bo.cnr.it
>
>
>
>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: ####@####.####
> For additional commands, e-mail: ####@####.####
>

Subject: Re: CCP in compare mode problem with PIC16F877
From: Snail Instruments ####@####.####
Date: 9 May 2002 06:37:50 -0000
Message-Id: <3.0.6.16.20020509064230.372f382a@pop3.iol.cz>

Hi Massimiliano, 

I believe you cannot access the RC1 & RC2 via PORTC when the compare module controls the pin. There is also limitation on using two compares: "The compare(s) should be configured for the special event trigger, which clears TMR1".

What do you need to achieve - a low frequency PWM on two pins? I cannot come up with a strightforward solution right now, but it doesn't sound impossible.

Regards,

Josef

>I have a question related to CCP modules in PIC 16F877.
>
>There is someone that use CCP modules in compare mode?
>
>I have tried to use CCP1 and CCP2 in compare mode, using
>TIMER1.
>....
Subject: Re: CCP in compare mode problem with PIC16F877
From: Ulrich Dziergwa ####@####.####
Date: 9 May 2002 08:22:11 -0000
Message-Id: <3CDA21D0.6A225BA@web.de>

Hi Massimiliano

massimiliano ruggeri wrote:
> 
> Hi All,
> I have a question related to CCP modules in PIC 16F877.
> 
> There is someone that use CCP modules in compare mode?
> 
> I have tried to use CCP1 and CCP2 in compare mode, using
> TIMER1.
> My problem is to generate a PWM with a low period,
> impossible to reach using PWM mode and prescaler, also with a 4 MHz
> clock (and also I have a 5 K flash program, and dynamics at 1ms, then I
> would
> use a 20 MHz clock!!!).
> The frequency would be approximately 100  Hz or less.
> Then, fantastic compare mode feature, perfect for me!
> 
---------snip--------

I haven't used the CCP module, but i have generated two PWM signal for
two motors at about 100 to 250 Hz in Software. TMT0 delivers an
interrupt on a fixed frequency, and the real PWM is generated by
software. With 10 MHz clock (thats what I use), there is enough time to
do much more in the interrupt handler, that can only get better on 20
MHz.

Best regards
Ulrich Dziergwa
Subject: Re: CCP in compare mode problem with PIC16F877
From: massimiliano ruggeri ####@####.####
Date: 9 May 2002 09:08:43 -0000
Message-Id: <3CDA39D7.AE3F6FEB@cemoter.bo.cnr.it>

Hi all,
Thank you very much Josef, Ulrich and Stefano for the answer.

I have a backup solution: the solution is to use the CCPx modules
using the software interrput on match (the pin status remain unchanged),
using the CCPx match interrupt to reset the RCx pin and using the TIMER1
interrupt (on overflow with agood prescaler and preset for my base period for PWM)
to set the RCx pin; it runs properly. Total: 3 interrupt.

What I'm trying, is to use the Compare modules in the classical manner:
The TIMER1 (setting a right prescaler and preset) is used to have the
period that's necessary to have my desired frequency;
using the TIMER1 interrupt on overflow, I can set the PIN RC1 and RC2 high,
and (i believe) when the CCPx module match the actual TIMER1 value,
then without a interrupt, the PIN switch to low value.
In this way with only a interrupt I can control two PWM.

But unfortunately it seems not possible.

And I think that isn't a compiler problem or register setting, because I tryed this also using ICE2000
emulator, setting directly the pin status: You change RC1 status, you do a step and
someone (?) reset the pin!!!!!
Only if you change the CCP mode, then you can change the pin status.
Then I think that what Josef sed ("I believe you cannot access the RC1 & RC2 via PORTC
when the compare module controls the pin. ...") Is right!

If we use the CCP compare mode, reprogramming the "mode" (with CCP1CON and CCP2CON) and
match value every half period (every high pin status period and low pin status period)
of a PWM, then it runs (probably), but what's the difference on using classic interrupt software procedure?
Then next time I will buy a micro without CCP and I will save money!

Interrupt is good, but in my project i will use also interrupt for a CAN communication using the MCP2510 from
microchip and other interrupt for 3 frequential inputs from a hall effect sensor (flywheel).....
and also I tryed to use interrupt, but remeber that you must take in cont the interrupt latency time
(@ 4MHz with no prescaler for TIMER1, then TIMER1 runs @ 1MHz, it will be around 23 - 27 counts of TIMER1).

Using CCP in compare mode, you have the chance to be more precise, but I don't have now the final solution to do this.
What I see, is that the CCP in interrupt software mode is good and you don't have the problem of reprogramming
different values in TIMER1 (to identify the switch time for both pins), and also the interrupt are very fast (only two bit reset).

But it isn't the best way!

Best regards

and thank you for all.

Max

--------------
Massimiliano Ruggeri
CEMOTER - C.N.R.
National Research Council Of Italy
Fluid Power Group
####@####.####
www.cemoter.bo.cnr.it



Snail Instruments wrote:

> Hi Massimiliano,
>
> I believe you cannot access the RC1 & RC2 via PORTC when the compare module controls the pin. There is also limitation on using two compares: "The compare(s) should be configured for the special event trigger, which clears TMR1".
>
> What do you need to achieve - a low frequency PWM on two pins? I cannot come up with a strightforward solution right now, but it doesn't sound impossible.
>
> Regards,
>
> Josef

[<<] [<] Page 1 of 1 [>] [>>]


Powered by ezmlm-browse 0.20.