Unable to get physical results as per simulation using LCD

For Flowcode users to discuss projects, flowcharts, and any other issues related to Flowcode 4.
To post in this forum you must have a registered copy of Flowcode 4 or higher. To sign up for this forum topic please use the "Online Resources" link in the Flowcode Help Menu.

Moderator: Benj

Post Reply
User avatar
John_RSD
Posts: 20
Joined: Sun May 15, 2011 9:23 pm
Location: UK
Has thanked: 3 times
Been thanked: 2 times
Contact:

Unable to get physical results as per simulation using LCD

Post by John_RSD »

Hi all

I have ran into a few issues on my first complete project using FC. Initially I started using it, just to test hardware but it was so much fun I cannot stop myself ;-)

My first application was to control a small DC motor direction/rotational position remotely.
Feedback would be via a pot directly coupled to the output shaft and read via the ADC.
Using ADC(0) as input, internal Vref and the pot will deliver 0-5Vish.
There will be a control loop eventually, for now I am just turning a pot manually and checking value on a LCD display, the LCD will be fitted, but main control will be through USB serial.
Device is a PIC18F4550

I have a lot working but had to cut back to debug. Now i am kind of stuck wondering if my display has some issue or if I have a memory issue.

LCD set to show a string "ADC VALUE", so I set display cursor to row 0 / 0 pos and then ShowString
LCD set to show me the ADC value as an int, so I set display cursor to row 0 / 10 pos and place a string ADC VALUE
All OK in simulation and real world.

LCD set to show a string "ROTATION", so I set display cursor to row 1 / 0 pos and then ShowString
LCD set to show me the ADC value, this time as after some conversion to a string (ADC value to float, /360 for step size, then work out the rotation, then change the resultant float to a string for display), so I set display cursor to row 0 / 10 pos and place a string POSITION
All OK in simulation, NOT OK in real world.
When I run this on the micro and real hardware, the rotation is always shown as 0.0. In simulation I see the correct 0-360 display.

So I am going to stick my neck out and assume the maths is OK, but something is lost on compile

Now one strange thing i notice when moving the pot in simulation, the ADC reads seem erranous, if I move the pot CW for the first time, it reads 0(well 15)-1023 at min/max position, but will read in the 1000's in between. That is except the first time I start the simulation and go from 0-1023, thats OK, winding back and fiorth after that, causes an issue.

Attached is a small screen capture

The real world display, does not follow the simulation on the displayed ADC value, that is always OK regardless of pot position, seems to be something in the simulation (or simulator)

But the simulation shows my rotational location, but the real world display does not.

Any tips or suggestions appreciated.
Attachments
0006.rar
Screen capture ADC
(80.9 KiB) Downloaded 273 times
Many thanks

John

medelec35
Matrix Staff
Posts: 9521
Joined: Sat May 05, 2007 2:27 pm
Location: Northamptonshire, UK
Has thanked: 2585 times
Been thanked: 3815 times

Re: Unable to get physical results as per simulation using L

Post by medelec35 »

Hi John Welcome to the Matrix forums.
John_RSD wrote: Initially I started using it, just to test hardware but it was so much fun I cannot stop myself ;-)
Don't worry, we all have that problem :P :lol:
John_RSD wrote: Now one strange thing i notice when moving the pot in simulation, the ADC reads seem erranous, if I move the pot CW for the first time, it reads 0(well 15)-1023 at min/max position, but will read in the 1000's in between. That is except the first time I start the simulation and go from 0-1023, thats OK, winding back and fiorth after that, causes an issue.

Attached is a small screen capture
Just after the print ADC Value (that prints 0 - 1023) ,
Place a LCDDisplay PrintString component.
Then in the string box do two sets of speech marks, separated by 3 spaces i.e " "
Then the old numbers will be overridden with spaces, and not kept.

As for the values not being the same, you need to use fdiv() function, within the calculation box (just click Function after double clicking calculation box).
Unfortunantly FloatA/FloatB does not work. You will need to use Float_Tot=fdiv(FloatA,FloatB)

