Learner PIC

For Flowcode users to discuss projects, flowcharts, and any other issues related to Flowcode 6.

Moderator: Benj

Jayadev
Posts: 17
Joined: Fri Jan 30, 2015 12:06 pm
Has thanked: 15 times
Been thanked: 1 time
Contact:

Learner PIC

Postby Jayadev » Fri Jan 30, 2015 1:10 pm

Hello everybody,

I am Jay, a beginner in embedded programming and I have no idea of any other programming language.I came across this amazing tool flowcode through youtube .

I expect to build some basic circuits and at first and learn.I have good skills in Analogue and linear electronics.

I have some pic micros recently purchased a Pickit2. I have already downloaded some ready to use firmer and made a few simple working e.g A frequency counter and a Inductance meter,But I came across some issues with codes which I am unable to resolve so I thought I should start building codes myself.So I started off by Learning C and "Hello world" but I understood it will take me very long to make it . FLowcode looks very promising and it seems to be virtually working.

As of now I am trying to make a switch with 12f675 which turns on with momentary switch and turns off with next press.But it is is supposed to activaate only when switch is depressed but my code gets active moment switch is pressed and it gets kind confused and it remain in state I can noticed code is running in the simulation.

I hope I am right place to seek help.




Thank you
Attachments
Capture.JPG
Capture.JPG (88.55 KiB) Viewed 10467 times

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

Re: Learner PIC

Postby medelec35 » Fri Jan 30, 2015 3:15 pm

Hi Jay,
welcome to the forums and the world of flowcode.
Yes you have posted in the right place for help :)
I have attached how I personally create a flowchart to toggle an output for a momentary switch.

I would recommend taking a look at the Learning Centre
I would also suggest following the link that's a part of my signature.

Good luck and most of all, have fun!

Martin
Attachments
Toggle_Switch.fcfx
(6.36 KiB) Downloaded 201 times
These users thanked the author medelec35 for the post:
Jayadev (Sat Jan 31, 2015 12:40 pm)
Rating: 5%
 
Martin

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

Jayadev
Posts: 17
Joined: Fri Jan 30, 2015 12:06 pm
Has thanked: 15 times
Been thanked: 1 time
Contact:

Re: Learner PIC

Postby Jayadev » Fri Jan 30, 2015 9:36 pm

Thank you very much martin I am going through the learning centre as of now.Will come back

Regards

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

Re: Learner PIC

Postby medelec35 » Fri Jan 30, 2015 10:53 pm

No problem if you get stuck then we can off further help.

One thing you will need to do is change the clock speed to 4MHz (Build, project options), as I left that bit out.

Martin
These users thanked the author medelec35 for the post:
Jayadev (Sat Jan 31, 2015 12:40 pm)
Rating: 5%
 
Martin

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

Jayadev
Posts: 17
Joined: Fri Jan 30, 2015 12:06 pm
Has thanked: 15 times
Been thanked: 1 time
Contact:

Re: Learner PIC

Postby Jayadev » Sat Jan 31, 2015 12:40 pm

What is cost of Flowcode for beginner like me? I am from India.I did not find merchandise link in matrix website.
It looks like my demo V6 will expire within a few days.Will I still be able to continue using it for learning/programming purpose for my basic projects ?

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

Re: Learner PIC

Postby medelec35 » Sat Jan 31, 2015 1:34 pm

Hi Jay,
Jayadev wrote: I am from India.I did not find merchandise link in matrix website.

If you go to the main site: http://www.matrixtsl.com
Select About then Distributors
You will be able to select your nearest country:
Distributors.png
Distributors.png (122.66 KiB) Viewed 10431 times

Jayadev wrote:It looks like my demo V6 will expire within a few days.Will I still be able to continue using it for learning/programming purpose for my basic projects ?

I believe it resorts to the free version.
The datasheet shows this:
Licenses.png
Licenses.png (247.45 KiB) Viewed 10431 times

To me it looks like the free version (after 30 days) does not compile to hex since there will be no chip pack enabled.
I could be wrong of course so someone else may have to answer that one.

Martin
Martin

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

Jayadev
Posts: 17
Joined: Fri Jan 30, 2015 12:06 pm
Has thanked: 15 times
Been thanked: 1 time
Contact:

Re: Learner PIC

Postby Jayadev » Thu Mar 12, 2015 10:13 am

