-
Notifications
You must be signed in to change notification settings - Fork 199
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
0c11e15
commit 6b9664b
Showing
7 changed files
with
842 additions
and
119 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
2.51 | ||
2.52 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,44 +1,128 @@ | ||
/* | ||
* pwm.c: | ||
* This tests the hardware PWM channel. | ||
* | ||
* Copyright (c) 2012-2013 Gordon Henderson. <[email protected]> | ||
*********************************************************************** | ||
* This file is part of wiringPi: | ||
* https://projects.drogon.net/raspberry-pi/wiringpi/ | ||
* | ||
* wiringPi is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU Lesser General Public License as published by | ||
* the Free Software Foundation, either version 3 of the License, or | ||
* (at your option) any later version. | ||
* | ||
* wiringPi is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU Lesser General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU Lesser General Public License | ||
* along with wiringPi. If not, see <http://www.gnu.org/licenses/>. | ||
*********************************************************************** | ||
*/ | ||
|
||
#include <wiringPi.h> | ||
|
||
#include<wiringPi.h> | ||
#include <stdio.h> | ||
#include <stdlib.h> | ||
#include <stdint.h> | ||
|
||
#define PWM_PIN 29 | ||
|
||
int main (void) | ||
int main(int argc, char *argv []) | ||
{ | ||
printf ("OrangePi Pi wiringPi PWM test program\n") ; | ||
int i = 0; | ||
int val = 0; | ||
int pin= 0; | ||
|
||
if (argc != 2) { | ||
fprintf (stderr, "Usage: %s <pin>\n", argv [0]) ; | ||
exit (1) ; | ||
} | ||
|
||
pin = (unsigned int)strtoul (argv [1], NULL, 10) ; | ||
|
||
if (pin != 3 && pin != 4 && pin != 21 && pin != 22) { | ||
fprintf (stderr, "pin 3 for PWM2 / pin 4 for PWM1 / pin 21 for PWM3 / pin 22 for PWM4\n") ; | ||
exit (1) ; | ||
} | ||
|
||
// 初始化 | ||
printf("wiringPiSetup start\n"); | ||
|
||
wiringPiSetup(); | ||
pinMode(pin,PWM_OUTPUT); | ||
|
||
printf("wiringPiSetup end\n"); | ||
|
||
// 开始测试 | ||
while(1) | ||
{ | ||
pwmSetRange(pin,1024); | ||
pwmSetClock(pin,1); | ||
pwmWrite(pin,512); | ||
|
||
//1. 调节PWM占空比 | ||
//1.1 通过设置ARR调节PWM占空比 | ||
printf("Modified ARR test start\n"); | ||
|
||
for (i = 0 ; i <= 8 ; i++) { | ||
pwmSetRange(pin,1024+i*128); | ||
delay(500); | ||
} | ||
|
||
delay(5000); | ||
|
||
for (i = 7 ; i >= 0 ; i-- ) { | ||
pwmSetRange(pin,1024+i*128); | ||
delay(500); | ||
} | ||
|
||
delay(5000); | ||
|
||
printf("Modified ARR test end\n"); | ||
|
||
pwmSetMode(pin,PWM_MODE_BAL); | ||
delay(5000); | ||
pwmSetMode(pin,PWM_MODE_MS); | ||
|
||
//1.2 通过设置CRR调节PWM占空比 | ||
printf("Modified CRR test start\n"); | ||
|
||
for (i = 0 ; i <= 8 ; i++) { | ||
pwmWrite(pin,512 + i*64); | ||
delay(500); | ||
} | ||
|
||
delay(5000); | ||
|
||
for (i = 7 ; i >= 0 ; i-- ) { | ||
pwmWrite(pin,512 + i*64); | ||
delay(500); | ||
} | ||
|
||
delay(5000); | ||
|
||
printf("Modified active range test end\n"); | ||
|
||
pwmSetMode(pin,PWM_MODE_BAL); | ||
delay(5000); | ||
pwmSetMode(pin,PWM_MODE_MS); | ||
|
||
//2.调节PWM频率 | ||
//2.1通过设置分频系数调节PWM频率 | ||
|
||
printf("Modified frequency division test start\n"); | ||
|
||
for (i = 1 ; i <= 10; i++) { | ||
pwmSetClock(pin,i); | ||
delay(500); | ||
} | ||
|
||
delay(5000); | ||
|
||
for (i = 9 ; i >= 1 ; i--) { | ||
pwmSetClock(pin,i); | ||
delay(500); | ||
} | ||
|
||
delay(5000); | ||
|
||
printf("Modified frequency division test end\n"); | ||
|
||
pwmSetMode(pin,PWM_MODE_BAL); | ||
delay(5000); | ||
pwmSetMode(pin,PWM_MODE_MS); | ||
|
||
//2.2 直接设置PWM频率 | ||
printf("Modified PWM frequency test start\n"); | ||
|
||
for (i = 1 ; i <= 10; i++) { | ||
pwmToneWrite(pin,2000*i); | ||
delay(2000); | ||
} | ||
|
||
if (wiringPiSetup () == -1) | ||
exit (1) ; | ||
delay(5000); | ||
|
||
pinMode (PWM_PIN, PWM_OUTPUT) ; | ||
pwmWrite (PWM_PIN, 500) ; | ||
printf("Modified PWM frequency test end\n"); | ||
|
||
return 0 ; | ||
pwmSetMode(pin,PWM_MODE_BAL); | ||
delay(5000); | ||
pwmSetMode(pin,PWM_MODE_MS); | ||
} | ||
return 0; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.