Pic18F87K22 - Frequency reader

For Flowcode users to discuss projects, flowcharts, and any other issues related to Flowcode 6.

Moderator: Benj

Post Reply
r_teixeir
Posts: 96
Joined: Fri Jul 15, 2016 10:51 am
Has thanked: 24 times
Been thanked: 5 times
Contact:

Pic18F87K22 - Frequency reader

Post by r_teixeir »

Hi all, Iam trying to write a code, where I use two timers (Timer0 and Timer1) on flowcode to read frequency., but iam having a hard time on my C code.

Explanation of the code:
Timer0 is used in a 16 bit counter mode, the external signal to be measured is applied to timer0 clock input T0CKI(RA4).
Timer1 Interrupts every 125ms, crating a 1s time window.

The frequency to be measured is connected to the clock input, the counter is enabled for a known time window, and the total count is read. Since each count corresponds to a clock pulse of the external signal, then the frequency can be measured.

Can anyone help? Thanks

Rod
Attachments
Frequency_Reader.fcfx
(8.67 KiB) Downloaded 367 times

medelec35
Matrix Staff
Posts: 9520
Joined: Sat May 05, 2007 2:27 pm
Location: Northamptonshire, UK
Has thanked: 2585 times
Been thanked: 3815 times
Contact:

Re: Pic18F87K22 - Frequency reader

Post by medelec35 »

Hi Rod,
As you are using FC V6 that uses BoostC.
The C code you have entered was not in the correct format.
For example you have got

Code: Select all

T0CON.TMR0ON = 1;

Registers with boost C must be in lower case and bit names in upper case.
So you should have

Code: Select all

t0con.TMR0ON = 1;

Code: Select all

if 
conditions should be placed within brackets & there is no requirement for semicolon after.
Also if not using curly braces then if condition is not true the only the next statement down will be ignored, but following statements will still be carried out.
so only if you want all the statements to be carried out if if is true, then you need something like this:

Code: Select all

if (intcon.TMR0IF == 1)
{
FCL_OVERFLOW++;
intcon.TMR0IF = 0;
}
I have only altered your C code for your flowchart so it compiles OK.
I have not tested the functionality to see if it works on hardware.

Martin
Attachments
Frequency_Reader 2.fcfx
(8.68 KiB) Downloaded 328 times
Martin

r_teixeir
Posts: 96
Joined: Fri Jul 15, 2016 10:51 am
Has thanked: 24 times
Been thanked: 5 times
Contact:

Re: Pic18F87K22 - Frequency reader

Post by r_teixeir »

Hi Medelec, thanks for replying and the corrections of the code. Anyway, the code still not running. I dont know If Iam missing something.
Right after my equation for the elapsed time, Iam suppose to have a conversion of longtoString that wasnt able to write! In normal c code i would write:

LongWordToStr(Elapsed, Txt); // Long to string conversion
Lcd_Cmd(_LCD_CLEAR); // Clear LCD
Lcd_Out(1,1,"Frequency (HZ)"); // Display heading
Lcd_Out(2,1,Txt); // Display measured frequency
Delay_ms(100);

but on flowcode Iam kind of stuck!
Anytips ...? Thanks again

Rod

medelec35
Matrix Staff
Posts: 9520
Joined: Sat May 05, 2007 2:27 pm
Location: Northamptonshire, UK
Has thanked: 2585 times
Been thanked: 3815 times
Contact:

Re: Pic18F87K22 - Frequency reader

Post by medelec35 »

Hi Rod,
Your welcome.
When I get a little spare time I will take a look and see if I can spot the issue.

Martin
Martin

r_teixeir
Posts: 96
Joined: Fri Jul 15, 2016 10:51 am
Has thanked: 24 times
Been thanked: 5 times
Contact:

Re: Pic18F87K22 - Frequency reader

Post by r_teixeir »

Hi Medelec, I tried to compile using the pic18F87K22 your example file for frequency meter using the ccp4, but still, I might be doing something wrong while coding.
I am trying to get an example of frequency meter using this Pic18F87K22 , on flowcode, but I cant get work.

I appreciate the help

Thanks

Rod
Attachments
Pulse & frequency Meter using ccp.fcfx
(10.2 KiB) Downloaded 323 times

medelec35
Matrix Staff
Posts: 9520
Joined: Sat May 05, 2007 2:27 pm
Location: Northamptonshire, UK
Has thanked: 2585 times
Been thanked: 3815 times
Contact:

Re: Pic18F87K22 - Frequency reader

Post by medelec35 »

hi Rod,
Sorry for the delay, not had a lot of time recently.
I have attached a very basic frequency reader which works with 16F1937
Injecting a 1MHz frequency the LCD dispalays 1000399.
I can't test the flowchart created for your device as I don't have any to hand.

Martin
Attachments
Frequency_Reader 1a 16F1937.fcfx
(10.51 KiB) Downloaded 367 times
Frequency_Reader 1a 18F87K22.fcfx
(10.88 KiB) Downloaded 352 times
Martin

r_teixeir
Posts: 96
Joined: Fri Jul 15, 2016 10:51 am
Has thanked: 24 times
Been thanked: 5 times
Contact:

Re: Pic18F87K22 - Frequency reader

Post by r_teixeir »

Hi Medelec, the program worked! Thanks! I had to change the ports, instead of RC.2 as input from your program, I changed for Trisa.4, and it worked.

With the input on RC.2 the program did not run on hardware.

Thanks again

Rod

medelec35
Matrix Staff
Posts: 9520
Joined: Sat May 05, 2007 2:27 pm
Location: Northamptonshire, UK
Has thanked: 2585 times
Been thanked: 3815 times
Contact:

Re: Pic18F87K22 - Frequency reader

Post by medelec35 »

Hi Rod,
Glad it works for you.
Thanks for letting me know.
r_teixeir wrote:With the input on RC.2 the program did not run on hardware.
I had not changed any settings, that's what they are on the flowchart you posted (Pulse & frequency Meter using ccp.fcfx).
I personally don't use C code for i/p & o/p.
I just use the standard flowchart i/p & o/p.

Martin
Martin

Post Reply