Page 1 of 2

Flowcode 5-Shadow Detect Program

Posted: Thu Mar 14, 2013 11:54 am
by JDR04
Hi Folks, I've attached a circuit I built not too long ago. The purpose of this circuit is simply to light a LED when a shadow falls onthe sensor which is a light dependent resister. The problem is I cannot easily control how long the LED stays on.

I'm wondering if somebody out there could show me how to develope a flowcode program to achieve this. I'm using a PIC 16F690 with a PICkit2 and a low pin count developement board all from Microchip.

I'm aware I will have to convert the circuit to run on 5V instead of the 9V as it currently stands

I would appreciate it if we could take this slowly as I am a complete newbie to all this.

Thanks again guys-John

Re: Flowcode 5-Shadow Detect Program

Posted: Thu Mar 14, 2013 7:42 pm
by medelec35
Hi I can help you with that.
when dark enough, Once triggered, we can do it so a timer starts timing then after a time out period LED goes off, but is triggered again since its still dark.
Or it can be done so timer only starts when light enough and LED should be off.
Which way would you like this done?
Also what time period have you got in mind?
there is no time limitations e.from 1 second to days.
Your choice.
So if you can post some specifications.

Have you tried the free online course Enamul posted about?
Well worth have a go.

If you do, the timing function will be using timer0 interrupt, so it would be worth while researching information on it, to give you an understanding of whats going on.

Martin

Re: Flowcode 5-Shadow Detect Program

Posted: Thu Mar 14, 2013 11:19 pm
by JDR04
Hello again Martin and thanks for helping out again.

I've looked at the course and will go into it more deeply soon. I am expecting a period of being confined to the bed due to bad back problems. I've also saved the other programs from the previous posts so I'll have time to study them then.

Getting back to this circuit, I'm keen to understand how to read the voltage from the detector and how to set the reference voltage. It would handy if I could adjust the output anything from 1 second to one hour.

Its fine if the circuit triggers again if it is still dark after time out. It's important that the sensitivity of detecting the darkness can be adjusted as is done by the potentiometer in the circuit.

Once again many thanks - John

Re: Flowcode 5-Shadow Detect Program

Posted: Fri Mar 15, 2013 12:48 am
by medelec35
Your welcome,
Unfortunately I have ran out of time tonight.
I will post a Flowchart for you tomorrow evening.

Re: Flowcode 5-Shadow Detect Program

Posted: Fri Mar 15, 2013 10:27 am
by JDR04
Thanks very much. Could I ask you how the following works.

If I have an analogue signal that rises and falls between say 0 and 9V and I want a schmidt trigger action at say 6 V, how does one go about that?

Thanks again - John

Re: Flowcode 5-Shadow Detect Program

Posted: Fri Mar 15, 2013 11:08 am
by medelec35
Hi John,
This may help?
viewtopic.php?f=29&t=8736&p=26471&#p26475

Martin

Re: Flowcode 5-Shadow Detect Program

Posted: Fri Mar 15, 2013 12:04 pm
by JDR04
Thanks, I think the best thing for me is to print it out and go throught it.

Thanks again - John

Re: Flowcode 5-Shadow Detect Program

Posted: Fri Mar 15, 2013 12:38 pm
by Enamul
Yes, it's always nice for a beginner to follow ready code which will orient you with tips & trick as well as basic programming techniques.

Re: Flowcode 5-Shadow Detect Program

Posted: Fri Mar 15, 2013 2:33 pm
by JDR04
OK, all sorted, rebooted the laptop and the LED's are there??? Dont know what to say???

Re: Flowcode 5-Shadow Detect Program

Posted: Fri Mar 15, 2013 2:56 pm
by Enamul
rebooted the laptop and the LED's are there??? Dont know what to say???
Don't really understand what you mean?

Re: Flowcode 5-Shadow Detect Program

Posted: Fri Mar 15, 2013 7:57 pm
by medelec35
Hi, I have based a flowchart on the diagram you have posted.
LDR connects to An2
Pot controlling sensitivity connects to An1 and delay is An2.
Since delay is from 1 to 3581 seconds
Pot delay adjustment will be very course in deed.
LED output on C0 is active low.
So when it gets dark, C0 goes from high to low, lighting LED. So in effect its sourcing rather than sinking.

This is only basic version, It may be a good idea to add a delay before LED is triggered (light fluctuations)
Also adding a bit of hysteresis my be wise.


Martin

Re: Flowcode 5-Shadow Detect Program

Posted: Sat Mar 16, 2013 5:58 pm
by JDR04
Thanks very much, I will have a look at it on Sunday and see just how far I can understand it all.

Really do appreciate the time you have spent trying to help me.

Thanks again - John

Re: Flowcode 5-Shadow Detect Program

Posted: Sat Mar 16, 2013 6:31 pm
by JDR04
Sorry Enamul, was having problems with the leds vanashing but after I rebooted the laptop all was fine.

Cheers John

Re: Flowcode 5-Shadow Detect Program

Posted: Sat Mar 16, 2013 11:36 pm
by medelec35
JDR04 wrote:Thanks very much, I will have a look at it on Sunday and see just how far I can understand it all.

Really do appreciate the time you have spent trying to help me.

Thanks again - John


Your welcome.

let me know if you want it changed and I will see what I can sort out for you.

Martin

Re: Flowcode 5-Shadow Detect Program

Posted: Tue Mar 19, 2013 12:23 am
by JDR04
Hi Martin, after programming I would like to test it out in a circuit.

I've attached a circuit for the PIC which I think will be correct. Could you be kind enough by checking it over for me please and providing any corrections.