Hi Medelec,
Thank you for your support.
Yes you are right there is some limitations but I am going through videos and trying to learn.Without having much of programming skills and all by myself I am on a bit of hard road . I will be in touch here.
Attachments
Capture.JPG
Capture.JPG (37.07 KiB) Viewed 10381 times

Jayadev
Posts: 17
Joined: Fri Jan 30, 2015 12:06 pm
Has thanked: 15 times
Been thanked: 1 time
Contact:

Re: Learner PIC

Postby Jayadev » Thu Mar 12, 2015 10:22 am

medelec35 wrote:Hi Jay,
welcome to the forums and the world of flowcode.
Yes you have posted in the right place for help :)
I have attached how I personally create a flowchart to toggle an output for a momentary switch.

I would recommend taking a look at the Learning Centre
I would also suggest following the link that's a part of my signature.

Good luck and most of all, have fun!

Martin


Hi Medelec,This 'file' being my proper learning foundation . I am tweaking and trying many things.e.g PWM driver,LED dimmer,timer etc. I feel great to say I see hopes.

Can you also Demostrate how to add an l eprom or memory so that the Pic remember/read the last state when power is turned back on .I am not sure if this x675 is capable of exernal eprom or maybe if you have a better one please do share and help.
Thanks in Advance.

Jayadev
Posts: 17
Joined: Fri Jan 30, 2015 12:06 pm
Has thanked: 15 times
Been thanked: 1 time
Contact:

Re: Learner PIC

Postby Jayadev » Sat Mar 14, 2015 7:53 pm

Hi Martin,

I am trying to add another switch ,but somehow it doesn't seems to work for me.I am sure I am missing something .Please help
PFA.
Attachments
Toggle_Switch 2nd.fcfx
(8.75 KiB) Downloaded 154 times

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

Re: Learner PIC

Postby medelec35 » Sat Mar 14, 2015 9:08 pm

Hi Jay,
What problem are you having with adding switches?
Can you give more details please.
I went to the Inputs menu, selected switch and add to dashboard panel and switch was placed in the dashboard panel OK:
Adding sw.png
Adding sw.png (87.9 KiB) Viewed 10356 times


Do you still require help with EEPROM?


Martin
These users thanked the author medelec35 for the post:
Jayadev (Tue Mar 17, 2015 5:04 pm)
Rating: 5%
 
Martin

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

Jayadev
Posts: 17
Joined: Fri Jan 30, 2015 12:06 pm
Has thanked: 15 times
Been thanked: 1 time
Contact:

Re: Learner PIC

Postby Jayadev » Tue Mar 17, 2015 5:01 pm

medelec35 wrote:Hi Jay,
What problem are you having with adding switches?
Can you give more details please.
I went to the Inputs menu, selected switch and add to dashboard panel and switch was placed in the dashboard panel OK:
Adding sw.png


Hi Martin,

I have added the switch to panel but I am unable to get the bistable condition for the second switch /led. please see to the attached file in my previous post.

medelec35 wrote:Do you still require help with EEPROM?


Martin


I would be obliged if you could help me with eeprom internal or external.As how it reads and writes every action and remembers after power off/on
As I am a beginner I am finding bit hard to get it.

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

Re: Learner PIC

Postby medelec35 » Tue Mar 17, 2015 8:45 pm

Hi Jay,
I have modified Flowchart to work with 3 switches and save output to internal EEPROM
To view the contents of EEPROM select Console from the View menu.
When reading EEPROM you need to not that the default value is always 255
What I do if 255 could be a value I would like to save is when writing to EEPROM say address 0 (1st address) for the fist time is also write a set number to address 1.
Then when power is restored, address 1 is read first, if it is the set number then read address 0 and assign to variable.
If address 1 is not the set number then ignore value of address 0

Things to remember about writing to EEPROM is they have a limited number of guaranteed successful write times (between 100K and 1M for 12F675)

So only write to EEPROM when necessary.
when you do write to EEPROM and remove power, EEPROM should how the correct value for at least 40 years!

Martin
Attachments
Toggle_Switch Multiple A.fcfx
(12.22 KiB) Downloaded 138 times
These users thanked the author medelec35 for the post (total 2):
Benj (Wed Mar 18, 2015 12:11 pm) • Jayadev (Tue Mar 24, 2015 8:24 pm)
Rating: 10%
 
Martin

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

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

Re: Learner PIC

