Please select To the mobile version | Continue to access the desktop computer version

OrangePi

 Login            
 Register            
Search
Hot search: orangepi
12Next
Return to list New
View: 14360|Reply: 11

PWM (hard) orange pi PC (H3) example blinky OK

[Copy link]

12

Threads

30

Posts

150

Credits

Registered member

Rank: 2

Credits
150
Post time 2016-2-18 22:20:14 | Show all posts |Read mode
I was looking into hardware pwm and thought I could use the sunxi_pwm module,
I had a look in the H3 manual, and I think only port PA5 is usable (serial boot connector middle pin)
I had no luck executing the sunxi_pwm module (filesystem with PWM0 is not created).
The fex file does not set the port correctly to pwm nor the pwm register.
WiringOP is not configured correctly for PWM (yet)

But you can always set the ports manually ;)
(p 317 H3 manual  011 PWM0 dataregister for port PA5)

in the H3 manual P.188 the state that the control register for PWM is at 0x01C21400 (here you can set the frequency with prescalers for 24Mhz)
At an offset of 0x04 you can find the control register for the period (duty cycle --upper 16bit is number of cycles -- lower 16bit is number of active cycles -- upper has to be greater or equal)
in the manual they only refer to channel 0...

I attached an example with comment, which blinks a LED attached to port PA05. You can play with it by modifying the code (see comment)




This post contains more resources

You have to Login for download or view attachment(s). No Account? Register

x

1

Threads

7

Posts

41

Credits

Novice

Rank: 1

Credits
41
Post time 2016-3-25 19:57:49 | Show all posts
I've check your code and PWM0 is working. I also tried to run PWM1 (I've changed information about register in code to PA6) but it didn't worked. So only one hadrware PWM is available on OP?

0

Threads

13

Posts

136

Credits

Registered member

Rank: 2

Credits
136
Post time 2016-2-21 19:20:21 | Show all posts
let me try
Reply

Use magic Report

1

Threads

15

Posts

103

Credits

Registered member

Rank: 2

Credits
103
Post time 2016-3-25 21:34:00 | Show all posts
@osator
Yes. You can read about this in  H3 datasheet v1.1
SoC H3 has only one port PWM

1

Threads

2

Posts

35

Credits

Novice

Rank: 1

Credits
35
Post time 2016-5-24 20:15:34 | Show all posts
Is there a way to use WiringPi with PWM on the OPC?

0

Threads

3

Posts

58

Credits

Registered member

Rank: 2

Credits
58
Post time 2016-5-27 17:44:25 | Show all posts
Please let me say,

How do you calculate your desired frequency?

You said that comment in your code,

        //data = (0x6EEE00EE);     //control register 987 hz (no prescaler)
        //  data = (0x000E0006);   //control register 1.6 Mhz max
        //   data = (0x00020001);  //control register 8 Mhz max

Your desired frequency is 987 hz and you calculate data value (0x6EEE00EE)

How do you calculate it?

Thanks...








0

Threads

3

Posts

58

Credits

Registered member

Rank: 2

Credits
58
Post time 2016-5-27 17:49:08 | Show all posts
And I want to control the brushless motor with esc. How do I control it? Is there any c codes?

Please advice me, Thanks....

0

Threads

1

Posts

14

Credits

Novice

Rank: 1

Credits
14
Post time 2016-6-24 14:43:46 | Show all posts
StaLeWaR29 replied at 2016-3-25 21:34
@osator
Yes. You can read about this in  H3 datasheet v1.1
SoC H3 has only one port PWM

Some findings to pass on:

WiringOP does not appear to have working PWM support at this time. I tested both the gpio app and the lib (via the pwm example program) and neither work due to missing H3 pin/mode configuration.

On my Orange PI PC, the GPIO PA5 PWM0 is accessible via the middle pin of the UART header. I could not get PWM0 or PWM1 working via the 40-pin header.

The Orange Pi header documentation and the OPI-PC schematics indicate that header pin 7 is H3 GPIO PA6 with PWM1 available on MUX 3, but the H3 datasheet v1.2 does not show PWM1 available on GPIO PA6, and setting PA6 to func 3 did not result in a PWM signal on pin 7.

The PWM0 function only appears to be available on the UART header (GPIO PA5: PWM0). The H3 datasheet shows the PWM function is also available on PL10, but the OPI-PC uses that pin for the power LED.


As to performance, I am evaluating the Orange Pi boards vs the Raspberry Pi 3 for GPIO at 1MHz+ speeds.

Here are my findings using C/assembly:

RPI3
===
~7.5ns : Set or clear up to 28 GPIO pins on 40-pin header. Setting some pins & clearing others takes 2x GPIO writes.
~52ns : Read the level of 28 GPIO pins on 40-pin header.

The RPI3 can bit-bang output to the GPIO at about 66MHz (using 2x GPIO writes to set and clear lines).
Reading is considerably slower at 19.2MHz.



Orange Pi PC (Armbian 5.14 Jessie 3.4.112 desktop)
========
~50ns: Set the level of all GPIO pins <on one port>.
~120ns: Read the level of all GPIO pins <on one port>.

The OPI-PC can bit-bang output to the GPIO at about 20MHz.
Reading is considerably slower at ~8MHz.



Because the OPI-PC uses GPIO from H3 ports A,C,D,G on the 40-pin header, it is very slow to read (4x 120ns) or write (4x 50ns) all 28 GPIO pins on the 40-pin header, and it is not possible to change them simultaneously.

-JB
twitter: @JBrooksBSI

4

Threads

6

Posts

49

Credits

Novice

Rank: 1

Credits
49
Post time 2016-11-27 15:37:09 | Show all posts
osator replied at 2016-3-25 19:57
I've check your code and PWM0 is working. I also tried to run PWM1 (I've changed information about r ...

Can you please help me to run this code on my orangepi zero i am new on that devices.i dont know how to change the pin and how can i control pwm ?

0

Threads

3

Posts

36

Credits

Novice

Rank: 1

Credits
36
Post time 2016-12-7 20:50:39 | Show all posts
I'm desperate in running MG996R SERVO . Can somebody help? Could you use this code to trigger this servo? I suck at coding so little example of forward and reverse would be extremely nice.
12Next
Return to list New
You have to log in before you can reply Login | Register

Points Rules

Archiver|Mobile edition|Darkroom|OrangePi En ( 粤ICP备14086627号-2

2019-9-19 18:23 GMT+8 , Processed in 0.039352 second(s), 24 queries .

Powered by Discuz! X3.2

© 2014-2015 orangepibbs en.

Quick Reply To Top Return to the list