[PIC] Compare Mode

classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|

[PIC] Compare Mode

David Duffy (AVD)
I have a PIC16F1828 running from the internal 4MHz oscillator. I use the
various timers regulatly, but don't recall using the CCP modules before.
I'm using MPLABX and XC8.

There is a 100Hz interrupt (INT0) from an optocoupler for zero cross
sync. I've set timer 1 to Fosc/4 and no prescaler, so that should be
ticking over at 1us increments. I'm trying to use CCP1, CCP2 and CCP3 to
get an interrupt at three different points from the zero cross interrupt.

CCP1CON is set to 0x0A (compare with interrupt) and CCPR1 is set to 5000
(decimal) when the INT0 interrupt occurs. I'm clearing a pin when INT0
occurs and setting it when the CCP1IF interrupt is serviced.

I'm getting a much longer period (LED off time) than the 5ms I expected.
The timing is not even proportional to the values I enter. Am I missing
something fundamental about how CCP works?

David...
--
http://www.piclist.com/techref/piclist PIC/SX FAQ & list archive
View/change your membership options at
http://mailman.mit.edu/mailman/listinfo/piclist
Reply | Threaded
Open this post in threaded view
|

Re: [PIC] Compare Mode

Harold Hallikainen-3
This sounds like a phase control light dimmer! I did a four channel one
with a single CCP register, figuring out which triac I needed to turn on
first, loading the CCP register with that value, then when I got the
interrupt, turned on the triac and loaded the CCP register with the next
value I needed. I have not looked at that in a long time (more than 10
years). I think I started with a 17C42 and ended up using an 18F452. If
indeed you're doing a light dimmer, I'd load the CCP registers and clear
the timer, and turn off the outputs on a zero cross. Then each CCP
interrupt would turn on an output and clear the interrupt flag.

This is probably not much help since it's been more than 10 years since I
worked on it.

Good luck!

Harold


> I have a PIC16F1828 running from the internal 4MHz oscillator. I use the
> various timers regulatly, but don't recall using the CCP modules before.
> I'm using MPLABX and XC8.
>
> There is a 100Hz interrupt (INT0) from an optocoupler for zero cross
> sync. I've set timer 1 to Fosc/4 and no prescaler, so that should be
> ticking over at 1us increments. I'm trying to use CCP1, CCP2 and CCP3 to
> get an interrupt at three different points from the zero cross interrupt.
>
> CCP1CON is set to 0x0A (compare with interrupt) and CCPR1 is set to 5000
> (decimal) when the INT0 interrupt occurs. I'm clearing a pin when INT0
> occurs and setting it when the CCP1IF interrupt is serviced.
>
> I'm getting a much longer period (LED off time) than the 5ms I expected.
> The timing is not even proportional to the values I enter. Am I missing
> something fundamental about how CCP works?
>
> David...
> --
> http://www.piclist.com/techref/piclist PIC/SX FAQ & list archive
> View/change your membership options at
> http://mailman.mit.edu/mailman/listinfo/piclist
>


--
FCC Rules Updated Daily at http://www.hallikainen.com
Not sent from an iPhone.
--
http://www.piclist.com/techref/piclist PIC/SX FAQ & list archive
View/change your membership options at
http://mailman.mit.edu/mailman/listinfo/piclist
Reply | Threaded
Open this post in threaded view
|

Re: [PIC] Compare Mode

David Duffy (AVD)
Hi Harold,
It is indeed phase control. There is a need to switch the output on a
specific time after the zero cross, but turn it off shortly before the
next zero cross occurs. I also need to do some other stuff at the mid
point of each half cycle, hence the multiple CCP use.

While writing this reply I realised my stupid mistake. I had not set the
CCPx interrupt enables. Things seem to be working correctly now. The
reason I was getting wacky timing was that the interrupt flags were
being checked, but only as a by-product of another interrupt sharing the
same vector. Doh!
David...

On 18/09/2020 1:27 pm, Harold Hallikainen wrote:

> This sounds like a phase control light dimmer! I did a four channel one
> with a single CCP register, figuring out which triac I needed to turn on
> first, loading the CCP register with that value, then when I got the
> interrupt, turned on the triac and loaded the CCP register with the next
> value I needed. I have not looked at that in a long time (more than 10
> years). I think I started with a 17C42 and ended up using an 18F452. If
> indeed you're doing a light dimmer, I'd load the CCP registers and clear
> the timer, and turn off the outputs on a zero cross. Then each CCP
> interrupt would turn on an output and clear the interrupt flag.
>
> This is probably not much help since it's been more than 10 years since I
> worked on it.
>
> Good luck!
>
> Harold
>
>
>> I have a PIC16F1828 running from the internal 4MHz oscillator. I use the
>> various timers regulatly, but don't recall using the CCP modules before.
>> I'm using MPLABX and XC8.
>>
>> There is a 100Hz interrupt (INT0) from an optocoupler for zero cross
>> sync. I've set timer 1 to Fosc/4 and no prescaler, so that should be
>> ticking over at 1us increments. I'm trying to use CCP1, CCP2 and CCP3 to
>> get an interrupt at three different points from the zero cross interrupt.
>>
>> CCP1CON is set to 0x0A (compare with interrupt) and CCPR1 is set to 5000
>> (decimal) when the INT0 interrupt occurs. I'm clearing a pin when INT0
>> occurs and setting it when the CCP1IF interrupt is serviced.
>>
>> I'm getting a much longer period (LED off time) than the 5ms I expected.
>> The timing is not even proportional to the values I enter. Am I missing
>> something fundamental about how CCP works?
>>
>>

--
___________________________________________
David Duffy        Audio Visual Devices P/L
Unit 8, 10 Hook St, Capalaba 4157 Australia
Ph: +61 7 38235717      Fax: +61 7 38234717
Our Web Site: www.audiovisualdevices.com.au
___________________________________________

--
http://www.piclist.com/techref/piclist PIC/SX FAQ & list archive
View/change your membership options at
http://mailman.mit.edu/mailman/listinfo/piclist
Reply | Threaded
Open this post in threaded view
|

Re: [PIC] Compare Mode

Harold Hallikainen-3
Glad you found the problem!

Harold

> Hi Harold,
> It is indeed phase control. There is a need to switch the output on a
> specific time after the zero cross, but turn it off shortly before the
> next zero cross occurs. I also need to do some other stuff at the mid
> point of each half cycle, hence the multiple CCP use.
>
> While writing this reply I realised my stupid mistake. I had not set the
> CCPx interrupt enables. Things seem to be working correctly now. The
> reason I was getting wacky timing was that the interrupt flags were
> being checked, but only as a by-product of another interrupt sharing the
> same vector. Doh!
> David...
>
> On 18/09/2020 1:27 pm, Harold Hallikainen wrote:
>> This sounds like a phase control light dimmer! I did a four channel one
>> with a single CCP register, figuring out which triac I needed to turn on
>> first, loading the CCP register with that value, then when I got the
>> interrupt, turned on the triac and loaded the CCP register with the next
>> value I needed. I have not looked at that in a long time (more than 10
>> years). I think I started with a 17C42 and ended up using an 18F452. If
>> indeed you're doing a light dimmer, I'd load the CCP registers and clear
>> the timer, and turn off the outputs on a zero cross. Then each CCP
>> interrupt would turn on an output and clear the interrupt flag.
>>
>> This is probably not much help since it's been more than 10 years since
>> I
>> worked on it.
>>
>> Good luck!
>>
>> Harold
>>
>>
>>> I have a PIC16F1828 running from the internal 4MHz oscillator. I use
>>> the
>>> various timers regulatly, but don't recall using the CCP modules
>>> before.
>>> I'm using MPLABX and XC8.
>>>
>>> There is a 100Hz interrupt (INT0) from an optocoupler for zero cross
>>> sync. I've set timer 1 to Fosc/4 and no prescaler, so that should be
>>> ticking over at 1us increments. I'm trying to use CCP1, CCP2 and CCP3
>>> to
>>> get an interrupt at three different points from the zero cross
>>> interrupt.
>>>
>>> CCP1CON is set to 0x0A (compare with interrupt) and CCPR1 is set to
>>> 5000
>>> (decimal) when the INT0 interrupt occurs. I'm clearing a pin when INT0
>>> occurs and setting it when the CCP1IF interrupt is serviced.
>>>
>>> I'm getting a much longer period (LED off time) than the 5ms I
>>> expected.
>>> The timing is not even proportional to the values I enter. Am I missing
>>> something fundamental about how CCP works?
>>>
>>>
>
> --
> ___________________________________________
> David Duffy        Audio Visual Devices P/L
> Unit 8, 10 Hook St, Capalaba 4157 Australia
> Ph: +61 7 38235717      Fax: +61 7 38234717
> Our Web Site: www.audiovisualdevices.com.au
> ___________________________________________
>
> --
> http://www.piclist.com/techref/piclist PIC/SX FAQ & list archive
> View/change your membership options at
> http://mailman.mit.edu/mailman/listinfo/piclist
>


--
FCC Rules Updated Daily at http://www.hallikainen.com
Not sent from an iPhone.
--
http://www.piclist.com/techref/piclist PIC/SX FAQ & list archive
View/change your membership options at
http://mailman.mit.edu/mailman/listinfo/piclist