Postby medelec35 » Wed Mar 18, 2015 2:47 pm

Modified Flowchart to use 3 bool variables for the 3 outputs.
Still only using a single byte to store individual bool values within EEPROM
Just saves EEPROM space.

Martin
Attachments
Toggle_Switch Multiple B.fcfx
(13.62 KiB) Downloaded 159 times
These users thanked the author medelec35 for the post:
Jayadev (Tue Mar 24, 2015 8:25 pm)
Rating: 5%
 
Martin

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

Jayadev
Posts: 17
Joined: Fri Jan 30, 2015 12:06 pm
Has thanked: 15 times
Been thanked: 1 time
Contact:

Re: Learner PIC

Postby Jayadev » Fri Feb 12, 2016 9:23 pm

medelec35 wrote:Modified Flowchart to use 3 bool variables for the 3 outputs.
Still only using a single byte to store individual bool values within EEPROM
Just saves EEPROM space.

Martin

Hi Medelec,

Due to some unavoidable reasons my study of programming completely halted.
But I am back to it again and I will stick to it henceforth .Apologies if that looks awkward.

I am trying to understand this expression from above file

"Output = Output XOR Switches << 3" (XOR - Exclusive OR <<3 = shift left 3 palces which is same as * 8 )
I do understand what is Xor.
What I dont understand <<3 shifting 3 places to left.What is being shifted to left here. And how does the Program recognizes which switch is being pressed and which output should be toggled correspondingly.

Thanks.

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

Re: Learner PIC

Postby medelec35 » Fri Feb 12, 2016 11:03 pm

Hi Jayadev,
Jayadev wrote:I do understand what is Xor.

XOR is eXclusive OR
Which means the output is high only when both inputs are exclusivity different.
The <<3 (shift three places to the left) just shift the bits 3 places to the left because the i/p is the first 3 bits and the output is from bit 4 to bit 7
For example if the output variable is 0 and A1 switch is high then with out the shift you have output = 00000010
now shift 3 places you have output = 00010000 = 16 which will light LED on A4

Reason for XOR is if A1 goes high again and is shifted 3 places to the left you will have
output = 00010000 XOR 00010000
the truth table for XOR is:
XOR Truth Table.png
XOR Truth Table.png (1.62 KiB) Viewed 9559 times

Since we are looking at bit 4 they are both 1
so 1 XOR 1 = 0
so bit 4 changes from 1 to 0 turning off LED on A4 so output = 00000000

Again if A1 is high then shifted 3 places to the left is high so you have
00000000 XOR 00010000
then A4 will go from low to high.
The affect of using XOR is to simply toggle a bit every time the switch is high.

Martin
These users thanked the author medelec35 for the post:
Jayadev (Sat Feb 13, 2016 9:35 am)
Rating: 5%
 
Martin

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

Jayadev
Posts: 17
Joined: Fri Jan 30, 2015 12:06 pm
Has thanked: 15 times
Been thanked: 1 time
Contact:

Re: Learner PIC

Postby Jayadev » Sat Feb 13, 2016 10:06 am

Hello Medelec,
Thank you quick response.
medelec35 wrote:
The <<3 (shift three places to the left) just shift the bits 3 places to the left because the i/p is the first 3 bits and the output is from bit 4 to bit 7

Does this 1-7 'bit' means pinout for the ports which is not as straight as I think or something more please explain . (attached a picture)

medelec35 wrote: For example if the output variable is 0 and A1 switch is high then with out the shift you have output = 00000010
now shift 3 places you have output = 00010000 = 16 which will light LED on A4

I noticed and understood that Bits are being shifted physically (not added),doesn't that mean we can use integer '16' directly to toggle A4 output (in general),If yes how it would be done.

medelec35 wrote: Reason for XOR is if A1 goes high again and is shifted 3 places to the left you will have
output = 00010000 XOR 00010000,Since we are looking at bit 4 they are both 1,so 1 XOR 1 = 0,
so bit 4 changes from 1 to 0 turning off LED on A4 so output = 00000000

Again if A1 is high then shifted 3 places to the left is high so you have
00000000 XOR 00010000 then A4 will go from low to high.
The affect of using XOR is to simply toggle a bit every time the switch is high.
Martin

This is well explained ,very helpful .However I am having a little trouble to picturise the bit wise operation probably because I am a newbie.I will try this out on a paper and see.

