HELP WITH A PROGRAM

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

Moderators: Benj, Mods

Post Reply
Jacob1
Posts: 35
Joined: Wed Dec 27, 2017 4:18 pm
Has thanked: 7 times
Been thanked: 6 times
Contact:

HELP WITH A PROGRAM

Post by Jacob1 »

Hi all,

I wondered if anyone would be able to help me with a program I have which is essentially a counter using a 8 bit led and 2 switches. I have attached the program brief below. I have been stuck with this program for a while as I am struggling to understand how the LEDS can be stopped and then restarted when the switch is pressed from the same LEDs. I have had a go at the program but I am not happy with the result,

Anyway, I would appreciate it if you could look at the attachment and give any help, advice (or even example solutions which would be perfect).

Thanks once again.
Attachments
Program counter.JPG
Program counter.JPG (52.58 KiB) Viewed 12749 times

kersing
Valued Contributor
Valued Contributor
Posts: 2045
Joined: Wed Aug 27, 2008 10:31 pm
Location: Netherlands
Has thanked: 553 times
Been thanked: 1081 times
Contact:

Re: HELP WITH A PROGRAM

Post by kersing »

You could start by posting what you have created. We do not supply ready answers for courseware as that will not teach you anything...
“Integrity is doing the right thing, even when no one is watching.”

― C.S. Lewis

Jacob1
Posts: 35
Joined: Wed Dec 27, 2017 4:18 pm
Has thanked: 7 times
Been thanked: 6 times
Contact:

Re: HELP WITH A PROGRAM

Post by Jacob1 »

Yes you are right I should have attached my work!

My program uses 4 switches, as I couldn't work out how to do it with 2. I'm not sure if my program does what it says on the brief, as I'm still a little bit confused to what it is asking in terms of how the program should work. My program still doesn't work fully.

Attached is my program,
Thanks a lot
Attachments
ex 7 prog 8 nv.fcfx
(20.24 KiB) Downloaded 298 times

Jacob1
Posts: 35
Joined: Wed Dec 27, 2017 4:18 pm
Has thanked: 7 times
Been thanked: 6 times
Contact:

Re: HELP WITH A PROGRAM

Post by Jacob1 »

Hi all,

I have done a few tweaks to the delay times for the program, so it runs smoothly. I just wondered how you can run two decision icon loops at the same time? As at the moment, the MSB LEDs count down and then the LSB LEDs count up and vice versa, but I believe this needs to happen in parallel. I am very new to flow code but I imagine there is a way of doing this.

Thanks
Attachments
ex 7 prog 8 final using 4 switches.fcfx
(20.51 KiB) Downloaded 298 times

User avatar
STibor
Posts: 263
Joined: Fri Dec 16, 2011 3:20 pm
Has thanked: 116 times
Been thanked: 113 times
Contact:

Re: HELP WITH A PROGRAM

Post by STibor »

sheep_counteer_2.fcfx
(18.71 KiB) Downloaded 355 times
Hello!
I used an internal rotary encoder component.

kersing
Valued Contributor
Valued Contributor
Posts: 2045
Joined: Wed Aug 27, 2008 10:31 pm
Location: Netherlands
Has thanked: 553 times
Been thanked: 1081 times
Contact:

Re: HELP WITH A PROGRAM

Post by kersing »

Jacob1 wrote:I just wondered how you can run two decision icon loops at the same time?
How about using one loop with two decision trees? Have a variable set to true if a count down is required and false if not and a condition to check if that part of the code needs to run, same for count up.
“Integrity is doing the right thing, even when no one is watching.”

― C.S. Lewis

Jacob1
Posts: 35
Joined: Wed Dec 27, 2017 4:18 pm
Has thanked: 7 times
Been thanked: 6 times
Contact:

Re: HELP WITH A PROGRAM

Post by Jacob1 »

STibor wrote:sheep_counteer_2.fcfxHello!
I used an internal rotary encoder component.
The program does not seem to work? :? I'm not sure how the encoder works and when the simulation is played two LEDs light up.

Jacob1
Posts: 35
Joined: Wed Dec 27, 2017 4:18 pm
Has thanked: 7 times
Been thanked: 6 times
Contact:

Re: HELP WITH A PROGRAM

Post by Jacob1 »

kersing wrote:
Jacob1 wrote:I just wondered how you can run two decision icon loops at the same time?
How about using one loop with two decision trees? Have a variable set to true if a count down is required and false if not and a condition to check if that part of the code needs to run, same for count up.
I have had to use 4 switches for my program which does now work. But could you explain a bit further what you mean by setting a variable true and how to do a condition check? Would it be possible for you to create a example of what you mean which might be easier for me to understand.

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: HELP WITH A PROGRAM

Post by medelec35 »

