Example code does nothing

For Flowcode users to discuss projects, flowcharts, and any other issues related to Flowcode 5.
To post in this forum you must have a registered copy of Flowcode 5 or higher.

Moderator: Benj

Post Reply
bluejetsthree
Flowcode v5 User
Posts: 17
Joined: Mon Sep 16, 2013 3:04 am
Been thanked: 1 time
Contact:

Example code does nothing

Post by bluejetsthree »

Trying to understand how I can count 10 pulses in one second and I am working through the examples of version 5.
However, these either do nothing or get stuck in an obvious loop so where am I going wrong looking at these examples??
Attachments
2. Interrupt every second.fcf
(6 KiB) Downloaded 252 times

bluejetsthree
Flowcode v5 User
Posts: 17
Joined: Mon Sep 16, 2013 3:04 am
Been thanked: 1 time
Contact:

Re: Example code does nothing

Post by bluejetsthree »

Managed to work out something here by modifying things....
Still can't work out why it takes approx 15 cycles to advance the "count".
All new to me so forgive my ignorance.
Attachments
10countsec.fcf
(14.5 KiB) Downloaded 266 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: Example code does nothing

Post by medelec35 »

Hi bluejetsthree,
Your flowchart would not work on hardware, since configuration settings and timer interrupt settings are both wrong.
So each point in turn.
Configuration settings:
Assuming your using a crystal of 19.66MHz then your Oscillator (Build,Project Options, Configure chip) Should be set for HS since frequency is greater then 4MHz.
See:http://www.matrixmultimedia.com/mmforum ... =26&t=6936
Watchdog should be off, until you specifically want it on then it can tackled.
Mater Clear Enabled should only be used if your using a pull-up resistor between MCLR and +5V otherwise it should be disabled.
Low voltage programming should always be disabled.

Timer Interrupt settings:
Double click on the timer interrupt component, then click on Properties.
Since your using the internal timer interrupt you will need to change Clock Source Select to Internal Clock

You have got interrupt frequency set at 19200Hz which means interrupt macro is accessed 19200 times a second = once every 1/19200 = 52us
Since you have

Code: Select all

 If count < 75 then Update = 1
etc then update is going to be every 75 * 52uS = 3.9ms
To correct this, you will need to either change Prescaler Rate from 1:1 to !:256 (Recommended)
Or change If count < 75 to If count < 19200 (Not Recommended)

What do you want to happen after 10 counts of hall effect being triggered within 1 second?
Since in your flowchart it just drops off at the end of main, so your hard ware will just stop.

I have modified your flowchart so when you run it, you can see from the LED's whats going on.
You will need to remember the simulation speed is much slower than real life, so timer interrupt of one second in simulator can take 33 seconds of real time.

Feel free to remove from the flowchart what you don't' need, only added extras for demonstration purposes.

Martin
Attachments
10countsec V2.fcf
(19.16 KiB) Downloaded 284 times
Martin

bluejetsthree
Flowcode v5 User
Posts: 17
Joined: Mon Sep 16, 2013 3:04 am
Been thanked: 1 time
Contact:

Re: Example code does nothing

Post by bluejetsthree »

Thanks so much for your reply.
I did not expect such a detailed response.
I will take a look at your changes and try to work it out from there.
To answer your query, once it has triggered 10 times, that will be the signal to say the engine is running. 10 pulses in one second ....600rpm.
Then I can start other measurements for advance/ retard. All model engine monitoring.

Thanks again, great help.

bluejetsthree
Flowcode v5 User
Posts: 17
Joined: Mon Sep 16, 2013 3:04 am
Been thanked: 1 time
Contact:

Re: Example code does nothing

Post by bluejetsthree »

I believe I have it ok now but perhaps a quick scan..??

Run at 4 meg ...interrupt frequency 15hz....settings as per instructed except I left xtal at XT.

Is that correct...??

Also, as mentioned above, this is just part of a larger program. After the 600rpm count (engine running)the program can continue.
Attachments
10countsecV3.fcf
(14.77 KiB) Downloaded 254 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: Example code does nothing

Post by medelec35 »