In below pic I see a red star on all of my flowchart boxes. Why are they showing up?
Attachments
Bit.JPG
Bit 1 to 7
Bit.JPG (12.79 KiB) Viewed 9538 times
led.JPG
Star on them
led.JPG (24.04 KiB) Viewed 9538 times

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

Re: Learner PIC

Postby medelec35 » Sat Feb 13, 2016 12:20 pm

Hi Jayadev,
No problem.
Jayadev wrote:Does this 1-7 'bit' means pinout for the ports which is not as straight as I think or something more please explain . (attached a picture)

Yes It is the pinout for the port.
The port in this case is 8 bits wide but we are just using bits 0 to 5 (A0 to A5):
Switch control LED1.png
Switch control LED1.png (3.78 KiB) Viewed 9527 times
Jayadev wrote:doesn't that mean we can use integer '16' directly to toggle A4 output (in general),If yes how it would be done.

That's why you shift bit 1 three places.
If switch on A1 is high = 2.
Then by shifting it three places it is going to be =16
So if port A was already = 16 and you XOR with 16 then that bit will go to 0.
If port A was 0 then after XORing with 16, port A = 16
Port Values1.png
Port Values1.png (5.66 KiB) Viewed 9527 times

Jayadev wrote:In below pic I see a red star on all of my flowchart boxes. Why are they showing up?

Red stars just means changes have been made since flowchart was last saved.
So if you save the flowchart all stars will disappear.
As soon you add or edit a component or calculation box, then the star will appear until flowchart is again saved.

As a seperate note.
If you press F8 to single step, Select arrow next to expression, it will allow you to add variables so you can watch what their values are.
This aids in debugging and helps to find out how flowcharts work.

Martin
These users thanked the author medelec35 for the post:
Jayadev (Sat Feb 13, 2016 2:12 pm)
Rating: 5%
 
Martin

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

Jayadev
Posts: 17
Joined: Fri Jan 30, 2015 12:06 pm
Has thanked: 15 times
Been thanked: 1 time
Contact:

Re: Learner PIC

Postby Jayadev » Sun Feb 14, 2016 10:37 am

Hi Medelec,
Thank you for above explanation.

I am trying to use a rotary encorder in place of the toggle switches so that whichever side the Encoder is rotated that side led glows,but the output from an encoder is bit complex compared to toggle switches.

Also I am unable to rotate the encoder in simulation to see the changes. like the way toggled switches
Attachments
rtry.JPG
rtry.JPG (42.07 KiB) Viewed 9515 times

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

Re: Learner PIC

Postby medelec35 » Sun Feb 14, 2016 11:24 am

Only when flowcode simulator is running you can click the red arrows to move in the direction arrows show.
Keep mouse button down for continuous movement.
These users thanked the author medelec35 for the post:
Jayadev (Sun Feb 14, 2016 12:21 pm)
Rating: 5%
 
Martin

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

Jayadev
Posts: 17
Joined: Fri Jan 30, 2015 12:06 pm
Has thanked: 15 times
Been thanked: 1 time
Contact:

Re: Learner PIC

Postby Jayadev » Sun Feb 14, 2016 12:22 pm

medelec35 wrote:Only when flowcode simulator is running you can click the red arrows to move in the direction arrows show.
Keep mouse button down for continuous movement.


I did that way but it does not move. Is it due to my code is not right?

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

Re: Learner PIC

Postby medelec35 » Sun Feb 14, 2016 12:35 pm

If you post your flowchart I will take a look.
These users thanked the author medelec35 for the post:
Jayadev (Sun Feb 14, 2016 1:38 pm)
Rating: 5%
 
Martin

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

Jayadev
Posts: 17
Joined: Fri Jan 30, 2015 12:06 pm
Has thanked: 15 times
Been thanked: 1 time
Contact:

Re: Learner PIC

Postby Jayadev » Sun Feb 14, 2016 1:24 pm

medelec35 wrote:If you post your flowchart I will take a look.


I just downloaded Quad enc test file "http://www.matrixtsl.com/wiki/index.php?title=Component:_Encoder_Rotary_%28Inputs:_General%29"

ANd tried to add the encdoer but it would not move.
Attachments
Quad_Encoder_Test.fcfx
(8.04 KiB) Downloaded 105 times

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

Re: Learner PIC

Postby medelec35 » Sun Feb 14, 2016 1:45 pm

