code for dual voltage 'window' on ADC input

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

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: code for dual voltage 'window' on ADC input

Post by medelec35 »

Can you please give more detail of LED on and off durations in ms for all the conditions, including if board is under or over voltage for window + when adc is reading voltage is 30V.
Thanks.
Martin

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

Re: code for dual voltage 'window' on ADC input

Post by daveb0360 »

Hi Martin,
Completely understood on the risk and responsibility front..........it's all mine....no comebacks guaranteed.

Just can't thank you enough.
Any time you need hardware design or PCB design........I'm your man............t'would be good to return the favour some day.

Dave

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

Re: code for dual voltage 'window' on ADC input

Post by daveb0360 »

Hi Martin, the timings are not critical.
All I need is easily differentiated pulsing for the various conditions.
The only definite is the standby phase, when supply voltage is below operational window, i.e. outside the the upper or lower acceptable ranges. To explain......The circuit must assume the vehicle (could be 12v or 24v vehicle) is stationary without engine running and go into standby state using minimum current (not draining the battery!) but still indicating it's alive and ready. So.......a slowly flashing led. just like an auto alarm would do.

The other must have is a rapid flash when over temperature by, say, 10 degrees...........something very noticeable like 5hz or so. This is to alert the user that the water may be too hot - scald risk! or that the tank is empty and the heater is overheating (There is a thermal fuse that shuts the whole circuit down, permanently! in a thermal runaway emergency. Apart from the rapid flashing warning, which should continue, this can be ignored programatically as in this event.....it's back to the factory for a new fuse.)

I reckon a solid ON when below temperature and heater energised and an even say, 1hz flash when at temperature. - or vise-verso.

I would have temperature upper limit of 45c at which point, heater switches off and doesn't come back on again until temperature has dropped by 5c. This to give some hysteresis to the thermal control loop. A small over/undershoot won't be significant.

I thought about the supply voltage out of range indication and decided this is not actually necessary..........it is only necessary to stop the heater function when out of range. The in range, solid or 1hz flash will indicate normal range and normal operation.

Hope this helps highlight what's needed.

Boards are being built now so here's hoping they work.....

Cheers

Dave

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

Re: code for dual voltage 'window' on ADC input

Post by daveb0360 »

Hi Martin,
I see your recommendation for using 12F617 and I'm all for it, not least because it's cheaper but particularly for it's greater flash capacity. Problem is, PICKIT 2 doesn't support this chip.....unless you know better.
There is some talk on forums, about creating a pickit2 header file for use with 617 but how the hell does one do this?

I'd be very reluctant to buy another programmer when the one i've got works fine....sure you see my point. but hey, if that's what it takes then........


Dave

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

Re: code for dual voltage 'window' on ADC input

Post by daveb0360 »

ermmmm...ignore my last post !

I've been stupid and didn't read the forums properly.......I have now downloaded the latest definition files for Pickit 2 and hey presto....12F617 is now in the supported devices list......voila!!

I have also just ordered a bunch of 617's from Farnell.

My only concern is the ADC loading, the 675 seems to have better tolerance for higher impedance sources than the 617.............but maybe I'm either reading it wrong or it doesn't matter a great deal.
Apparently, it's more important to allow a sufficient acquisition time.......which we can do because we're running a very slow app.......right?

Dave

User avatar
Enamul
Posts: 1772
Joined: Mon Mar 05, 2012 11:34 pm
Location: Nottingham, UK
Has thanked: 271 times
Been thanked: 814 times
Contact:

Re: code for dual voltage 'window' on ADC input

Post by Enamul »

Hi,
I see your recommendation for using 12F617 and I'm all for it, not least because it's cheaper but particularly for it's greater flash capacity. Problem is, PICKIT 2 doesn't support this chip.....unless you know better.
It does support PIC12f617....as according to the link..
http://www.microchip.com/stellent/idcpl ... e=en027813
There is some talk on forums, about creating a pickit2 header file for use with 617 but how the hell does one do this?
PIC12F615*, HV615*
- Use AC162083 ICD header & AC164110 adapter.
Even if you need the special ICD header its pretty easy to make one..if you think you want to make a try please let us know..we can help you.
Enamul
Enamul
University of Nottingham
enamul4mm@gmail.com

User avatar
Enamul
Posts: 1772
Joined: Mon Mar 05, 2012 11:34 pm
Location: Nottingham, UK
Has thanked: 271 times
Been thanked: 814 times
Contact:

Re: code for dual voltage 'window' on ADC input

Post by Enamul »

Hi,
My only concern is the ADC loading, the 675 seems to have better tolerance for higher impedance sources than the 617.............but maybe I'm either reading it wrong or it doesn't matter a great deal.
Apparently, it's more important to allow a sufficient acquisition time.......which we can do because we're running a very slow app.......right?
As Martin said, you can use 617 in 8MHz speed just using internal clock whereas 675 maximum 4 MHz using internal clock..so you have 2x speed gain in any peripherals which is true for ADC as well. So I don't feel any problem in using 617 than 675...the only issue is EEPROM which you can get in 675 but not in 617 whereas in 617 with higher memory and double speed you will get CCP module..
Enamul
Enamul
University of Nottingham
enamul4mm@gmail.com

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

Re: code for dual voltage 'window' on ADC input

Post by daveb0360 »

Hi again............it's getting late and I'm talking dumb again re: impedances..........both devices have virtually the same spec.


Duhh.......g'night all

Dave

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: code for dual voltage 'window' on ADC input

Post by medelec35 »

Hi David,
Here is my 1st attempt utilising your given specifications.
Target device = 12F617.
If It works then final step is enabling watchdog timer.
But its not just a case of enabling, so we can go through that when your ready.
Martin
Attachments
Dual voltage window 4.fcf
(21.17 KiB) Downloaded 329 times
Martin

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

Re: code for dual voltage 'window' on ADC input

Post by daveb0360 »

Hi Martin,

Thanks again for the code !! :-)
I am having trouble simulating it though.
The LED currently marked 'over voltage' is not leaving the slow, 'standby' led mode of long off - short on except when over voltage or low voltage.
Maybe I wasn't clear in my synopsis. In any case, it would be great if I understood the flowchart so I could utilise this code as a baseline to do my own tweaks........unfortunately, much of it loses me..!?
I'll try and clarify what's needed graphically...not sure how yet....going to think about it.

