Help needed!

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

jjw
Posts: 78
Joined: Sat Aug 25, 2012 5:35 am
Has thanked: 71 times
Been thanked: 9 times
Contact:

Help needed!

Post by jjw »

I’m designing timekeeping system for control line speed model F2G.
The sensor is designed with two Phototransistors in order to measure the speed. One lap is 100 m it will take from 1.2 s to 1.6 s depending of the speed.

My question is this chart acting the opposite way when pushing the push-button what longer I am push getting greater value. Should it be the opposite way or am I wrong?
Thanks in advance for your help.

Wbr,
jjw
Attachments
Timing systemv1.fcf
(41.16 KiB) Downloaded 1025 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: Help needed!

Post by medelec35 »

Hi jjw,
No your not wrong at all Since speed = distance/time.

I would guess you will need to time between the first pulse and second pulse then use speed (K/h) = 100/time in seconds * 3.6
Since 1 m/s = 3.6 k/h

Example:
If the time between for 100 meters pulse is 1.2 seconds
Speed = 100/1.2 * 3.6 = 300 Km/h
or
If time take is 1.6 seconds then:
Speed = 100/1.6 * 3.6 = 225 Km/h

That is some fast laps!

Is that what speed you're expecting?

If not using floats (I personally would not)
The use milliseconds for timing.
Speed = 10000/(ms/10)*36/10
So for 1.2secs =1200ms
= 10000/120*36/10
= 298 K/h
Not that far off

Results will be different if using a calculator because calculators will be using whle numbers ad parts of whole numbers.
PIC maths if not using floats uses whole numbers only.

Hope this helps and I have got my fact correct?

If you give implementing this within your flowchart a go then if you get stuck I can help you further.

Martin
Martin

jjw
Posts: 78
Joined: Sat Aug 25, 2012 5:35 am
Has thanked: 71 times
Been thanked: 9 times
Contact:

Re: Help needed!

Post by jjw »

Thanks Martin to answering with so short notice.

”That is some fast laps! Is that what speed you're expecting?”

Yes it’s fast some decades ago it would have been not hard as it now…. I’m hoping to fly some 240…250 km/h during this season.

I understand what is missing in my flowchart but need some personal help. Any change to get it?


jjw

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: Help needed!

Post by medelec35 »

jjw wrote:Thanks Martin to answering with so short notice.
No problem, If I can help then I will.
jjw wrote: I’m hoping to fly some 240…250 km/h during this season.
Sounds interesting, hope it works out as you intended.
jjw wrote:but need some personal help. Any change to get it?
Yes I can help.

Just so as far as you can with the information provided, then post flowchart.

I will then take a look at and see if I can improve things.

Martin
Martin

jjw
Posts: 78
Joined: Sat Aug 25, 2012 5:35 am
Has thanked: 71 times
Been thanked: 9 times
Contact:

Re: Help needed!

Post by jjw »

Hi Martin,
This is the version which I’ve been testing in my hardware. Hopefully you can make the needed changes….

Wbr,
jjw
Attachments
Timing systemv2.fcf
(39.6 KiB) Downloaded 1018 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: Help needed!

Post by medelec35 »

Hi jjw,
jjw wrote:This is the version which I’ve been testing in my hardware. Hopefully you can make the needed changes….
You need to try and make the changes yourself as it's the only way to learn.
I have suggested the formula to try.
Once you have made the changes, I can look at your flowchart and assist you further.
Hint use timer interrupt to count in milliseconds.

Martin
Martin

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: Help needed!

Post by medelec35 »

Hi Jukka,
Got back late so not got time to test on hardware.

Attached is my first attempt.
Hopefully it work in a similar way you have in mind.

I have also added a time out function after 3 seconds has elapsed and port is not activated then hardware is reset and waiting for the start.

Martin
Attachments
Timing systemv3.fcf
(21.74 KiB) Downloaded 1018 times
Martin

jjw
Posts: 78
Joined: Sat Aug 25, 2012 5:35 am
Has thanked: 71 times
Been thanked: 9 times
Contact:

Re: Help needed!

Post by jjw »

Great thanks Martin you have done a lot of work for me. I will test the chart in my hardware later in the evening and let you know.

Wbr,
jjw

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: Help needed!

Post by medelec35 »

np's.
Does LCD still flash?
Martin

jjw
Posts: 78
Joined: Sat Aug 25, 2012 5:35 am
Has thanked: 71 times
Been thanked: 9 times
Contact:

Re: Help needed!

Post by jjw »

Does LCD still flash?
Only Timeout line when getting it.

Simulation in Flowcode seems to work quite well. In my hardware I get 6550km/h and Timeout message when program starts. After giving new pulse and I don’t get any new values in Lcd and no changes in Lcd.

I couldn’t use Real Pic Simulator since the Mcu is not supported….

Wbr,
jjw

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: Help needed!

Post by medelec35 »