Hi,
you had two encoders added to your flowchart.
One on the system panel and one on the dashboard.
The components won't simulate (rotate on the panel) if enable wasn't added.
This turned out to be the case.
Encoder on the system panel does have enabled component added so that does rotate just fine.
I have removed encoder from the dashboard.

Martin
Attachments
Quad_Encoder_Test.fcfx
(7.6 KiB) Downloaded 123 times
These users thanked the author medelec35 for the post:
Jayadev (Sun Feb 14, 2016 1:55 pm)
Rating: 5%
 
Martin

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

Jayadev
Posts: 17
Joined: Fri Jan 30, 2015 12:06 pm
Has thanked: 15 times
Been thanked: 1 time
Contact:

Re: Learner PIC

Postby Jayadev » Tue Feb 16, 2016 5:51 pm

Hi Medelec,

Apologies for being so naive. I am supposed to go through lot of example files before asking questions but being such a newbie I am finding it difficult to move ahead.
I have have a few doubts.

1.As per the flowchart I thought the counter would reset after 255 but it doesnt.it seems to be counting forever.I made it count more than 1049
2.What does LCD_Write > 50 means in the decision box?
3.How do I add some words I think they are called strings. e.g. "No. of Rotation=140++"
4.What is difference between 'i==2' and 'i=2'
5.Fortunately,It seems like I don't have to add any codes for rotaryEncoder (Thanks to Flowcode team,But I will try to learn C as well soonest)
6.What would be my next step to say output the encoder to another port as serial data or pwm?
7.It seems like my logical part of the brain is not sparking up ,Why I am unable to find a quick solution,is it because I am a newbie ,lack of practice or do I have any reference books as learning aid.
Attachments
Capture.JPG
Capture.JPG (56.41 KiB) Viewed 9459 times

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

Re: Learner PIC

Postby medelec35 » Tue Feb 16, 2016 8:39 pm

Jayadev wrote:1.As per the flowchart I thought the counter would reset after 255 but it doesnt.it seems to be counting forever.I made it count more than 1049

It depends on what type the variables are designed to.
When you add a new variable:
Variable ranges1.png
Variable ranges1.png (11.87 KiB) Viewed 9450 times

You can see if you add a byte, when incrementing the variable will go 254,255,0,1 ...
When decrementing the variable will go 2,1,0,255,254....
Since Count variable is an integer then it will count to 32767 then If 1 is added will roll-over to -32768, -32767,-32766 etc.
If you want the count to stop at 255 and go to 0 then you need to change count variable from Integer to Byte.
Or you can add a decision branch
If Count >= 255 then Quad component ResetCounter
The 255 can be any number you like.
Jayadev wrote:2.What does LCD_Write > 50 means in the decision box?

I did not develop that flowchart but it look like its used to refresh LCD when LCD_Write is greater than 50.
Jayadev wrote:3.How do I add some words I think they are called strings. e.g. "No. of Rotation=140++"

There are two ways.
1 add a LCD PrintString component then add "text" within expression box:
Display String.png
Display String.png (16.81 KiB) Viewed 9450 times

2 You add a string variable and at the end of the name palce[] with the size within brackets.
Then within flowchart instead of adding "text" you add the string variable.
Jayadev wrote:4.What is difference between 'i==2' and 'i=2'

With Flowcode you can use either so nothing .
Jayadev wrote:6.What would be my next step to say output the encoder to another port as serial data or pwm?

Plan what you want to do then learn how it's controlled e.g. PWM
To do that look at the Learning centre as there is a free Flowcode Beginners course & numerous examples.
Also take a look a Flowcode wiki as there are links to examples.
These links and others can be found on the matrix main site under support.

You can use the variable values generated by the encoder to alter PWM (or whatever you want to do the encoder values)

Jayadev wrote:Why I am unable to find a quick solution,is it because I am a newbie ,lack of practice or do I have any reference books as learning aid.

Answered above.
Also there is an Book by Bert Van Dam see This link

You will be best doing some research, looking at examples and watching youtube videos

Hope this helps you.

Martin
These users thanked the author medelec35 for the post (total 3):
LeighM (Wed Feb 17, 2016 10:13 am) • Benj (Wed Feb 17, 2016 12:24 pm) • Jayadev (Fri Feb 19, 2016 1:38 pm)
Rating: 15%
 
Martin

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