Flowcode 5-Shadow Detect Program

For questions and comments on programming in general. And for any items that don't fit into the forums below.

Moderators: Benj, Mods

JDR04
Posts: 264
Joined: Tue Mar 05, 2013 10:49 pm
Has thanked: 111 times
Been thanked: 13 times
Contact:

Flowcode 5-Shadow Detect Program

Postby JDR04 » Thu Mar 14, 2013 11:54 am

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
Attachments
LDR1PDF.pdf
(10.95 KiB) Downloaded 96 times

User avatar
medelec35
Valued Contributor
Valued Contributor
Posts: 8440
Joined: Sat May 05, 2007 2:27 pm
Location: Northamptonshire, UK
Has thanked: 2412 times
Been thanked: 3450 times
Contact:

Re: Flowcode 5-Shadow Detect Program

Postby medelec35 » Thu Mar 14, 2013 7:42 pm

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
Martin

If you read a post that is useful, please show appreciation by clicking on thumbs up Icon.

JDR04
Posts: 264
Joined: Tue Mar 05, 2013 10:49 pm
Has thanked: 111 times
Been thanked: 13 times
Contact:

Re: Flowcode 5-Shadow Detect Program

Postby JDR04 » Thu Mar 14, 2013 11:19 pm

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

User avatar
medelec35
Valued Contributor
Valued Contributor
Posts: 8440
Joined: Sat May 05, 2007 2:27 pm
Location: Northamptonshire, UK
Has thanked: 2412 times
Been thanked: 3450 times
Contact:

Re: Flowcode 5-Shadow Detect Program

Postby medelec35 » Fri Mar 15, 2013 12:48 am

Your welcome,
Unfortunately I have ran out of time tonight.
I will post a Flowchart for you tomorrow evening.
Martin

If you read a post that is useful, please show appreciation by clicking on thumbs up Icon.

JDR04
Posts: 264
Joined: Tue Mar 05, 2013 10:49 pm
Has thanked: 111 times
Been thanked: 13 times
Contact:

Re: Flowcode 5-Shadow Detect Program

Postby JDR04 » Fri Mar 15, 2013 10:27 am

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

User avatar
medelec35
Valued Contributor
Valued Contributor
Posts: 8440
Joined: Sat May 05, 2007 2:27 pm
Location: Northamptonshire, UK
Has thanked: 2412 times
Been thanked: 3450 times
Contact:

Re: Flowcode 5-Shadow Detect Program

Postby medelec35 » Fri Mar 15, 2013 11:08 am

Hi John,
This may help?
viewtopic.php?f=29&t=8736&p=26471&#p26475

Martin
These users thanked the author medelec35 for the post:
JDR04 (Fri Mar 15, 2013 12:03 pm)
Rating: 5.26%
 
Martin

If you read a post that is useful, please show appreciation by clicking on thumbs up Icon.

JDR04
Posts: 264
Joined: Tue Mar 05, 2013 10:49 pm
Has thanked: 111 times
Been thanked: 13 times
Contact:

Re: Flowcode 5-Shadow Detect Program

Postby JDR04 » Fri Mar 15, 2013 12:04 pm

Thanks, I think the best thing for me is to print it out and go throught it.

Thanks again - John

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: Flowcode 5-Shadow Detect Program

Postby Enamul » Fri Mar 15, 2013 12:38 pm

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.
Enamul
University of Nottingham
enamul4mm@gmail.com

JDR04
Posts: 264
Joined: Tue Mar 05, 2013 10:49 pm
Has thanked: 111 times
Been thanked: 13 times
Contact:

Re: Flowcode 5-Shadow Detect Program

Postby JDR04 » Fri Mar 15, 2013 2:33 pm

OK, all sorted, rebooted the laptop and the LED's are there??? Dont know what to say???

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: Flowcode 5-Shadow Detect Program

Postby Enamul » Fri Mar 15, 2013 2:56 pm

rebooted the laptop and the LED's are there??? Dont know what to say???
Don't really understand what you mean?
Enamul
University of Nottingham
enamul4mm@gmail.com

User avatar
medelec35
Valued Contributor
Valued Contributor
Posts: 8440
Joined: Sat May 05, 2007 2:27 pm
Location: Northamptonshire, UK
Has thanked: 2412 times
Been thanked: 3450 times
Contact:

Re: Flowcode 5-Shadow Detect Program

Postby medelec35 » Fri Mar 15, 2013 7:57 pm

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
Attachments
Shadow Detect1.fcf
(17.5 KiB) Downloaded 77 times
These users thanked the author medelec35 for the post:
JDR04 (Sat Mar 16, 2013 6:29 pm)
Rating: 5.26%
 
Martin

If you read a post that is useful, please show appreciation by clicking on thumbs up Icon.

JDR04
Posts: 264
Joined: Tue Mar 05, 2013 10:49 pm
Has thanked: 111 times
Been thanked: 13 times
Contact:

Re: Flowcode 5-Shadow Detect Program

Postby JDR04 » Sat Mar 16, 2013 5:58 pm

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

JDR04
Posts: 264
Joined: Tue Mar 05, 2013 10:49 pm
Has thanked: 111 times
Been thanked: 13 times
Contact:

Re: Flowcode 5-Shadow Detect Program

Postby JDR04 » Sat Mar 16, 2013 6:31 pm

Sorry Enamul, was having problems with the leds vanashing but after I rebooted the laptop all was fine.

Cheers John

User avatar
medelec35
Valued Contributor
Valued Contributor
Posts: 8440
Joined: Sat May 05, 2007 2:27 pm
Location: Northamptonshire, UK
Has thanked: 2412 times
Been thanked: 3450 times
Contact:

Re: Flowcode 5-Shadow Detect Program

Postby medelec35 » Sat Mar 16, 2013 11:36 pm

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
Martin

If you read a post that is useful, please show appreciation by clicking on thumbs up Icon.

JDR04
Posts: 264
Joined: Tue Mar 05, 2013 10:49 pm
Has thanked: 111 times
Been thanked: 13 times
Contact:

Re: Flowcode 5-Shadow Detect Program

Postby JDR04 » Tue Mar 19, 2013 12:23 am

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
Attachments
PIC 16F690 Circuit-PDF.pdf
(6.77 KiB) Downloaded 67 times

kersing
Valued Contributor
Valued Contributor
Posts: 1873
Joined: Wed Aug 27, 2008 10:31 pm
Location: Netherlands
Has thanked: 530 times
Been thanked: 1040 times
Contact:

Re: Flowcode 5-Shadow Detect Program

Postby kersing » Tue Mar 19, 2013 12:39 am

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
These users thanked the author kersing for the post:
JDR04 (Tue Mar 19, 2013 2:16 pm)
Rating: 5.26%
 
“Integrity is doing the right thing, even when no one is watching.”

― C.S. Lewis

User avatar
medelec35
Valued Contributor
Valued Contributor
Posts: 8440
Joined: Sat May 05, 2007 2:27 pm
Location: Northamptonshire, UK
Has thanked: 2412 times
Been thanked: 3450 times
Contact:

Re: Flowcode 5-Shadow Detect Program

Postby medelec35 » Tue Mar 19, 2013 9:43 am

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
These users thanked the author medelec35 for the post:
JDR04 (Tue Mar 19, 2013 2:16 pm)
Rating: 5.26%
 
Martin

If you read a post that is useful, please show appreciation by clicking on thumbs up Icon.

JDR04
Posts: 264
Joined: Tue Mar 05, 2013 10:49 pm
Has thanked: 111 times
Been thanked: 13 times
Contact:

Re: Flowcode 5-Shadow Detect Program

Postby JDR04 » Tue Mar 19, 2013 2:16 pm

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
Attachments
PIC 16F690 Circuit=PDF.pdf
(7.84 KiB) Downloaded 67 times

User avatar
medelec35
Valued Contributor
Valued Contributor
Posts: 8440
Joined: Sat May 05, 2007 2:27 pm
Location: Northamptonshire, UK
Has thanked: 2412 times
Been thanked: 3450 times
Contact:

Re: Flowcode 5-Shadow Detect Program

Postby medelec35 » Wed Mar 20, 2013 2:31 pm

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
These users thanked the author medelec35 for the post:
JDR04 (Wed Mar 20, 2013 5:00 pm)
Rating: 5.26%
 
Martin

If you read a post that is useful, please show appreciation by clicking on thumbs up Icon.

JDR04
Posts: 264
Joined: Tue Mar 05, 2013 10:49 pm
Has thanked: 111 times
Been thanked: 13 times
Contact:

Re: Flowcode 5-Shadow Detect Program

Postby JDR04 » Wed Mar 20, 2013 5:00 pm

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
Attachments
PIC 16F690 Circuit-PDF.pdf
(7.89 KiB) Downloaded 77 times

User avatar
medelec35
Valued Contributor
Valued Contributor
Posts: 8440
Joined: Sat May 05, 2007 2:27 pm
Location: Northamptonshire, UK
Has thanked: 2412 times
Been thanked: 3450 times
Contact:

Re: Flowcode 5-Shadow Detect Program

Postby medelec35 » Wed Mar 20, 2013 6:14 pm

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
Attachments
Shadow Detect2 with hysteresis.fcf
(17.5 KiB) Downloaded 69 times
These users thanked the author medelec35 for the post:
JDR04 (Wed Mar 20, 2013 7:42 pm)
Rating: 5.26%
 
Martin

If you read a post that is useful, please show appreciation by clicking on thumbs up Icon.

JDR04
Posts: 264
Joined: Tue Mar 05, 2013 10:49 pm
Has thanked: 111 times
Been thanked: 13 times
Contact:

Re: Flowcode 5-Shadow Detect Program

Postby JDR04 » Wed Mar 20, 2013 7:41 pm

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

User avatar
medelec35
Valued Contributor
Valued Contributor
Posts: 8440
Joined: Sat May 05, 2007 2:27 pm
Location: Northamptonshire, UK
Has thanked: 2412 times
Been thanked: 3450 times
Contact:

Re: Flowcode 5-Shadow Detect Program

Postby medelec35 » Wed Mar 20, 2013 8:07 pm

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 5272 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.
Martin

If you read a post that is useful, please show appreciation by clicking on thumbs up Icon.

JDR04
Posts: 264
Joined: Tue Mar 05, 2013 10:49 pm
Has thanked: 111 times
Been thanked: 13 times
Contact:

Re: Flowcode 5-Shadow Detect Program

Postby JDR04 » Wed Mar 20, 2013 8:33 pm

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

User avatar
medelec35
Valued Contributor
Valued Contributor
Posts: 8440
Joined: Sat May 05, 2007 2:27 pm
Location: Northamptonshire, UK
Has thanked: 2412 times
Been thanked: 3450 times
Contact:

Re: Flowcode 5-Shadow Detect Program

Postby medelec35 » Wed Mar 20, 2013 9:34 pm

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.
These users thanked the author medelec35 for the post:
JDR04 (Wed Mar 20, 2013 10:26 pm)
Rating: 5.26%
 
Martin

If you read a post that is useful, please show appreciation by clicking on thumbs up Icon.