Hi Jacob1,
It looks like you're reading Introduction To Microprogramming - The complete course.
Have you been jumping straight into all the exercises, without reading from page 39 onwards first?

The idea is to complete the exercises only after reading the relevant parts of the course.
If you can't complete the exercises then more reading will be required first.
Only then ask if really stuck.
Take a look in the Learning centre
There are Flowcode Training Videos and other useful resources.
Another good place to visit is Flowcode V7 Wiki.

Martin
Martin

User avatar
STibor
Posts: 263
Joined: Fri Dec 16, 2011 3:20 pm
Has thanked: 116 times
Been thanked: 113 times
Contact:

Re: HELP WITH A PROGRAM

Post by STibor »

Jacob1 wrote:
STibor wrote:sheep_counteer_2.fcfxHello!
I used an internal rotary encoder component.
The program does not seem to work? :? I'm not sure how the encoder works and when the simulation is played two LEDs light up.
Maybe I do not understand the question.

https://youtu.be/wyFQ1l6FkWI

Jacob1
Posts: 35
Joined: Wed Dec 27, 2017 4:18 pm
Has thanked: 7 times
Been thanked: 6 times
Contact:

Re: HELP WITH A PROGRAM

Post by Jacob1 »

STibor wrote:
Jacob1 wrote:
STibor wrote:sheep_counteer_2.fcfxHello!
I used an internal rotary encoder component.
The program does not seem to work? :? I'm not sure how the encoder works and when the simulation is played two LEDs light up.
Maybe I do not understand the question.

https://youtu.be/wyFQ1l6FkWI
The program you have sent is missing those two buttons above shown on the YouTube video, which is why maybe it is not working but I'm not sure. :?

User avatar
STibor
Posts: 263
Joined: Fri Dec 16, 2011 3:20 pm
Has thanked: 116 times
Been thanked: 113 times
Contact:

Re: HELP WITH A PROGRAM

Post by STibor »

Opened in Flowcode v7, there are two pushbuttons.
Port A0 and PortA1 connected. I upload a Flowcode v6-v7 compatible program.
Attachments
sheep_counteer_3_fc6.fcfx
(13.89 KiB) Downloaded 216 times

Jacob1
Posts: 35
Joined: Wed Dec 27, 2017 4:18 pm
Has thanked: 7 times
Been thanked: 6 times
Contact:

Re: HELP WITH A PROGRAM

Post by Jacob1 »

STibor wrote:Opened in Flowcode v7, there are two pushbuttons.
Port A0 and PortA1 connected. I upload a Flowcode v6-v7 compatible program.
When the switches are pressed no LEDs light up. I think it is opening it wrong on my laptop for some reason, I'm guessing as I can see it works on your You tube video fine. I've screenshotted the simulation, do I need to change anything or is ready to be simulated?

Thanks for your help
Jacob
Attachments
Program simulation.JPG
Program simulation.JPG (106.32 KiB) Viewed 12628 times
Last edited by Jacob1 on Sun Dec 31, 2017 6:11 pm, edited 2 times in total.

Jacob1
Posts: 35
Joined: Wed Dec 27, 2017 4:18 pm
Has thanked: 7 times
Been thanked: 6 times
Contact:

Re: HELP WITH A PROGRAM

Post by Jacob1 »

medelec35 wrote:Hi Jacob1,
It looks like you're reading Introduction To Microprogramming - The complete course.
Have you been jumping straight into all the exercises, without reading from page 39 onwards first?

The idea is to complete the exercises only after reading the relevant parts of the course.
If you can't complete the exercises then more reading will be required first.
Only then ask if really stuck.
Take a look in the Learning centre
There are Flowcode Training Videos and other useful resources.
Another good place to visit is Flowcode V7 Wiki.

Martin
Hi,

I have been reading the Flow code 6 tutorials, which is the same as the content from page 39 onwards from the complete course booklet you stated. In my opinion, the tutorial content or the content from page 39 onwards from the complete course booklet doesn't cover all the program exercises that you have to complete. So it would be useful if they were more tailored to the exercises and if they were Flowcode 7 content not Flowcode 6. But that's just my opinion of the course booklet and I have been able to get most of the programs to work on simulation and with the micro controller itself, so I must be learning something!
Thanks for the links you have given me, I have managed to get the program to work but with 4 switches.
Jacob

User avatar
STibor
Posts: 263
Joined: Fri Dec 16, 2011 3:20 pm
Has thanked: 116 times
Been thanked: 113 times
Contact:

Re: HELP WITH A PROGRAM

Post by STibor »

Jacob1 wrote:
STibor wrote:Opened in Flowcode v7, there are two pushbuttons.
Port A0 and PortA1 connected. I upload a Flowcode v6-v7 compatible program.
When the switches are pressed no LEDs light up. I think it is opening it wrong on my laptop for some reason, I'm guessing as I can see it works on your You tube video fine. I've screenshotted the simulation, do I need to change anything or is ready to be simulated?

