PWM + Сapture + Сomparison

Post here to discuss any new features, components, chips, etc, that you would like to see in Flowcode.
carworker
Posts: 28
http://meble-kuchenne.info.pl
Joined: Sun Jan 01, 2023 11:01 am
Location: UA
Been thanked: 3 times
Contact:

Re: PWM + Сapture + Сomparison

Post by carworker »

Believe me, I tried different options. Even this one. Without ";" if(PIR1 & (1 << CCP1IF)) // You wrote about this before.
And this option
if (PIR1=0b00000100) //Check if the CCP1 interrupt flag is set
{
FCM_%n(); //read int in body
PIR1bits.CCP1IF = 0; // Clear interrupt flag
}
// There are no changes

mnfisher
Valued Contributor
Posts: 1339
Joined: Wed Dec 09, 2020 9:37 pm
Has thanked: 126 times
Been thanked: 667 times

Re: PWM + Сapture + Сomparison

Post by mnfisher »

The if(PIR1=0b000100) actually sets PIR1 to be 0b... To test for equality you need to use == (though here I would just test the relevant bit).

To strip things back a bit.

Can you measure a single pulse (and I would just try every rising pulse and not swap direction for the moment) with TMR0 disabled (not used). Then add in TMR0 - can you still measure a pulse. Then try adding a TMR0 counter. Does this break things?

What clock are you using - set as HS (in properties) - so I assume you have a 20MHz crystal attached. Does a 1s blinkie work AOK?

Have just tested a timer and pulse counter on the PIC12 and it seems to work okay - timer increases as expected and pulses still measured

Martin

carworker
Posts: 28
Joined: Sun Jan 01, 2023 11:01 am
Location: UA
Been thanked: 3 times
Contact:

Re: PWM + Сapture + Сomparison

Post by carworker »

if(PIR1=0b000100) //it works like that too . if (CCP1IF) //this works too
I have done everything you recommend more than once. Capture works great until TMR0 is added to the program body. And then TMR0 interrupts somehow magically penetrate TMR1, thereby distorting measurements.
Microchip recommends stopping TM0 before reading CCPR1H CCPR1L or reading them 2 times.
I wonder if you use Flowcode to write to the chip?

LeighM
Valued Contributor
Posts: 437
Joined: Mon Dec 07, 2020 1:00 pm
Has thanked: 81 times
Been thanked: 235 times

Re: PWM + Сapture + Сomparison

Post by LeighM »

if(PIR1=0b000100) //it works like that too . if (CCP1IF) //this works too
Just to reiterate what Martin said,
and in addition, those two statements will always evaluate to true,
so you will always run the true clause code,
this will have unintended consequences.

carworker
Posts: 28
Joined: Sun Jan 01, 2023 11:01 am
Location: UA
Been thanked: 3 times
Contact:

Re: PWM + Сapture + Сomparison

Post by carworker »

If anyone is still interested. I did it! Now TM0 does not affect TM1. A month ago I did not know S. As it turned out, this is not a problem. Thank you Martin. You helped. Indeed, Flowcode is a flexible system. You just need to learn to adapt this environment to your tasks.
Best regards, Petro
Attachments
913_CCP_V2.rar
(90.25 KiB) Downloaded 37 times

mnfisher
Valued Contributor
Posts: 1339
Joined: Wed Dec 09, 2020 9:37 pm
Has thanked: 126 times
Been thanked: 667 times

Re: PWM + Сapture + Сomparison

Post by mnfisher »

Great that you've got it up and running.

Glad to have helped a little along the way - and I learnt something too, I'd not seen about the capture compare facility in PICs before and it looks very useful....

Martin

chipfryer27
Valued Contributor
Posts: 1434
Joined: Thu Dec 03, 2020 10:57 am
Has thanked: 337 times
Been thanked: 497 times

Re: PWM + Сapture + Сomparison

Post by chipfryer27 »

Hi

I was following with interest and it saved me from a ton of work to figure out.

Regards

Post Reply