
very simple 4ch PWM output demo for "mbed LPC824"
Information
Program sample for https://twitter.com/nxpfan/status/545030103462203392
main.cpp@0:a7f40d4e5c58, 2014-12-17 (annotated)
- Committer:
- nxpfan
- Date:
- Wed Dec 17 01:32:34 2014 +0000
- Revision:
- 0:a7f40d4e5c58
4ch PWM output demo
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
nxpfan | 0:a7f40d4e5c58 | 1 | #include "mbed.h" |
nxpfan | 0:a7f40d4e5c58 | 2 | |
nxpfan | 0:a7f40d4e5c58 | 3 | #define PI 3.14159265 |
nxpfan | 0:a7f40d4e5c58 | 4 | |
nxpfan | 0:a7f40d4e5c58 | 5 | PwmOut pwm[] = { |
nxpfan | 0:a7f40d4e5c58 | 6 | PwmOut( dp6 ), |
nxpfan | 0:a7f40d4e5c58 | 7 | PwmOut( dp7 ), |
nxpfan | 0:a7f40d4e5c58 | 8 | PwmOut( dp8 ), |
nxpfan | 0:a7f40d4e5c58 | 9 | PwmOut( dp9 ), |
nxpfan | 0:a7f40d4e5c58 | 10 | }; |
nxpfan | 0:a7f40d4e5c58 | 11 | |
nxpfan | 0:a7f40d4e5c58 | 12 | int main() |
nxpfan | 0:a7f40d4e5c58 | 13 | { |
nxpfan | 0:a7f40d4e5c58 | 14 | int count = 0; |
nxpfan | 0:a7f40d4e5c58 | 15 | float t = PI / 40.0; |
nxpfan | 0:a7f40d4e5c58 | 16 | |
nxpfan | 0:a7f40d4e5c58 | 17 | while(1) { |
nxpfan | 0:a7f40d4e5c58 | 18 | for ( int i = 0; i < 4; i++ ) { |
nxpfan | 0:a7f40d4e5c58 | 19 | pwm[ 0 ] = powf( sin( t * (float)(count + 0) ), 2.0 ); |
nxpfan | 0:a7f40d4e5c58 | 20 | pwm[ 1 ] = powf( sin( t * (float)(count + 5) ), 2.0 ); |
nxpfan | 0:a7f40d4e5c58 | 21 | pwm[ 2 ] = powf( sin( t * (float)(count + 10) ), 2.0 ); |
nxpfan | 0:a7f40d4e5c58 | 22 | pwm[ 3 ] = powf( sin( t * (float)(count + 15) ), 2.0 ); |
nxpfan | 0:a7f40d4e5c58 | 23 | } |
nxpfan | 0:a7f40d4e5c58 | 24 | wait_ms( 20 ); |
nxpfan | 0:a7f40d4e5c58 | 25 | count++; |
nxpfan | 0:a7f40d4e5c58 | 26 | } |
nxpfan | 0:a7f40d4e5c58 | 27 | } |
nxpfan | 0:a7f40d4e5c58 | 28 |