TMRO

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

Moderators: Benj, Mods

Post Reply
Ondra
Posts: 325
Joined: Wed Aug 29, 2007 7:33 pm
Been thanked: 2 times
Contact:

TMRO

Post by Ondra »

Good day again. Got another question.
I have a board running a PIC 18F258 with an 18.432MHz crystal. In TMRO properties when I select to use the transition on T0CKI pin my program does not run. When I select Internal clock(CLKO) the program runs fast, does not keep time. I The program is very simple it is supposed to capture data form 2 sensors and print the numbers to the RS232 port every 10 Seconds, but the output is happening at about ever 1 second. TMRO prescaler is set to 1:256 which with a clock speed of 1843200 give an Interrupt Freq of: 70.3125Hz but again when I select the what I think is the external clock nothing happens. But when I select the internal clock the program runs but fast. Got any Idea about what I should check. Also I am using MPLAB with PIC Start Plus as my programmer.

Ondra

User avatar
Benj
Matrix Staff
Posts: 15312
Joined: Mon Oct 16, 2006 10:48 am
Location: Matrix TS Ltd
Has thanked: 4803 times
Been thanked: 4314 times
Contact:

Post by Benj »

Hello Ondra

What is your hardware configured to use.

Eg in Chip -> Configure -> Switch to expert -> are you using the HS Oscillator mode.

You are correct in using the CLK0 this is the internal clock but it is based on the external clock / 4. This is assuming that you are in HS mode.

Also make sure that the watchdog timer and low voltage programming are disabled in the configuration settings.

Ondra
Posts: 325
Joined: Wed Aug 29, 2007 7:33 pm
Been thanked: 2 times
Contact:

Post by Ondra »

Yes I am using the HS mode. Is this correct.
Yes

User avatar
Benj
Matrix Staff
Posts: 15312
Joined: Mon Oct 16, 2006 10:48 am
Location: Matrix TS Ltd
Has thanked: 4803 times
Been thanked: 4314 times
Contact:

Post by Benj »

Hello Ondra

If you send me your program then I will give it a going over and see if I can spot whats going wrong.

My email is ben@matrixmultimedia.co.uk

Ondra
Posts: 325
Joined: Wed Aug 29, 2007 7:33 pm
Been thanked: 2 times
Contact:

Post by Ondra »

I think I found the problem. I was calling a routine that updated a variable call seconds every time the interrupt fired. I understand that I should have a separate interrupt routine counter variable.
Question: Should I put a Macro call inside the interrupt routine or should I just reference the interrupt variable in this case TMR0. Also My Interrupt Freq is 70.3125Hz should I use a prescaler value that calculates to a whole number or should I us the 70.3125 in my "if TMR0= Interrupt Freq seconds=seconds+1" routine.

Ondra

User avatar
Benj
Matrix Staff
Posts: 15312
Joined: Mon Oct 16, 2006 10:48 am
Location: Matrix TS Ltd
Has thanked: 4803 times
Been thanked: 4314 times
Contact:

Post by Benj »

I have had a go with your program and this should work a lot better.

I have changed the Timer0 prescalar so that it produces an integer frequency.

The program would work better if the prescalar could be lower. Maybe you could use a different crystal to achieve a better timeout value. eg a 19.6608MHz crystal allows for an exact timeout of 75Hz instead of the current 1125Hz.

The program should now do the following. Update variables for seconds, minutes, hours, days and also print out this is a test onto the RS232 every 30 seconds.

Ondra
Posts: 325
Joined: Wed Aug 29, 2007 7:33 pm
Been thanked: 2 times
Contact:

Post by Ondra »

Thanks again Ben.
Got a question for you. When I run the program it prints "this a test" about 37 times why and how do I print it just once.

Ondra

User avatar
Benj
Matrix Staff
Posts: 15312
Joined: Mon Oct 16, 2006 10:48 am
Location: Matrix TS Ltd
Has thanked: 4803 times
Been thanked: 4314 times
Contact:

Post by Benj »

Hello Ondra

The previous program printed this is a test every time the Seconds variable was at 30. eg once a minute at 30 seconds.

You will need to modify the program so that this message is printed at the start before entering the main loop.

If you wanted to output the time via the RS232 then this could be done in a second macro in the main loop.

You will also need a third macro to break numbers into 1 - 2 ascii characters.

Post Reply