EEPROM issue?

For Flowcode users to discuss projects, flowcharts, and any other issues related to Flowcode 5.
To post in this forum you must have a registered copy of Flowcode 5 or higher.

Moderator: Benj

Post Reply
GTF
Posts: 170
Joined: Sat Dec 10, 2011 7:21 pm
Location: Canada
Has thanked: 20 times
Been thanked: 52 times
Contact:

EEPROM issue?

Post by GTF »

Hi,
I'm using a 18F14K50 in a PWM position control application with a 0-5V analog sensor. I am writing the learned max, neutral and min values to EEPROM in a learn procedure. The values are read at startup and my routine loops until various variables go out range. The loop and hardware appears to function normally if I do not test for the position being within range. The problem is that when I do, the position values are always out of range on startup. Have I done something wrong here that could cause this? The attached abbreviated program behaves in the same manner in my application.

Thanks,

Grant
Attachments
EEPROM_Test.fcf
(18.28 KiB) Downloaded 249 times

User avatar
JonnyW
Posts: 1230
Joined: Fri Oct 29, 2010 9:13 am
Location: Matrix Multimedia Ltd
Has thanked: 63 times
Been thanked: 290 times
Contact:

Re: EEPROM issue?

Post by JonnyW »

Hello. I am not sure what values you are getting out, but your code:

Code: Select all

max_limit = learn_max + 10
min_limit = learn_min - 10
Might be the problem. Because these are byte values then if you have a reading below 10 or above 245 these will wrap (5 - 10 = 251). Try changing your limit values to signed integers and this may behave more correctly.

Cheers,

Jonny

GTF
Posts: 170
Joined: Sat Dec 10, 2011 7:21 pm
Location: Canada
Has thanked: 20 times
Been thanked: 52 times
Contact:

Re: EEPROM issue?

Post by GTF »

Hello Jonny,

I have tried simply using the learned values as the limits as well as the signed integers. The result is the same. I have 2 separate sensors in the application and the same thing is happening with both of them. At times it has been OK in the forward direction(decreasing V), but a little into reverse(increasing V) the loop is ended. My meter shows that I am far from the limit. Min is 0.63V Max is 4.45V Neutral is 3.53V (asymmetrical)

Grant

edit: added info re sensor output vs direction- full forward is 4.45V, full reverse is 0.63V, VDD is 4.88V

User avatar
JonnyW
Posts: 1230
Joined: Fri Oct 29, 2010 9:13 am
Location: Matrix Multimedia Ltd
Has thanked: 63 times
Been thanked: 290 times
Contact:

Re: EEPROM issue?

Post by JonnyW »

Hello. I have just re-read your code. Did you mean for the code:

Code: Select all

  loop
    A = ADC()
  while A > min_limit AND A < max_limit
As this will wait until 'A' is outside the range. To wait until it is inside the range, use:

Code: Select all

  loop
    A = ADC()
  while A < min_limit AND A > max_limit
I would also bracket your inequalities and use && rather than AND:

Code: Select all

  loop
    A = ADC()
  while (A < min_limit) && (A > max_limit)
Cheers,

Jonny

GTF
Posts: 170
Joined: Sat Dec 10, 2011 7:21 pm
Location: Canada
Has thanked: 20 times
Been thanked: 52 times
Contact:

Re: EEPROM issue?

Post by GTF »

The loop is to end when A is outside the limits, so that code appears to be correct. I have tried brackets/no brackets before. My actual code has brackets. The signed integers may have helped get this example working on my hardware. I also had to initially increase the max_limit by 50 over the learned_max, but was then able to drop it back down to 10 with it still working??

Looks like it is going to take some more effort though to get this to work in my actual code. At least the loop now runs until I get into the reverse direction (moving toward learned_max).

Thanks.

Post Reply