Hi bluejetsthree,
bluejetsthree wrote:I believe I have it ok now but perhaps a quick scan..??
You have got interrupt set at 15.259Hz. So that means every second interrupt macro is accessed 15 times.
However you have got

Code: Select all

If count < 10 then Run_freq = frequency 
Since 10 is less then 15.259 then less then 1 second ( 1/15.259*10 = 0.655 sec) has elapsed.
So when you multiply by 60 to get RPM the RPM will be out by a fair bit.

I have modified your flowchart to use RPM directly (assuming 1 hall effect device is fitted)
Since your now using 4MHz (using a crystal or internal oscillator? Since with internal osc, no external crystal or capacitor will be required)
I have changed timer0 to timer2 for increased accuracy.
No the interrupt is exactly 25.00Hz. Its fine using timer 2 so long as your not going to use PWM component in the future.

For future reference:
When you was using timer0 you placed

Code: Select all

tmr0 = 0x00;
within timer interrupt.
This is not required since the timer interrupt is only accessed when tmr0 rolls over from 255 to 0 any way.
So at the point tmr0 = 0x00; it should be at 0 anyway.
Attachments
10countsecV4.fcf
(14.9 KiB) Downloaded 286 times
Martin

bluejetsthree
Flowcode v5 User
Posts: 17
Joined: Mon Sep 16, 2013 3:04 am
Been thanked: 1 time
Contact:

Re: Example code does nothing

Post by bluejetsthree »

Ok...I can see now the 4Mhz divided down.

4Meg/4 to give the clock speed(1Meg) and then prescaled 1:16 with rollover at 250 and post-scale at 10 all divides down to 25 hz.

At this, the program will cycle through the interrupt 25 times a second which will add 1 to the “count” on each pass until it reaches 25.

Then it will take the alternate route through the decision to set the “update”, transfer the “frequency” (after *60 to give minute) and then reset “count” and the “frequency” registers then exit the interrupt.

If speed is over 600 then led goes off.

If I have the sim speed set to 1000, how long in real time will this take to initiate the first of the 25 “counts”.

Any pointers on how I can work this out for myself?

Just like to be able to see the registers are clicking over so I can verify any program I write.

Thanks....

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: Example code does nothing

Post by medelec35 »

bluejetsthree wrote:If I have the sim speed set to 1000, how long in real time will this take to initiate the first of the 25 “counts”.
No idea, but you can set a break point by right clicking on Tick=0 and select set breakpoint.
Then run simulation and wait for the flowchart to stop at the breakpoint.
Then select run and time how long it takes for flowchart to stop at the break point for the second time, then x result by 25

Flowcode V6 is much faster than Flowcode V5 perhaps it would be interesting to make a comparison?

Another way of checking how long things will take on hardware by not using any hardware is by using a third party simulator like
Real pic simulator:
http://digitalelectrosoft.com/pic-simulator

Pic sim ide:
http://www.oshonsoft.com/pic.html

Or the free simulator built in to MPLAB:
http://www.microchip.com/stellent/idcpl ... t=SW007002

Not used the latter but have got the 1st two options.
Since you will need the pay for the 1st two, it will be best to try as a demo to see if they meed expectations.
Martin

bluejetsthree
Flowcode v5 User
Posts: 17
Joined: Mon Sep 16, 2013 3:04 am
Been thanked: 1 time
Contact:

Re: Example code does nothing

Post by bluejetsthree »

ok...i will take a look at them.

I have a the Oshonsoft somewhere I think.

Here’s what I did to view the program running. (Just to see it works the way I wanted)
On your version 4, I made these changes.

Set both the prescaller and postscale values at 1:1.
That gave an interrupt frequency of 4000hz.
Set the sim speed to 1000 so I can view the variables and then selected all variables to view.
This ran a cycle of interrupt around 3 seconds or so and one can see the changes quite clearly.
Thanks once again for your help. Much appreciated.

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: Example code does nothing

Post by medelec35 »

Oh i see what your trying to do.
An alternative just for simulation is place a call timer interrupt within main.
you can then keep pressing F8 to single step if you like as well as run.
Setting breakpoints is a very handy.
Martin

Post Reply