Also, would a 100K resistor be OK for the hysterersis and where exactly would I position it?

Once again thanks for your help. John

Re: Flowcode 5-Shadow Detect Program

Posted: Tue Mar 19, 2013 12:39 am
by kersing
John,

I think you should add at least one 100nF capacitor between 0V and 5V near the connections of the PIC and preferably a 10uF capacitor between 0V and 5V as well to stabilize the power.

Looking at the VR2 connections I am wondering what you are trying to achieve.

Best regards,

Jac

Re: Flowcode 5-Shadow Detect Program

Posted: Tue Mar 19, 2013 9:43 am
by medelec35
I totally agree with Jac comments + your chip supplys are the wrong way round. 20 = 0V = VSS
1 = +5V = VDD.

VR2 is not wired correct.

Each end of pot goes between +5V supply and 0V.

Middle wiper goes to pin 18 (An1) if used for controlling Brightness threshold.
There is a pot missing for delay.
You can remove pot in series with LDR replace wit ha fixed resistor, and use that pot for delay.

Martin

Re: Flowcode 5-Shadow Detect Program

Posted: Tue Mar 19, 2013 2:16 pm
by JDR04
Thanks for that guys. Appreciate your time.

I've made the changes to my schematic and would appreciate you guys giving it the "eagle eye". All suggestions/criticisms are appreciated.

Would I install the resistor for hysterisis between pins 16 and 18? Say 100K???

Thanks again -John

Re: Flowcode 5-Shadow Detect Program

Posted: Wed Mar 20, 2013 2:31 pm
by medelec35
Hi John,
JDR04 wrote:Would I install the resistor for hysterisis between pins 16 and 18? Say 100K???

hysteresis can be done within the software.

Re your circuit the negative supply is now showing on your circuit.
Also the delay pot is connected to the same connection as the LDR connection which is inadvisable.
What you can do is Select View, Chip.
Right click on the pot on your control panel and select connections.
Cross reference with the chip diagram to determine correct pin connections for designing your hardware.

Martin

Re: Flowcode 5-Shadow Detect Program

Posted: Wed Mar 20, 2013 5:00 pm
by JDR04
Thanks again Martin, I've made some changes and I think its right. Could you you check it out please.

Do you think the 100K pots will make adjustments more refined? Also, how would you do the hysteresis in the software?

Thanks a lot for your time. - John

Re: Flowcode 5-Shadow Detect Program

Posted: Wed Mar 20, 2013 6:14 pm
by medelec35
your welcome John.
JDR04 wrote:Do you think the 100K pots will make adjustments more refined?

No 100K pots will be no more refined than 10K for instance.
Pots connected this way are just a potential divider, so 1/2 way will measure 1/2 its total resistance across wiper and outer connected so 1/2 Vcc will be at adc i/p
1/2 vcc with 100K pot = 1/2 vcc with 10K pot etc. the only difference being the higher the pot value the more it will be affected by external electrical noise and more it will be affected by input resistances. etc. If too low in value then too much power could be drawn, lowering the voltage across adc i/p and heating pot up.
JDR04 wrote:Also, how would you do the hysteresis in the software?


Attached is one way of adding hysteresis.

Martin

Re: Flowcode 5-Shadow Detect Program

Posted: Wed Mar 20, 2013 7:41 pm
by JDR04
OK thanks, I think I'm way ahead of myself now. Is the rest of the circuit schematic OK.

I think I need to start programming into the PIC and build the circuit so I can start to digest all the info you have kindly given me. So If you could check the schematic out for me please I;ll get started with all this and give you a bit of peace.

Thanks again -John

Re: Flowcode 5-Shadow Detect Program

Posted: Wed Mar 20, 2013 8:07 pm
by medelec35
Your circuit looks ok.
My comments would be:
since your not using a reset switch on MLCR line, then you don't need MCLR connected. But the MCLR has to be changed from external to internal within configuration settings.

How are you going to program your device?

What I do if making up small circuits like that is set the hardware up to program via ICSP.

To do that you need a connector with data,clock,VPP,GND and +5V going to it.

Here is the way I normally set up ICSP connections:
icsp1.png
From PICkit2 Users Guide.
icsp1.png (35.36 KiB) Viewed 5569 times

Due to newer devices requiring a lower VPP value, out of habit, I use a 10K resistor in series with programmer and VPP of target device, and no other connection to VPP.
It can't be done that way if using a pull up resistor on VPP.

Re: Flowcode 5-Shadow Detect Program

Posted: Wed Mar 20, 2013 8:33 pm
by JDR04
Hi Martin, oh dear this all seems to be getting way way ahead of me. I was hoping to do the programming via my PICkit2 programmer and low pin count board then remove the PIC and insert it into the circuit and start to figure the program out.

So I take it if I dont configure the MCLR correctly nothing will work? How would I do that?

Thanks again - John

Re: Flowcode 5-Shadow Detect Program

Posted: Wed Mar 20, 2013 9:34 pm
by medelec35
JDR04 wrote:I was hoping to do the programming via my PICkit2 programmer and low pin count board then remove the PIC and insert it into the circuit and start to figure the program out.


It's fine you can program the chip like that and then move it.

I only suggested ICSP so you can program and reprogram without moving your target device but that can be done at a later stage when your confidence grows and ready for the next stage.

JDR04 wrote:So I take it if I dont configure the MCLR correctly nothing will work? How would I do that?

Don't worry abut the MCLR line for now. If you keep pin 4 tied to +5 volts, your hardware will work as expected.

You should not need to change configuration settings.