Dave

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: code for dual voltage 'window' on ADC input

Post by medelec35 »

Hi Dave
daveb0360 wrote:I am having trouble simulating it though.
You only have two options as code can't simulated in Flowcode.
This is because I have used LUT for thermistor to determine water temperature and LUT uses C code and as you may or may not be aware of C can't be simulated. The simulator will just think the water temperature is permanently at 0 deg C
So the over heat and at correct temperature conditions will never be met

Two options are 1) Use real pic simulator
Take a look here:
http://www.matrixmultimedia.com/mmforum ... 01&#p24998
Full version is good value for money, link for it is a few posts down.

2) Test on real hardware.
daveb0360 wrote: The LED currently marked 'over voltage' is not leaving the slow, 'standby' led mode of long off - short on except when over voltage or low voltage.
I only was using 1 LED for all the different indications, was that not correct, since you marked it as 'over voltage'
Flowchart gets a bit complex since there is one LED for indicating, and 5 different conditions. Some conditions call for two different patterns at the dame time, e.g normal voltage, water at correct temperature, or normal voltage and over heat. In these cases there has to be a priority.
It would be much easier (for determine board status and for flowchart simplicity) if you had two LED'S, one for voltage indication and the other for water temperature indication.

Unless you have and I misread your posts?
Martin

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

Re: code for dual voltage 'window' on ADC input

Post by daveb0360 »

