PAJ27
I created this simple ladder code, simulates - but will not upload to Pico W I get this error.
 
Is this related to the PWM error too?
 
New uploading error.png
Reply 0 0
thiagoralves
%MW0 is a 16-bit location, but you're trying to put a 32-bit variable (DINT) in it. Also, Arduino boards don't support memory locations (%M)
Reply 0 0
PAJ27
Ok thanks- I modified it to now not to use %M, get this error
 
Is any body else using the Pico W with OpenPLC ?
 
AnaIn error uploading.png
Reply 0 0
PAJ27
This version also gave same error :
Again works with simulator
 
AnaIn error uploading v2.png
Reply 0 0
thiagoralves
%IW0 is a 16-bit location, but you're trying to put a 32-bit variable (DINT) in it.
Reply 0 0
PAJ27
So is the DIV expecting a 32-bit var ?
Reply 0 0
PAJ27
Is there a document somewhere describing the various blocks data type requirements ?
Reply 0 0
thiagoralves
DIV is any_num-any_num:
Untitled.png
 
It will take any numeric input as long as both inputs are of the same type.
 
The problem is not with DIV, but with you declaring a DINT, which is a 32-bit var type, on %IW0 which is a 16-bit location. They don't fit! For %IW0 you must use UINT, INT, or any other 16-bit variable type.
Reply 0 0
PAJ27
Hi
 
Ok - I  got this code to both build and upload to a Pico W.
 
It does not control the ouput led, it's on regardless of the Ain value. What is the actual analog range 0..4095   or  0..65535 ?
 
I've tried all the Ain pins (obviously adapting the code to suit). I have also tried them all as an Int type.
 
What else can I try ?
 
I'm trying develop a pico w system for use in one of my college classes - however I need to include at least the Analog inputs.
 
I hope you can help
 
Simple Analog in test.png
Reply 0 0
thiagoralves
Yes, the range should be 0-65535, which is the range for a full UINT. Your program seems correct, it should control the lamp based on the analog input value. You can use Modbus TCP and Radzio (which is a free Modbus utility that connects to Modbus devices and read/write their registers) to confirm the analog value and make sure the driver works. If analogs and PWM are not working then the Pico W driver must be revisited. If you have any knowledge on Arduino C code you can help making changes to it. The file is located at editor/arduino/src/hal folder on your OpenPLC Editor installation. Here is the original file on Github: https://github.com/thiagoralves/OpenPLC_Editor/blob/master/editor/arduino/src/hal/rp2040pico.cpp . It was written by a user in this forum.
 
You can make changes live in your own OpenPLC Editor copy and then compile your PLC project again. You can even keep the compilation window open while you make changes to the rp2040pico.cpp file. No need to reload the editor.
Reply 0 0
PAJ27
Ok - thanks, after some playing around with the *.cpp file - got some usable results, using these code mod's. Maybe of use to others
 
Terst plc code for Ana fixes.png
 
 
OpenPLC pico.cpp mods.png
Reply 0 0
thiagoralves
Nice work. Can you scale the analog inputs and PWM so that they fit in the standard OpenPLC scale of 0-65535?
Reply 0 0
Reply