1 to 30 minute timeout based on pot.

For Flowcode users to discuss projects, flowcharts, and any other issues related to Flowcode 4.
To post in this forum you must have a registered copy of Flowcode 4 or higher. To sign up for this forum topic please use the "Online Resources" link in the Flowcode Help Menu.

Moderator: Benj

Post Reply
daveb0360
Posts: 139
Joined: Mon Sep 21, 2009 10:17 am
Location: Leicester
Has thanked: 35 times
Been thanked: 12 times

1 to 30 minute timeout based on pot.

Post by daveb0360 »

Hi, Can anyone help with some code to create a timer that, once triggered with an external low going signal, starts a timer that will issue a signal after a 1 - 30 mins approx delay, with this timeout being set by a simple pot of value 100K. The timer needs to be able to be cancelled by a button/signal and await the next trigger any time after being triggered.

I am sure this is simple to many but I am lost and need help.....particularly with the A/D functionality and simulating the variable A/D value in FC.

Thanks in advance.
Dave

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

Re: 1 to 30 minute timeout based on pot.

Post by medelec35 »

Hi Dave

What hardware set up are you using?
E.g Target device, oscillator type e.g internal external and oscillator speed.
Once you have supplied that information, a flowchart can be produced for you.

If you want to try your self, we normally use a timer interrupt. E.g Timer0.
Within the timer0 interrupt macro, do something like count = count +1.
suppose interrupt frequency is 75Hz. this means the timer0 macro will be accessed 75 times in one second.
So if count =75 then count = 0: Seconds = seconds +1 etc.

Good thing about using an interrupt, is it keeps counting, no matter what part of your flowchart is being accessed.
I have explained about timer0 interrupt here:
http://www.matrixmultimedia.com/mmforum ... =26&t=8660

Re A/D functionality. when the i/p to the ADC pin rises from 0V to 5V then the variable reading if using readAsByte will vary from 0 to 255. So 1/2 of 5V is at the pin input then the values assigned to the variable = 127 etc. What you want to do is use a calculation box to convert the 0 to 255 to 1 to 30
E.g Time_Delay = Read_ADC*11/94+1

Few things with pic maths.
1) numbers are always rounded down. e.g 11/6 = 1 Not = 2
2) If multiplying then do not exceed 32767 or results will be wrong.
3) since bytes and integers are whole numbers then (10/20)*1000 = 0 not = 500.
This is because 10/20 = 0 not 0.5

There are plenty of hints and tips about the forums.
You can also look here for examples:
http://www.matrixmultimedia.com/flowcode.php

Above all if stuck, carry on asking!

Martin.
Martin

daveb0360
Posts: 139
Joined: Mon Sep 21, 2009 10:17 am
Location: Leicester
Has thanked: 35 times
Been thanked: 12 times

Re: 1 to 30 minute timeout based on pot.

Post by daveb0360 »

Hi Martin,
Thanks for the reply, however, I have trouble at my age (51) understanding the intricacies of interrupts etc regardless of how they are written and the maths formulas such as "E.g Time_Delay = Read_ADC*11/94+1"............ OK.......I get the 11/94 gives a fraction that multiplied by 255 gives almost 30 but what is the +1 doing........it means nothing. and then what do I do with this once I've got it........put it all inside a count loop perhaps......I'm lost.

I propose to use a 16F88 or similar (as long as it has ADC and is within FC V4 pro device list)

I propose to put a 100k pot between VDD and ground and tap from the wiper to give the variable voltage on which to reference the timing function.
The trigger comes from a sub circuit that I have already designed.....a window comparator that will detect a voltage as being above or below a threshold but gives a negative going pulse regardless. This detects a signal that is either from a volt free relay contact or a 12 V signal with reference to 0V.

The timer must begin on receipt of this low going signal but reset if it goes back high during the countdown. Timer must also be cancellable by means of a seperate low going signal, wherupon it will go back to waiting for the signal. Ideally, the timer should give a selectable 1 - 30 minute timeout as described OR a 5 - 10 milisecond pulse dependent on an option jumper on one of the ports. This is because the circuit needs to trigger 2 different types of UPS, one needs a pulse to start and an identical pulse to shut down. The other needs a DC signal to be present for the duration over which it is required to be powered up.

Hope this makes it clear. Hardware design is my forte and have rarely needed to code anything so have never had the need to learn so this is a steep learning curve for me and have my customer on the phone almost hourly, chasing me for a solution. We were going the analogue route but getting long timing periods that are predictable with analogue circuits such as a 7555 is difficult.....probably more difficult than a coded solution.

Cheers
Dave

daveb0360
Posts: 139
Joined: Mon Sep 21, 2009 10:17 am
Location: Leicester
Has thanked: 35 times
Been thanked: 12 times

Re: 1 to 30 minute timeout based on pot.

Post by daveb0360 »

Hi Martin, forgot to mention that I will probably use internal clock at 4Mhz

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

Re: 1 to 30 minute timeout based on pot.

Post by medelec35 »

