Customizing TMR1

For general Flowcode discussion that does not belong in the other sections.
Post Reply
samtin
Posts: 52
http://meble-kuchenne.info.pl
Joined: Sat Jul 10, 2021 2:43 pm
Has thanked: 12 times
Been thanked: 6 times

Customizing TMR1

Post by samtin »

Hello everyone,
I tried to make a custom TMR1 for PIC16F877A and visualize the signals on pin A0 on the oscilloscope, but it doesn't compile.
Can anyone help me? I'm using Flowcode 10.
Attachments
test TMR1.fcfx
(12.06 KiB) Downloaded 10 times

Steve-Matrix
Matrix Staff
Posts: 1737
Joined: Sat Dec 05, 2020 10:32 am
Has thanked: 252 times
Been thanked: 409 times

Re: Customizing TMR1

Post by Steve-Matrix »

It looks like the capitalisation for the registers is wrong. For example, use "INTCONbits.PEIE = 1;"

See the Wiki entry here:
https://www.flowcode.co.uk/wiki/index.p ... -_PICmicro

NOTE: it looks like the images on that page are out of date, but the text itself seems to be correct. I will replace the images to avoid confusion.

samtin
Posts: 52
Joined: Sat Jul 10, 2021 2:43 pm
Has thanked: 12 times
Been thanked: 6 times

Re: Customizing TMR1

Post by samtin »

Thank you very much, it worked.

samtin
Posts: 52
Joined: Sat Jul 10, 2021 2:43 pm
Has thanked: 12 times
Been thanked: 6 times

Re: Customizing TMR1

Post by samtin »

Hello everyone,
I didn't get any signals on pin A0. Can anyone help me?
What is the mechanism of the custom code?
T1CON is the register where I select the prescale bits, but where are the postscale bits selected?
What is the register for setting the final value?

Here I found the custom code:
https://www.flowcode.co.uk/wiki/index.p ... -_PICmicro
Attachments
test TMR1.fcfx
(12.32 KiB) Downloaded 5 times

Steve-Matrix
Matrix Staff
Posts: 1737
Joined: Sat Dec 05, 2020 10:32 am
Has thanked: 252 times
Been thanked: 409 times

Re: Customizing TMR1

Post by Steve-Matrix »

There is a "Timer 1" interrupt for that device in Flowcode. Would using that be better or do you specifically need a custom version?

The Custom Interrupt feature is a more advanced feature that requires a knowledge of C code and the registers in the chip and so it's often much easier to make do with the inbuilt interrupts if they have the functionality you require.

samtin
Posts: 52
Joined: Sat Jul 10, 2021 2:43 pm
Has thanked: 12 times
Been thanked: 6 times

Re: Customizing TMR1

Post by samtin »

The existing code does not generate any signal on pin A0.
Why? The oscilloscope is connected to pin A0.

Enable code:
T1CON = 0x79; // Start timer with Internal clock source, prescaler = 1:8
INTCONbits.PEIE = 1; // Enable peripheral interrupts
INTCONbits.GIE = 1; // Enable global interrupts
PIE1bits.TMR1IE = 1; // Enable Timer 1 interrupts

Disable code:
PIE1bits.TMR1IE = 0; // Disable Timer 1 interrupts

Handler code:
if (PIR1 & (1 << TMR1IF)) // Check to see if the interrupt flag is set
{
FCM_%n(); // Call Flowcode Macro
PIR1bits.TMR1IF= 0; // Clear interrupt flag
}

Do I need to add more code to the existing one?

samtin
Posts: 52
Joined: Sat Jul 10, 2021 2:43 pm
Has thanked: 12 times
Been thanked: 6 times

Re: Customizing TMR1

Post by samtin »

I am really interested in custom timing and I am trying
to observe how it works, but unfortunately it does not work.

Steve-Matrix
Matrix Staff
Posts: 1737
Joined: Sat Dec 05, 2020 10:32 am
Has thanked: 252 times
Been thanked: 409 times

Re: Customizing TMR1

Post by Steve-Matrix »

Ok, I understand. I suggest then you try using the inbuilt Timer 1 interrupt and look at the C code that is generated. For example, the following shows the custom code and the inbuilt code and from that you should be able to see how it works.

The datasheet for the chip should also have a lot of useful information about the settings required for T1CON.
Attachments
Screenshot 2026-02-04 120433.png
Screenshot 2026-02-04 120433.png (31.14 KiB) Viewed 162 times

BenR
Matrix Staff
Posts: 2110
Joined: Mon Dec 07, 2020 10:06 am
Has thanked: 561 times
Been thanked: 744 times

Re: Customizing TMR1

Post by BenR »

Hello,

Your custom interrupt code looks ok to me.

Have you tried a one second flasher test to confirm the basic setup is ok and the chip is running?
https://www.flowcode.co.uk/wiki/index.p ... ED_flasher

Your current setup suggests an external 19.6608MHz crystal is that correct?

Post Reply