Engmarcio
Bom dia.
 
Existe algum bloco pwm no open plc?
 
poderiam me ajudar.
 
preciso gerar 400 pulsos a partir de uma sw1 - digital imput
Reply 0 0
gfine
The Arduino Uno only has 3 PWM channels, that are available on pins 9,10 and 11
 
The Arduino Uno only has 3 PWM channels, that are available on pins 9,10 and 11
It has been awhile since I wrote this post. I believe that for this PWM instruction to reference the PWM at pin 10 the top line of the PWM instruction has to equal 1 ( C1 = 1) which is Channel 1 on pin 10. If you wanted to reference Channel 0 on pin 9 you would set C1 to 0 and if you wanted to reference Channel 2 on pin 11 you would set C1 to 2.
Reply 0 0
Dzahien
It has been awhile since I wrote this post. I believe that for this PWM instruction to reference the PWM at pin 10 the top line of the PWM instruction has to equal 1 ( C1 = 1) which is Channel 1 on pin 10. If you wanted to reference Channel 0 on pin 9 you would set C1 to 0 and if you wanted to reference Channel 2 on pin 11 you would set C1 to 2.
right, but what if you're using an Arduino Mega? How does the pin addressing work and where can I get this information in details?
Reply 0 0
thiagoralves
Unfortunately there isn’t much documentation about this block. But you can get the pin mapping from the driver code directly. Here is the Mega for instance: https://github.com/thiagoralves/editor/blob/8dda209252d6bdf6ddfcc0d2214e50d58c75785e/arduino/src/hal/mega_due.cpp#L47
 
Reply 0 0
Dzahien
Unfortunately there isn’t much documentation about this block. But you can get the pin mapping from the driver code directly. Here is the Mega for instance: https://github.com/thiagoralves/editor/blob/8dda209252d6bdf6ddfcc0d2214e50d58c75785e/arduino/src/hal/mega_due.cpp#L47
 
Once again, thank you, Thiago.
 
For future reference of people in this forum who were confused as I was;
 
Here are some references for this specific topic. Hope this helps as much as it did to me.
Reply 0 0
Dzahien
Once again, thank you, Thiago.
 
For future reference of people in this forum who were confused as I was;
 
Here are some references for this specific topic. Hope this helps as much as it did to me.
Here you go
Reply 1 0
Dzahien
Sorry there's a bit of confusion here,
 
Why are these two mappings different from the code and documentation?
[203128%2F9342846%2Fmceclip0]
[203128%2F9342848%2Fmceclip0]
Reply 0 0
gfine
right, but what if you're using an Arduino Mega? How does the pin addressing work and where can I get this information in details?
I have not used the Mega, but assume that the C=0,1,2, still corresponds to Channels 0,1,2,3, but you wire to the corresponding pin for the Mega instead of the Uno. If there are more channels it would follow that C =3,4,5,6... etc. If you try this please let us know.
Reply 0 0
thiagoralves
Sorry there's a bit of confusion here,
 
Why are these two mappings different from the code and documentation?
[203128%2F9342846%2Fmceclip0]
[203128%2F9342848%2Fmceclip0]
The current version of the editor has a dynamic mapping - the user can define whatever mapping is needed on the upload dialog under I/O Config. So this is more of a suggestion and defaults than something set on stone
Reply 0 0
Dzahien
I have not used the Mega, but assume that the C=0,1,2, still corresponds to Channels 0,1,2,3, but you wire to the corresponding pin for the Mega instead of the Uno. If there are more channels it would follow that C =3,4,5,6... etc. If you try this please let us know.
Hi Gfine, apologies for asking multiple questions for clarity and thank you for replying them.
 
I have a new query regarding your PWM mapping:
[203128%2F9344692%2Fmceclip0]
 
The S1 coil is addressed to a Boolean output, but the C1 is an analog output? Which one should I connect my physical signal to the servo?
 
In other words, which output C1 or S1 should I connect my PWM pin to my physical servo?
 
Thank you again.
Reply 0 0
thiagoralves
S1 is connected to the SUCCESS output pin of the PWM_CONTROLLER block, so it only informs you if the block succeeded or not in enabling the hardware PWM. This is NOT the PWM signal, just a boolean true/false telling you if it worked or not. I don't know what you've defined your C1 variable to be, but that in essence is the pin where the PWM signal will be enabled at, according to our discussion above. The pins are tied to PWM channels, and each platform has a channels mapped to different pins. These are hardware mappings (i.e. the silicon vendor defines them). In case of the Arduino Mega, that uses a ATMEGA2560 chip, PWM channel 0 is mapped to Arduino pin 2, channel 1 is mapped to Arduino pin 3, and so on as defined here: https://github.com/thiagoralves/editor/blob/8dda209252d6bdf6ddfcc0d2214e50d58c75785e/arduino/src/hal/mega_due.cpp#L47
 
So, in summary, if you connect the value 0 to CHANNEL input of your PWM_CONTROLLER block (or in your diagram, if your variable C1 = 0), then the PWM signal will be available on Arduino pin 2 of the Arduino Mega.
Reply 0 0
Dzahien
Dear Dr. @thiagoralves,
 
I do understand your explanation until that point.
 
The reason for my confusion is attached within my reply.
 
Even when I think the setup is correct, I am still unable to get an output from the PWM pins as shown from the RMMS modbus simulator.
 
Am I missing something here?
 
Thank you in advanced.
Reply 0 0
thiagoralves
You won’t be able to see the PWM value from Modbus because it is being generated in hardware. You’re simply reading holding registers that have nothing to do with the PWM generation. What you can do is place your FREQ and DUTY variables in a located area with Modbus access so you can see those values over Modbus
Reply 0 0
Dzahien
You won’t be able to see the PWM value from Modbus because it is being generated in hardware. You’re simply reading holding registers that have nothing to do with the PWM generation. What you can do is place your FREQ and DUTY variables in a located area with Modbus access so you can see those values over Modbus
Unfortunately, even on my physical servo, there seems to be no output.
 
This is how I would set up my wiring.
 
Please advise. Thank you
Reply 0 0
Dzahien
Unfortunately, even on my physical servo, there seems to be no output.
 
This is how I would set up my wiring.
 
Please advise. Thank you
Anybody who has any insights on this are very much welcome to participate. Thanks!
Reply 0 0
gfine
Anybody who has any insights on this are very much welcome to participate. Thanks!
I am not sure about the Modbus, but if you go according to my original post and looking at this Mega board it appears pin 2 is Channel 0, so that the C1 value in my example would be 0. If you have C1 =1 then you should be on pin 3.
Reply 0 0
Reply