daveb0360 wrote:Hi Martin,
but what is the +1 doing........
Dave
All before the +1 is calculating the correct value determined by the pot setting. The +1 is the minimum time. Since if pot is on its minimum resistance, leaving out the +1 in question, you will have Read_ADC*11/94
Since Read_ADC = value of variable which will be 0
Then Delay time in minutes = 0*11/94 = 0/94 = 0
So now you add the +1 = 0+ 1 = 1

So if lowest time is 5 minuites and highest time is 30 minutes, you can use the same formula but instead of +1 you would use +5
Assuming pot is still on its minimum setting
You will have
Read_ADC*11/94+5
=0*11/94+5
=0 +5
=5

Hope this helps.

Martin
Martin

daveb0360
Posts: 139
Joined: Mon Sep 21, 2009 10:17 am
Location: Leicester
Has thanked: 35 times
Been thanked: 12 times

Re: 1 to 30 minute timeout based on pot.

Post by daveb0360 »

Hi Martin,
Sorry to wate your time with that one.....things don't spring to mind like they used to and I played with the maths in a simulation and worked it out...it's so obvious.......now I'm embarrassed...

In actual fact, I placed this code in a calculation box (ADC_Value = ADC_Value*0.0292553+1) which returns 1 - 30 as POT as altered from min to max....exactly as required.
Just need to figure out what to do now......LOL.......I'll get a coffee and step through it in my mind.......I know it's not difficult but..blh blah blah.....I'll go boil the kettle...

Dave

daveb0360
Posts: 139
Joined: Mon Sep 21, 2009 10:17 am
Location: Leicester
Has thanked: 35 times
Been thanked: 12 times

Re: 1 to 30 minute timeout based on pot.

Post by daveb0360 »

Hi Martin,
Have just had a thought, I could use another ADC on chip to perform the window detector function as well I reckon.....just need to scale the incoming 12V signal down to the 5V PIC rail voltage using resistor divider and a zener to prevent overvoltage at the AD input of the pic.

In other words...use ADC to ignore a mid point voltage (byte) between, say, 80 and 200 but provide a logic '0' on anything higher or lower than this range.........formidable solution and knocks component cost down.........hopefully?!?!

I could offer a small financial arrangement if you could work with me on this since it is commercial for me..........it would be worth it to me.... What do you think?

Dave

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

Re: 1 to 30 minute timeout based on pot.

Post by medelec35 »

Hi Dave,
Don’t worry about being embarrassed!. There are loads of people (myself included) that have thought at the time: “Now why didn’t I think of that!
To be honest I could design the type of system you’re after.
However, because of work commitments etc and coupled with the fact that other people could do a better job than myself.
There are huge resources available on these forums to enable any type of flowchart to be created.
As with reading a voltage higher than 5V, you can use a voltage divider, and so long as the resistance or resistor connected to the +12V is high to limit current going into the pin, then it does not matter if the pin voltage does go above 5V, since there are clamping diodes connected to the i/p pin (except MCLR) , keeping voltage clamped to just above 5V
For instance I have used a 1M resistor connected between live mains and i/p pin , for zero crossing mains detection. No issues at all.
For long timing periods a microcontroller is far superior to 7555. Since you can time form a few microseconds to several days/ weeks etc.
You can also source and sink 25 mA per pin, up to a maximum total current of about 250mA
Also you get devices with comparator’s built in!
If you need a flowchart quicker than I could develop a 100% working one and you don’t mind paying for the service, then you could try the Freelance Embedded Engineers see:
http://www.matrixmultimedia.com/mmforum ... m.php?f=32

If you are still struggling and no enginer has got back to you with offers of help, I will come up with a flowchart that may suit your needs.
I never charge, as it may not be the best way.
Regards
Martin
Martin

User avatar
001tech
Posts: 5
Joined: Wed May 18, 2011 6:29 pm
Been thanked: 1 time
Contact:

Re: 1 to 30 minute timeout based on pot.

Post by 001tech »

Hello Dave,

Yes this is something I could do for you. If you would like to contact me with your specification of what you need and what you are willing to pay then I will do the work for you over this coming weekend.

daveb0360
Posts: 139
Joined: Mon Sep 21, 2009 10:17 am
Location: Leicester
Has thanked: 35 times
Been thanked: 12 times

Re: 1 to 30 minute timeout based on pot.

Post by daveb0360 »

Hiya,
I am seriously mulling this one over and appreciate the offer. I actually think I may be able to sort this one now I've overcome the mystery on using the ADC.
Now, if I could just work out how to display the 0 - 30 variable on a dual 7 segment display, I may win this battle without further help...........the logic/state machine functions I need are relatively straightforward once this is overcome.

I'll post another question on the forum about using dual 7 segment display instead of the single or quad supplied.

Thanks again and I may take you up on your offer yet.....
Dave

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

Re: 1 to 30 minute timeout based on pot.

Post by medelec35 »

daveb0360 wrote: if I could just work out how to display the 0 - 30 variable on a dual 7 segment display, I may win this battle without further help...........the logic/state machine functions I need are relatively straightforward once this is overcome.

I'll post another question on the forum about using dual 7 segment display instead of the single or quad supplied.
Heres A good place to look:
http://www.matrixmultimedia.com/mmforum ... 248#p23062
Martin
Martin

Post Reply