Thanks for your help
Jacob
I think you do not fully test switch logic.
Example:
The sheep goes from right to left.
Initial value, left and right are 0 logical values.
4/1, right side switch logic value = 1, left side logical value = 0 (sheep activates right sensor)
4/2, right side switch logic value = 1, left logical value = 1 (sheep activates both sensors)
4/3, right side switch logic value = 0, left page logic value = 1 (sheep activates left sensor)
4/4, right side switch logic value = 0, left logical value = 0 (sheep on left side, end of cycle, increase of left counter, number display, etc.)

Jacob1
Posts: 35
Joined: Wed Dec 27, 2017 4:18 pm
Has thanked: 7 times
Been thanked: 6 times
Contact:

Re: HELP WITH A PROGRAM

Post by Jacob1 »

STibor wrote:
Jacob1 wrote:
STibor wrote:Opened in Flowcode v7, there are two pushbuttons.
Port A0 and PortA1 connected. I upload a Flowcode v6-v7 compatible program.
When the switches are pressed no LEDs light up. I think it is opening it wrong on my laptop for some reason, I'm guessing as I can see it works on your You tube video fine. I've screenshotted the simulation, do I need to change anything or is ready to be simulated?

Thanks for your help
Jacob
I think you do not fully test switch logic.
Example:
The sheep goes from right to left.
Initial value, left and right are 0 logical values.
4/1, right side switch logic value = 1, left side logical value = 0 (sheep activates right sensor)
4/2, right side switch logic value = 1, left logical value = 1 (sheep activates both sensors)
4/3, right side switch logic value = 0, left page logic value = 1 (sheep activates left sensor)
4/4, right side switch logic value = 0, left logical value = 0 (sheep on left side, end of cycle, increase of left counter, number display, etc.)


Your right I wasn't testing it properly! I get how it works now, so from right to left both switches need to be pressed but then sensor 1 is turned off first as it has passed it, clever :) Out of curiosity, what does the encoder do in the program? Could you briefly explain how the program works as all the text is not in English?

Thank you for your help,
Jacob

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: HELP WITH A PROGRAM

Post by medelec35 »

Hi Jacob,
I have created a flowchart that uses loops, Switch component (2 branches) and decision icons.
In order to follow flowchart you need to know how the Switch component:
Switch Comonent.png
(6.91 KiB) Downloaded 4731 times
works.
You also need to know how to do bitwise e.g

Code: Select all

& |
etc.
Logic manipulation using

Code: Select all

&& ||
etc.
Also

Code: Select all

 >>
and

Code: Select all

<<
.
So you show you understand bit wise can you explain how I got to split the number of sheep in each pen on the left and right side of port B:
Binary seperaton.png
(75.42 KiB) Downloaded 4728 times
Note only used one variable called

Code: Select all

LefthandPaddock
to store and display the results,
As you can see, if the Left hand Paddock contains 5 = 4 + 1, then Right hand Paddock contains 1

Martin
Attachments
ex 7 prog 8 nv1.fcfx
(22.2 KiB) Downloaded 184 times
Martin

Jacob1
Posts: 35
Joined: Wed Dec 27, 2017 4:18 pm
Has thanked: 7 times
Been thanked: 6 times
Contact:

Re: HELP WITH A PROGRAM

Post by Jacob1 »

medelec35 wrote:Hi Jacob,
I have created a flowchart that uses loops, Switch component (2 branches) and decision icons.
In order to follow flowchart you need to know how the Switch component:Switch Comonent.pngworks.
You also need to know how to do bitwise e.g

Code: Select all

& |
etc.
Logic manipulation using

Code: Select all

&& ||
etc.
Also

Code: Select all

 >>
and

Code: Select all

<<
.
So you show you understand bit wise can you explain how I got to split the number of sheep in each pen on the left and right side of port B:Binary seperaton.png

Note only used one variable called

Code: Select all

LefthandPaddock
to store and display the results,
As you can see, if the Left hand Paddock contains 5 = 4 + 1, then Right hand Paddock contains 1

Martin

Thanks for your example!
I will need to do some reading on logic manipulation and bitwise, is there a specific link I can go to for this is should I try the Flowcode wiki?

Thanks for your help once again
Jacob

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: HELP WITH A PROGRAM

Post by medelec35 »

You're welcome.
Jacob1 wrote:I have done some research regarding bite wise functions and logical but I am still unsure about how the program actually works. Especially for the prev sensor variable and the last output icon.
if you need anymore reading, one place to look is here.
Also from page 75 of the course goes into bitwise operations a bit excuse the pun lol.

prev sensor variable is just to store the input value before it changes.
Its just use for comparing current input with the previous input.
that way you know which direction the sheep is going.

