Issues with reading Analog Inputs & EESAVE

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

Moderator: Benj

Post Reply
Steven_SS
Posts: 46
Joined: Wed Jul 18, 2018 6:33 pm
Has thanked: 18 times
Been thanked: 3 times
Contact:

Issues with reading Analog Inputs & EESAVE

Post by Steven_SS »

Hello,
I am having difficulty reading analog inputs from an ATMEGA2560. In the Flowcode project I've attached, I have two methods of going at it, 1-by utilizing the Modbus slave component "ReadAnalogueInput" and 2-through cal_adc enable/sample/disable. When I test AI0, nothing shows up.
Can someone spot out a mistake if there's one in the program on how I'm attempting to read the AI's please? I think it might be something with how im sampling the cal_adc but i'm not sure.

And the other issue is trying to get the EEPROM functioning properly once I input new values into registers, and re-run it, those new values will appear for the registers instead of grabbing the default values from the LUT. But it keeps grabbing the LUT values instead of the newly inputted values from the eeprom.
I thought it'd be a fuse setting error, where eesave was not programmed, and I was right. So I edited the hi fuse register to turn on eesave setting my fuses as- low: 0xFF, hi: 0x90, ext: 0xFC. My hardware has sufficient power, but still no luck... Again, maybe it's something in the program?

Note: ADC input channels 0-3 are on port pin PF0-PF3, channel 0-3.

Thanks
Attachments
AI_EEPROM.fcfx
(65 KiB) Downloaded 178 times
I'm just trying to keep learning & growing in a infinite loop... unless I wanna break. Cheers :)
Steven

viktor_au
Posts: 342
Joined: Fri Jan 26, 2018 12:30 pm
Location: South Australia
Has thanked: 43 times
Been thanked: 60 times
Contact:

Re: Issues with reading Analog Inputs & EESAVE

Post by viktor_au »

Hello Steven_SS

I have only Ard(uino) licence and I couldn't compile your project.

One question.

Menu->Project options->Clock speed (Hz) = 14745600.
What is the reason you have chosen this clock speed?

Steven_SS
Posts: 46
Joined: Wed Jul 18, 2018 6:33 pm
Has thanked: 18 times
Been thanked: 3 times
Contact:

Re: Issues with reading Analog Inputs & EESAVE

Post by Steven_SS »

viktor_au wrote: What is the reason you have chosen this clock speed?
Hey Viktor!
I'm not entirely sure, we first had it at 16000000 Hz but then we were just recommended to change that setting to 14745600 Hz.
I managed to get the ADC working correctly! I was using the incorrect ADC component in flowcode.

However, I still cannot get the EEPROM to save changes, as well as cannot have the LUT set values larger than 255(i.e. 1024).
In the program, the LUT storage type is set to 16 bit and in it contains the values 1024. If I run a simulation LCD in the dashboard panel it will print out the correct values(1024) but once I set up the hardware and set up the Modbus master the registers show the values in the LUT as 255 instead of 1024 :x (the registers are INT type so it is capable of holding that value)
I'm just trying to keep learning & growing in a infinite loop... unless I wanna break. Cheers :)
Steven

viktor_au
Posts: 342
Joined: Fri Jan 26, 2018 12:30 pm
Location: South Australia
Has thanked: 43 times
Been thanked: 60 times
Contact:

Re: Issues with reading Analog Inputs & EESAVE

Post by viktor_au »

...and set up the Modbus master

Can I ask you Steven_SS,

Do you have any problems between the Modbus Master and Slave N1 on Mega2560?

I am not sure if it is important, but at Init stage I do the next:
I use the function: SetSlaveAddress(1) // if Slave ID = 1
I checked. I think we use this function only if we have to change/override the slave ID.
In the macro Comms you do it at the end of macro.
Should we do it only once by using the Modbus Slave properties->Slave address (1) ?

Local and global variables

In the Main loop you call the macro EEPROM_Read were you do assign the .Return to global variable RetVal.
However in Decision you do not check this value,
Instead you check the local variable .retVal = .SUCCESS

You have 2 variables with the same name: RetVal, .RetVal.
One is global and one is local.
The local one you write as .retVal or .RetVal.
I am not sure if it is a good practice.

PS
When I tried to run the program with Ard Mega2560 board, I noticed the warning:
Uninitialised variable: RetVal
Attachments
Uninit_variableRetVal.jpg
Uninit_variableRetVal.jpg (17.42 KiB) Viewed 3824 times
RetVal.jpg
RetVal.jpg (27.53 KiB) Viewed 3827 times
ModbusSlaveSetAddress-1.jpg
ModbusSlaveSetAddress-1.jpg (23.89 KiB) Viewed 3828 times
Last edited by viktor_au on Sat Mar 23, 2019 7:31 am, edited 1 time in total.

viktor_au
Posts: 342
Joined: Fri Jan 26, 2018 12:30 pm
Location: South Australia
Has thanked: 43 times
Been thanked: 60 times
Contact:

Re: Issues with reading Analog Inputs & EESAVE

Post by viktor_au »

I noticed the same problem in the next:
Modbus slave checks the Master request and save it as local variable .status.
If .status = 1 (success) you assign this value as: .Return = .status
.Return is assigned to global variable RetVal (I am not sure why do you use RetVal again)
The Switch however uses the local variable .retVal.
Attachments
SlaveCheckRequest.jpg
SlaveCheckRequest.jpg (42.74 KiB) Viewed 3815 times

Steven_SS
Posts: 46
Joined: Wed Jul 18, 2018 6:33 pm
Has thanked: 18 times
Been thanked: 3 times
Contact:

Re: Issues with reading Analog Inputs & EESAVE

Post by Steven_SS »

viktor_au wrote: Do you have any problems between the Modbus Master and Slave N1 on Mega2560?
I'm not sure I understand the question Viktor... what do you mean when you say "N1"?

That is strange how I had that global/local variable of return val. I altered that decision statement where it looks at the global RetVal now, thanks for picking that out! I solved the EEPROM issue. It was within the EEPROM_Write module where I zeroed out the reserved bytes, the simple numbering for that loop was off. Fixed those ranges and the EEPROM/EESAVE worked well.

Now: When reading Analog input 0(AI0), say as an example I get the raw count to be about 512. The register in the Modbus client will show that but the registers that show the other Analog inputs raw count are very close to that as well when those should be 0 or 900s but they seem dependent on the AI0. The way I'm reading the AI'S are the same as in the fcfx from the first post.
They should all be independent from one another!! But aren't at the moment :/
I'm just trying to keep learning & growing in a infinite loop... unless I wanna break. Cheers :)
Steven

viktor_au
Posts: 342
Joined: Fri Jan 26, 2018 12:30 pm
Location: South Australia
Has thanked: 43 times
Been thanked: 60 times
Contact:

Re: Issues with reading Analog Inputs & EESAVE

Post by viktor_au »

Hello Steven

Slave N1 means that you have slave number one.

Steven_SS
Posts: 46
Joined: Wed Jul 18, 2018 6:33 pm
Has thanked: 18 times
Been thanked: 3 times
Contact:

Re: Issues with reading Analog Inputs & EESAVE

Post by Steven_SS »

viktor_au wrote:Slave N1 means that you have slave number one.
Oh gotcha, no I do not have problems between them two. At least not yet haha
I'm just trying to keep learning & growing in a infinite loop... unless I wanna break. Cheers :)
Steven

Post Reply