If you don't mind sharing your flowchart, I'm sure we can assist you further.

Martin
Last edited by medelec35 on Sun Jul 24, 2011 11:45 pm, edited 1 time in total.
Martin

User avatar
John_RSD
Posts: 20
Joined: Sun May 15, 2011 9:23 pm
Location: UK
Has thanked: 3 times
Been thanked: 2 times
Contact:

Re: Unable to get physical results as per simulation using L

Post by John_RSD »

Hi Martin

Thanks for the quick reply, was not expecting any responses so quick.

I figured out about fdiv() eventually, I also moved some components around, a start and clear and eventually the simulation was behaving as it should. Do not ask me what part actually fixed the simulation, I have no idea.

So simulation and real world are now more or less the same.

The chart has changed some what as I now added a vegas test to my outputs (leds) and a couple of buttons to check EE read/write as I will need to store preset positions when I have got further.

Its off topic for the orignal title but I am now trying to figure that one out before doing much more by just using 2 buttons, one to set the E2_0 value based on ADC value, then read it back and display just to make sure it works real world. So far I am reading back as ascii but of course the displays char set does not always show whats been written. Ideally i would like to rewrite/read the actual corrected 0-360 value but have not figured that out yet.

Chart attached.
Attachments
LCD_test.rar
LCD TEST
(5.07 KiB) Downloaded 274 times
Many thanks

John

medelec35
Matrix Staff
Posts: 9521
Joined: Sat May 05, 2007 2:27 pm
Location: Northamptonshire, UK
Has thanked: 2585 times
Been thanked: 3815 times

Re: Unable to get physical results as per simulation using L

Post by medelec35 »

John_RSD wrote: Its off topic for the orignal title but I am now trying to figure that one out before doing much more by just using 2 buttons, one to set the E2_0 value based on ADC value, then read it back and display just to make sure it works real world. So far I am reading back as ascii but of course the displays char set does not always show whats been written. Ideally i would like to rewrite/read the actual corrected 0-360 value but have not figured that out yet.

Chart attached.
Your welcome John.
EEPROM is only 8bits wide, so you can only store numbers 0 - 255 in each location.

However there is a nice work around so you can store much higher numbers e.g 0 to 32767 etc. It is using the high byte and low byte of 16bit number.
Take a look here:
http://www.matrixmultimedia.com/mmforum ... 618#p22616
and if you get stuck, I can help you modify your flowchart.

Edit..For LCD if a byte or int number you want to dispaly,You can just use print number not print ASCII.
Martin
Martin

User avatar
John_RSD
Posts: 20
Joined: Sun May 15, 2011 9:23 pm
Location: UK
Has thanked: 3 times
Been thanked: 2 times
Contact:

Re: Unable to get physical results as per simulation using L

Post by John_RSD »

MArtin

Many thanks again, I will have ago and see if i get stuck.

There is a ways to go, I am sure I will have plenty questions, the complete project involves store/retrieve these position memories as well as being able to have 2 "cal" data stores, ultimately I want to drive full CCW until a stop is reached, then set 0 value, drive fully CW until the stop is reached, set full value, get the range then divide by 360 (or 270 in case of only 270 deg pot) and store, after that the display should only read 0-270 or 0-360.

For memories I need to have memories set by some menu scroll, roll down the memories then hit store, or go down the memories and hit go. This will be all the setup stuff.

Actual control will be via IR remote (10 mems 0-9 keys) and menu navigation using up/down/left/right then a select button for setting limits etc or run from PC application by commands received from USB serial.

It will be a lot of work for me, I do not have a developer background. The hardware is real easy, to be honest i could probably mop up the over current sense and so on into the soft world by using more ADC's but I do not want to complicate things too much yet.

I did thing of using the MIAC hardware but did not invetigate it more, the harwdare is still eveolving so it is just as easy for me to build it. You never know, I might go the graphical route instead, a nice graphic position reference would be real cool.

BR, John
Many thanks

John

Post Reply