To make it easier for you, just single step by pressing F8.
change the switches and watch the variables within Simulation debugger change.
You can also watch the variables change value when simulation is running, but the simulation speed must not be on Normal!
Are you able to workout how the output works?
Martin

Jacob1
Posts: 35
Joined: Wed Dec 27, 2017 4:18 pm
Has thanked: 7 times
Been thanked: 6 times
Contact:

Re: HELP WITH A PROGRAM

Post by Jacob1 »

Yeah the step into is great button!

I get why the prev sensors is used now, as it will stay in the loop until both switches have been turned on and one has been turned off, as this then means the while statement is false?

However, I'm a bit unsure as to why when both switches have been turned on and then when one is turned off the switch icon loop is chosen? Is this because the switch icon uses the old sensor or prev sensor as you've named it.

E.g When switch A0 is turned off it chooses the first switch loop, I thought these loops were only chosen when a switch is on?

As the switch loops will be 1,2,4,8,16,32..... and the loop is selected when the corresponding switch is chosen in binary.

Just still a little bit confused about the statements inside the loops etc

Thanks for your help
Jacob

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: HELP WITH A PROGRAM

Post by medelec35 »

I created the logic for changing LefthandPaddock value.
for decreasing LefthandPaddock (sheep going from left to right):

Code: Select all

A1 A0
1  0
0  1
0  0
It's required to wait for 0 0 as it states the sheep can change their mind.
to increase LefthandPaddock:

Code: Select all

A1 A0
0  1
1  0
0  0
so 1 1 is ignored.
The switch icon is for testing the logic conditions.
Have another look and see if you can see the above logic working as you step into the code?
Do you understand how the switch component function works?

Do you agree with the logic I used?
Martin

Jacob1
Posts: 35
Joined: Wed Dec 27, 2017 4:18 pm
Has thanked: 7 times
Been thanked: 6 times
Contact:

Re: HELP WITH A PROGRAM

Post by Jacob1 »

medelec35 wrote:I created the logic for changing LefthandPaddock value.
for decreasing LefthandPaddock (sheep going from left to right):

Code: Select all

A1 A0
1  0
0  1
0  0
It's required to wait for 0 0 as it states the sheep can change their mind.
to increase LefthandPaddock:

Code: Select all

A1 A0
0  1
1  0
0  0
so 1 1 is ignored.
The switch icon is for testing the logic conditions.
Have another look and see if you can see the above logic working as you step into the code?
Do you understand how the switch component function works?


Do you agree with the logic I used?

Yeah im getting it now. As the switch uses the old sensor as its variable, which is only ever 1 or 2 so it selects that loop. In terms of the logic I belive you are right, but on mine the sim bugger shows this as 1,2,3 as in the binary value.

E.g left to right =

when A1 pressed
Sensor Oldsensor
2 2

When A0 pressed
Sensor Old sensor
3 2

When A1 pressed off
Sensor Old sensor
1 2


This brings me onto my next question, what does this statement mean "(Oldsensor <> Sensors) && (Sensors < 3)", especially <>?


So now the old sensor is 2 so the switch with number 2 is followed, the loop is followed causing:
Sensor Old sensor
1 1

When A0 is turned off the sensor total is now 0 so the while statement is false, as sensor has to be greater than 0 for it to continue

So now countdown can take place if the count variable is greater than 0

In terms of the final output icon, from left to right I believe the second bracket apply s which is (6 - Countvar & 15), this is how ive understood it:


6 = 0000 0110
15= 0000 1111
Count var = -1
E.g 6 = 6 -1 will be 5

So 6 - 5 AND 15
will be 0000 0001 AND 0000 1111

Total = 0000 0001 which is the first LED light up, this will continue for each cycle

Thanks!
Jacob

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: HELP WITH A PROGRAM

Post by medelec35 »

Jacob1 wrote:This brings me onto my next question, what does this statement mean "(Oldsensor <> Sensors) && (Sensors < 3)", especially <>?
So
> greater than
< less than
<> not equals to

Which is the same as
!=
You can use either method as the results should be the same!
So

Code: Select all

Oldsensor <> Sensors
means only true when Oldsensor is a diffent value to Sensors.

Code: Select all

&& (Sensors < 3)
AND when old sensors is less than 3 in value.
Putting it all together:
Value is only TRUE (1 in value) when value of (Oldsensor AND Sensors) are different AND the value of Sensors is less than 3.

Hope this helps to make it more clear?
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: HELP WITH A PROGRAM

Post by medelec35 »

Hi Jacob,
suppose there was 2 sheep in the left paddock.
Can you explain how the output will show the values of both left and right paddocks?
So basically can you explain how

Code: Select all

(LefthandPaddock << 4 & 240) | (6 - LefthandPaddock & 15)
works.
You only partially explained in your last post.

Martin
Martin

Post Reply