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

Post by Jayadev »

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 15252 times

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: Learner PIC

Post by medelec35 »

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 334 times
Martin

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

Re: Learner PIC

Post by Jayadev »

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

Regards

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: Learner PIC

Post by medelec35 »

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
Martin

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

Re: Learner PIC

Post by Jayadev »

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 ?

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: Learner PIC

Post by medelec35 »

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
(122.65 KiB) Downloaded 10476 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
(247.45 KiB) Downloaded 10476 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

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

Re: Learner PIC

Post by Jayadev »

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 15166 times

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

Re: Learner PIC

Post by Jayadev »

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

Post by Jayadev »

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 288 times

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: Learner PIC

Post by medelec35 »

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
(87.89 KiB) Downloaded 10401 times
Do you still require help with EEPROM?


Martin
Martin

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

Re: Learner PIC

Post by Jayadev »

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.

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: Learner PIC

Post by medelec35 »

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 242 times
Martin

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: Learner PIC

Post by medelec35 »

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 258 times
Martin

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

Re: Learner PIC

Post by Jayadev »

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.

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: Learner PIC

Post by medelec35 »

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
(1.62 KiB) Downloaded 9604 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
Martin

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

Re: Learner PIC

Post by Jayadev »

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 1 to 7
Bit 1 to 7
Bit.JPG (12.79 KiB) Viewed 14323 times
Star on them
Star on them
led.JPG (24.04 KiB) Viewed 14323 times

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: Learner PIC

Post by medelec35 »

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
(3.78 KiB) Downloaded 9572 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
(5.66 KiB) Downloaded 9572 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
Martin

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

Re: Learner PIC

Post by Jayadev »

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 14300 times

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: Learner PIC

Post by medelec35 »

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

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

Re: Learner PIC

Post by Jayadev »

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?

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: Learner PIC

Post by medelec35 »

If you post your flowchart I will take a look.
Martin

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

Re: Learner PIC

Post by Jayadev »

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 ... General%29"

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

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: Learner PIC

Post by medelec35 »

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 214 times
Martin

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

Re: Learner PIC

Post by Jayadev »

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 14244 times

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: Learner PIC

Post by medelec35 »

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
(11.86 KiB) Downloaded 9495 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
(16.81 KiB) Downloaded 9495 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
Martin

Post Reply