Hi Martin,
I've put a graphic together to illustrate.
I have an old board with the previous hardware that I can try the code on until I have chance (time) to build one of the new ones with the 617 chip on board. So I will try this code in the 675 based old board tomorrow.
(I have a job on the bench for a customer that must come first!......it's late so must crack on with it)

I don't think we need to indicate specifically, any over voltage state...this is hardware protected......just a general 'out of range' (standby) state where no heater activity will be allowed.
I will need to know which variables to 'tweak' to make the hardware perform within real world values and tolerances.
Cheers
Dave
Attachments
HeaterSeq.PNG
Graphic of operation and led sequencing for differing states.
(51.83 KiB) Downloaded 3468 times

User avatar
Enamul
Posts: 1772
Joined: Mon Mar 05, 2012 11:34 pm
Location: Nottingham, UK
Has thanked: 271 times
Been thanked: 814 times
Contact:

Re: code for dual voltage 'window' on ADC input

Post by Enamul »

Nice depiction...if Martin delays in FC..I will post one for you...
Enamul
Enamul
University of Nottingham
enamul4mm@gmail.com

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: code for dual voltage 'window' on ADC input

Post by medelec35 »

Yes that is much better Dave!
So much easier to follow :)
Enamul wrote:if Martin delays in FC..I will post one for you...
Enamul
Ok, I will post my updated one after you have posted yours.

Martin
Martin

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

Re: code for dual voltage 'window' on ADC input

Post by daveb0360 »

Hi Martin,
This is being developed to replace an obsolete control board for a customer. He is limited to a single led as all his brochures, metalwork etc. is in stock and not cost effective to modify for a second led.
The voltage measurement only serves to allow or disallow the heater activity.
If voltages are in range, the heater control loop will activate and the differing led patterns of a functioning temperature control loop will indicate normal working.

There are only 4 led patterns.
1. Slow, uneven blink....long off-short on. Standby condition - waiting for supply voltage to be in range - Heating control disabled and heater OFF.
2. Even - ~0.5sec blink. Water under temperature and actively heating - supply voltage determined to be within one of the working ranges
3. Constant on. Water at working temperature (40-45c) - NOT actively heating but supply voltage determined to be within one of the working ranges
4. Rapid Blink. Water temperature exceeded normal +10c This rapid blinking must remain active, even if supply voltage falls out of range but revert to the standby condition if water temp falls back to normal.

This means, effectively, the temperature monitoring circuit must be a continuous process - even in standby OR, once overtemp has been detected, it continues to signal the alarm until temperature falls back to normal and then goes to standby indication as normal.
Reason for this is simply that a user need to know the possible risk of harm even when the vehicle has been switched off.........any overhot water, may remain overhot for some time after the engine is switched off.
Any excursions away from normal supply voltages, must override the heater to a default OFF state in all conditions.

I feel I must apologise now as I haven't been very clear and should have given this more thought before I asked for help !
I would completely understand if you throw in the towel! -:(
Hopefully it is all clear now........it is finally in my own mind!
Dave
Attachments
HeaterSeq.PNG
(51.83 KiB) Downloaded 3465 times

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

Re: code for dual voltage 'window' on ADC input

Post by daveb0360 »

Enamul wrote:Nice depiction...if Martin delays in FC..I will post one for you...
Enamul
With all this help on offer.....I'm never gonna learn....lol :oops:
Actually...not quite true, whilst I'm not ready to embark on this relatively complex task.........I'm studying what you guys are presenting me with and learning piecemeal........so double thanks.

No doubt if I had a few weeks to get this done, I'd probably get it by reading the lits and picking up tips from this forum........unfortunately.......I don't have time, customer is hoping to pick up working proto's on Friday...... :(

Dave

User avatar
Enamul
Posts: 1772
Joined: Mon Mar 05, 2012 11:34 pm
Location: Nottingham, UK
Has thanked: 271 times
Been thanked: 814 times
Contact:

Re: code for dual voltage 'window' on ADC input

Post by Enamul »

Hi,
I have spent couple of hours to check your requirements and design the FC using temperature portion from Martin as his LUT is great for Thermistor temperature measurement. I don't have this chip to test in hardware..but you can test obviously in hardware...please let me know how it's going.
Enamul
Attachments
Water_Heater_Control.fcf
(14.34 KiB) Downloaded 264 times
Enamul
University of Nottingham
enamul4mm@gmail.com

User avatar
Enamul
Posts: 1772
Joined: Mon Mar 05, 2012 11:34 pm
Location: Nottingham, UK
Has thanked: 271 times
Been thanked: 814 times
Contact:

Re: code for dual voltage 'window' on ADC input

Post by Enamul »

Hi,
I have just simulated in Real PIC...there are couple of problems in last posted version...I am correcting those...Almost done..I will post soon..Can you please download FCV5 free version from the link...as seems ADC problem in FCV4 in this chip...You can easily compile the pg in fcv5..
http://www.matrixmultimedia.com/lc_index.php?p=25
Enamul
Enamul
University of Nottingham
enamul4mm@gmail.com

User avatar
Enamul
Posts: 1772
Joined: Mon Mar 05, 2012 11:34 pm
Location: Nottingham, UK
Has thanked: 271 times
Been thanked: 814 times
Contact:

Re: code for dual voltage 'window' on ADC input

Post by Enamul »

Hi,
Here is the V5 version. I have tested this in Real PIC Simulator...works excellent. I have posted hex so that you can try in hardware...
Hope this helps. :)
Attachments
Water_Heater_Control.hex
(3.11 KiB) Downloaded 232 times
Water_Heater_Control.fcf
(23.27 KiB) Downloaded 261 times
Enamul
University of Nottingham
enamul4mm@gmail.com

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

