View: 34955|Reply: 13

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

[Copy link]

12

threads

30

posts

150

credits

Registered member

Rank: 2

credits
150
Published in 2016-2-18 22:20:14 | Show all floors |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 thread contains more resources

You need to Log in to download or view,No account?    Register

x

1

threads

2

posts

37

credits

Novice

Rank: 1

credits
37
Published in 2016-5-24 20:15:34 | Show all floors
Is there a way to use WiringPi with PWM on the OPC?

1

threads

7

posts

41

credits

Novice

Rank: 1

credits
41
Published in 2016-3-25 19:57:49 | Show all floors
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
Published in 2016-2-21 19:20:21 | Show all floors
let me try
Reply

Use magic report

1

threads

15

posts

103

credits

Registered member

Rank: 2

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

0

threads

3

posts

58

credits

Registered member

Rank: 2

credits
58
Published in 2016-5-27 17:44:25 | Show all floors
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
Published in 2016-5-27 17:49:08 | Show all floors
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
Published in 2016-6-24 14:43:46 | Show all floors
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
Published in 2016-11-27 15:37:09 | Show all floors
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
Published in 2016-12-7 20:50:39 | Show all floors
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.
You need to log in before you can reply login | Register

Points Rule

Quick reply Top Return list