jjw wrote:In my hardware I get 6550km/h and Timeout message when program starts.
Sounds like switch is floating so pulses are too quick.
If testing with a switch you must use a pull-down resistor between RB6 (pin27) and GND
Also don't forget the two rising pulses on real hardware has be be less than 3 seconds apart or you will get time out.
You can try pressing switch then pressing again 1 & 1/2 seconds later.

I'm assuming you are using a SPST N.O. momentary switch?


As for simulator, just change target for a microcontroller that's supported in Real pic.
Compile then load into real pic:
Real pic Timing1.png
(174.24 KiB) Downloaded 24601 times
Looks correct to me!

If using real pic, the function generator will show 1/2 the time indicated on LCD display.
This is as expected since timer is working on rising edge only.

I have tried flowchart on two different simulators and on both are displaying expected results

Martin
Attachments
Timing systemv3 16F887.zip
(3.64 KiB) Downloaded 721 times
Martin

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: Help needed!

Post by medelec35 »

jjw wrote:Dear Martin,
You were right the switch was floating added 4.7 k resistor into ground for pin B6 and added also 390R resistor after the switch into +5V.

Still having problems quite seldom get message “timing started” it’s stacked into mode “waiting for trigger” and then I get also message “Timeout”. RealPic simulator and Flowcodes simulator works fine no problem. Is there anything to do to get this flowchart working with my Mcu. Is there a need some delays etc.

Wbr,
Jukka
Sounds to me like contact bounce.

When I designed the flowchart, I assumed it was going to be electronic triggering, hence no bounce.
I have added 50ms of de-bouncing, so it should work with a switch without affecting the result as 50ms is not added to the overall time taken.
Since with this flowchart I'm using timer 2 instead of timer 6 you should be able to use flowchart for simulation, or change target for 16F1938 and use on your hardware.

Can you let me know if it's any better please.

I could be wrong and you have a hardware issue.
If flowchart does not sort things out then I will test on hardware.

Also just to play safe can you post a full circuit diagram.

Martin
Attachments
Timing system v4 16F887.fcf
(22 KiB) Downloaded 948 times
Martin

jjw
Posts: 78
Joined: Sat Aug 25, 2012 5:35 am
Has thanked: 71 times
Been thanked: 9 times
Contact:

Re: Help needed!

Post by jjw »

Sounds to me like contact bounce.
Can you let me know if it's any better please.
I could be wrong and you have a hardware issue.
If flowchart does not sort things out then I will test on hardware.
Good news I was testing today my hardware with function generator both version 3 and 4. Both versions did work as designed the reason why couldn’t get hardware working was contact bounce. I will build my own pulse generator with LT1013 and some other components for further testing the program.

Great thanks to Martin for his help and patience.

Wbr,
jjw

jjw
Posts: 78
Joined: Sat Aug 25, 2012 5:35 am
Has thanked: 71 times
Been thanked: 9 times
Contact:

Re: Help needed!

Post by jjw »

Hi folks, I would be grateful if someone could suggest the way how to detect my sensors curve in my flowchart. These curves are recorded in a field from my sensor with two photo diodes.
Every time the plane (some 60 cm long) passes the sensor with two detectors the flowchart should only recognize the shape of the pulse coming from sensor nothing else. Circumstantial factors for this time keeping system are quite challenging since in the field can be bright sunshine cloudy and everything between that….

Wbr,
jjw
Sensor curve.jpg
(62.07 KiB) Downloaded 13162 times
Attachments
Timing systemv3.fcf
(21.74 KiB) Downloaded 895 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: Help needed!

Post by medelec35 »

Hi Jukka,

Probably the easiest way would be to change port interrupt from positive edge triggering to negative edge triggering
You will probably have to add a potential divider to the output so voltage of pulse drops below triggering threshold voltage.

Can you give the untested flowchart a try and see if it works.

Someone else will probably have a better idea, but the above is the way I would probably tackle it.

Martin
Attachments
Timing systemv4.1.fcf
(21.74 KiB) Downloaded 898 times
Martin

jjw
Posts: 78
Joined: Sat Aug 25, 2012 5:35 am
Has thanked: 71 times
Been thanked: 9 times
Contact:

Re: Help needed!

Post by jjw »

Thanks Martin I will test the flowchart early next week when getting into my lab.

I tested the flowchart in a Real Pic Simulator and it works just fine.

Wbr,
jjw

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: Help needed!

Post by medelec35 »

np.

Let's work out what you will need to do hardware wise.
Looking at specifications on page 365 of the datasheet input low for TTL input (RB7) is maximum of 0.8V.
For good reliability We must make sure that input drops lower than this say 0.4V
Also look at the datasheet, we also need to make sure that in normal sate i/p voltage stay above 2.0V
So at least 2.2V (the higher up to 5V the better).
According to your scope the highest voltage is say 6.7V and the normal voltage is just over 4.5V.
unfortunately doing the maths any potential divider will take the voltage out of either high or low range.
So the band of 2.0V and normal 4.5V will require widening or triggering may not get detected
If not, the only other way maybe to tightly poll ADC.
I'm sure that could work :?:

Martin
Martin

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: Help needed!

Post by medelec35 »

Hi Hi Jukka,,
I have pm'd you a flowchart since you want it kept private.
It uses ADC and also counts laps with the speed of last lap kept on the display.
Switch is used to start and stop/reset values.

Martin
Martin

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: Help needed!

Post by medelec35 »

Hi Jukka,
Not finished the SD card side of things because no experience with that as of yet.
Just had a thought.
There is an alternative to sending data to SD card.
A Vdrive2 (in operation better than Vdrive3) can be used to send data to a standard USB Flash drive.
You will only need minimum of 4 connections.
I know how to get flowcode to create a file on flash drive then update file with data (ASCII).
Then flash drive can be plugged into PC to retrieve data.
I developed a data logger with inbuilt RTC that detects when a boiler changes from demand to no demand and vica versa, then instantly updates a text file with time, date & if boiler demand goes on or off.
Since only changes are detected then file is not swamped with unnecessary data.

Martin
Martin

jjw
Posts: 78
Joined: Sat Aug 25, 2012 5:35 am
Has thanked: 71 times
Been thanked: 9 times
Contact:

Re: Help needed!

Post by jjw »

Great thanks to Martin I’m very grateful of your help. This is very good start and I will concentrate later on into a SD card when everything else is working.

One thing which I couldn't figure it out yet how to limit time taking into a 10 laps?

Wbr,
jjw

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: Help needed!

Post by medelec35 »

Hi Jukka,
No problem
All you need to do is:
10 laps.png
(10.32 KiB) Downloaded 23750 times
To save some memory you can change Lap variable type from Int to Byte as I did not know how may laps there was going to be.

I did notice compiling with Fat causes a compile error.

Martin
Martin

jjw
Posts: 78
Joined: Sat Aug 25, 2012 5:35 am
Has thanked: 71 times
Been thanked: 9 times
Contact:

Re: Help needed!

Post by jjw »

Thanks it works well I also changed MCU into 18f252 for later purpose…
I did notice compiling with Fat causes a compile error.

Vdrive2 (in operation better than Vdrive3) can be used to send data to a standard USB Flash drive.
You will only need minimum of 4 connections.
This seems to be promising will order one.

Wbr,
jjw

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: Help needed!

Post by medelec35 »

I have been using them for nearly a year now.
They have their little idiosyncrasies.
E.g you need to state minimum amount of chars to be sent to flash drive.
If you don't then a close file command (necessary otherwise file will not be produced) before all chars sent will have no effect.

The Vdrive 2 is driven by Vinculum VNC1L which is mentioned elsewhere on the forums.
I personally don't use the component Jordy posted (although it looks very good indeed) since I don't use flow control which saves a couple of pins as I use Vdrive2 on a 12F1840.
I don't believe the user component allows to select flow control on/off?

Places you can order them from are:
RS components
Farnell
Mouser Electronics
Digikey
Most places have them in stock for immediate delivery.

Since Vdrive2 comes complete with cable you will also either cut one of the connectors off or just purchase an 8way SR 2mm male pin PCB header:
2mm 6W SR male header.png
(43.19 KiB) Downloaded 23713 times
We should also add switch debounce which simulators does not simulate:
debounce.png
(11.06 KiB) Downloaded 23713 times
Martin

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: Help needed!

Post by medelec35 »

Hi Jukka,
From PM:
jjw wrote:Correct if I’m wrong but I remember that in early days the chart was recognising the pulse of the rising edge. Now it seems that the chart should recognised of the falling edge. In case I’m right any change that you could advise me how to do it.
Jukka
Since you wanted to start timing when voltage falls bellow a certain voltage then we call it a falling edge anyway.
So your hardware will work on falling edge.
I can't tell by the scope waveform what value for

Code: Select all

(adc < 204) || (allow_tmr = 0) 
is required since there is no scale of divisions for voltage.
E.g 500mV per division.
You can work out correct value.
When you know what the trigger voltage is going to be e.g. you want trigger to be 2V or less then
adc value = 255/5 * trigger voltage
= 51 * 2
= 102
Therefore correct code will be:

Code: Select all

](adc < 102) || (allow_tmr = 0) 
Also from PM:
jjw wrote: How is Vdrive2 article proceeding any change that I could get example code how to read text file into USB stick? It would help me for example is the average speed calculated right etc…
Wbr,
Jukka
I have started the blog yesterday, and when I get time to spare I keep adding to it.
In reality will take a few days to complete.

Martin
Martin

jjw
Posts: 78
Joined: Sat Aug 25, 2012 5:35 am
Has thanked: 71 times
Been thanked: 9 times
Contact:

Re: Help needed!

Post by jjw »

Hi Martin,
So your hardware will work on falling edge.
I can't tell by the scope waveform what value for.
The sensor works just fine the shown and used voltage is 4V. Stronger pulse than previous sensor design. ....
In case very low speed let say less than 100 km/h how to change it into a flowchart?

jjw

Post Reply