Re: code for dual voltage 'window' on ADC input

Post by daveb0360 »

Hi Enamul,
Problem with this instruction....
Enamul wrote:Hi,
I have just simulated in Real PIC...there are couple of problems in last posted version...I am correcting those...Almost done..I will post soon..Can you please download FCV5 free version from the link...as seems ADC problem in FCV4 in this chip...You can easily compile the pg in fcv5..
http://www.matrixmultimedia.com/lc_index.php?p=25
Enamul
The demo/free version doesn't support the chip we're using and I don't have the budget at the mo for the full upgrade....I'd be more comfortable with the file in v4 format.
I tried the code in Real Pic sim and as you say, seems to work fine.......

I am building the boards in a while, now I've finished my assembly job, and will build with the f617 as Martin suggested.

Can't believe you sat up so late/early doing this for me, Both you and Martin are utter stars.....I applaud you !.. (I too, worked through the night to get the assy job done so I know how tired you must be right now.....I can't do any more than thank you......but it's a big thanks..

Dave

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: code for dual voltage 'window' on ADC input

Post by medelec35 »

Hi Dave,
Here is my modified version.
Voltage and temperature readings are taken all the time and there must not be any voltage deviation for a continuous time of 2 seconds.
Formula for voltage changed to use a direct voltage value e.g. 16=16V etc.
Also using status picture, modified so should be as picture. E.g. Heater is active only when thermistor is lower than 40C and Voltage is within correct parameters.

Martin
Attachments
Dual voltage window5.fcf
(21.47 KiB) Downloaded 266 times
Martin

User avatar
Enamul
Posts: 1772
Joined: Mon Mar 05, 2012 11:34 pm
Location: Nottingham, UK
Has thanked: 271 times
Been thanked: 814 times
Contact:

Re: code for dual voltage 'window' on ADC input

Post by Enamul »

Hi,
Sorry I should remember that FCV5 demo has some limitation....I was sleepy I guess....
I don't have time, customer is hoping to pick up working proto's on Friday......
Actually, this line you posted made me to wake till so late...as you really need support...for this project if you still feel any modification needed you can tell me I will modify that one and send you a hex..Of course we welcome you V5+ version whenever you become sound. :)
Enamul
Enamul
University of Nottingham
enamul4mm@gmail.com

User avatar
Enamul
Posts: 1772
Joined: Mon Mar 05, 2012 11:34 pm
Location: Nottingham, UK
Has thanked: 271 times
Been thanked: 814 times
Contact:

Re: code for dual voltage 'window' on ADC input

Post by Enamul »

Hi,
I have checked this one using Real PIC simulator...it works fine..this is in FCV4..so I guess last time in V4 problem is just because of late working..
You can change if needed..as this is in FCV4
Enamul
Attachments
Water_Heater_Control.fcf
FCV4 version
(14.34 KiB) Downloaded 249 times
Enamul
University of Nottingham
enamul4mm@gmail.com

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

Re: code for dual voltage 'window' on ADC input

Post by daveb0360 »

Hi Enamul,
Thanks again.........pleased to say, hardware is working perfectly.....absolutely no issues with the hardware...yeehaaaa.
The code has a problem though.
When I try to compile to HEX I get the following warnings.

Warning unreferenced functions removed:
FCI_FLOAT_TO_STRING in: C:\Program Files (x86)\Matrix Multimedia\Flowcode V4\FCD\internals.h
FCI_NUMBER_TO_HEX in: C:\Program Files (x86)\Matrix Multimedia\Flowcode V4\FCD\internals.h
FCI_STRING_TO_INT in: C:\Program Files (x86)\Matrix Multimedia\Flowcode V4\FCD\internals.h
FCI_STRING_TO_FLOAT in: C:\Program Files (x86)\Matrix Multimedia\Flowcode V4\FCD\internals.h
Wdt_Delay_S in: C:\Program Files (x86)\Matrix Multimedia\Flowcode V4\FCD\internals.h
Wdt_Delay_Ms in: C:\Program Files (x86)\Matrix Multimedia\Flowcode V4\FCD\internals.h
isinf in: C:\Program Files (x86)\Matrix Multimedia\Flowcode V4\FCD\internals.h
FCD_ADC0_ReadAsByte in: C:\Users\Dave\AppData\Local\Temp\Water_Heater_Control.c
FCD_ADC0_ReadAsVoltage in: C:\Users\Dave\AppData\Local\Temp\Water_Heater_Control.c
FCD_ADC0_ReadAsString in: C:\Users\Dave\AppData\Local\Temp\Water_Heater_Control.c
FCD_ADC1_ReadAsInt in: C:\Users\Dave\AppData\Local\Temp\Water_Heater_Control.c
FCD_ADC1_ReadAsVoltage in: C:\Users\Dave\AppData\Local\Temp\Water_Heater_Control.c
FCD_ADC1_ReadAsString in: C:\Users\Dave\AppData\Local\Temp\Water_Heater_Control.c

Have you any Idea what might be the problem?

Dave

User avatar
Enamul
Posts: 1772
Joined: Mon Mar 05, 2012 11:34 pm
Location: Nottingham, UK
Has thanked: 271 times
Been thanked: 814 times
Contact:

Re: code for dual voltage 'window' on ADC input

Post by Enamul »

Hi,
The code has a problem though.
When I try to compile to HEX I get the following warnings.

Warning unreferenced functions removed:
This is not a problem...this is normally done by FC compiling...for example if you use ADC in your c code all the adc macros are copied but you might have use one macro. Rest are unnecessary for your program and if converted to hex will just unnecessarily occupy lots of space in memory...That's why FC removes this and just make a warning..
you can see here...
FCD_ADC0_ReadAsByte in: C:\Users\Dave\AppData\Local\Temp\Water_Heater_Control.c
FCD_ADC0_ReadAsVoltage in: C:\Users\Dave\AppData\Local\Temp\Water_Heater_Control.c
FCD_ADC0_ReadAsString in: C:\Users\Dave\AppData\Local\Temp\Water_Heater_Control.c
it doesn't say warn for FCD_ADC0_ReadAsInt as we used INT read for ADC0
FCD_ADC1_ReadAsInt in: C:\Users\Dave\AppData\Local\Temp\Water_Heater_Control.c
FCD_ADC1_ReadAsVoltage in: C:\Users\Dave\AppData\Local\Temp\Water_Heater_Control.c
FCD_ADC1_ReadAsString in: C:\Users\Dave\AppData\Local\Temp\Water_Heater_Control.c
But for ADC1 warn for INT read not for Byte read as we used Byte read...
As long as you get success returned at the bottom of msg don't need to worry..
Enamul
Enamul
University of Nottingham
enamul4mm@gmail.com

Post Reply