libpruio  0.6.8
Fast and easy Digital/Analog Input/Output for Beaglebones
pwm_cap.bas
Go to the documentation of this file.
1 
18 
19 ' include libpruio
20 #INCLUDE ONCE "BBB/pruio.bi"
21 ' include the convenience macros for header pins
22 #INCLUDE ONCE "BBB/pruio_pins.bi"
23 
24 
25 #DEFINE P_OUT P9_21
26 
27 #DEFINE P_IN P9_42
28 
29 VAR io = NEW PruIo
30 
31 WITH *io
32  DO
33  IF .Errr THEN ?"NEW failed: " & *.Errr : EXIT DO
34 
35  IF .Cap->config(P_IN, 2.) THEN _ ' configure input pin
36  ?"failed setting input @P_IN (" & *.Errr & ")" : EXIT DO
37 
38  DIM AS Float_t _
39  f1 _
40  , d1 _
41  , f0 = 31250 _
42  , d0 = .5
43  IF .Pwm->setValue(P_OUT, f0, d0) THEN _
44  ?"failed setting output @P_OUT (" & *.Errr & ")" : EXIT DO
45 
46  IF .config(1, 2) THEN _ ' upload configuration to PRU
47  ?"config failed: " & *.Errr : EXIT DO
48 
49  ?!"\n--> " & LEFT("Frequency: " & f0 & SPACE(10), 20) _
50  & LEFT(", Duty: " & d0 & SPACE(10), 20) ' initial info
51  WHILE 1
52  VAR k = ASC(INKEY())
53  IF k THEN
54  SELECT CASE AS CONST k ' react on user keystrokes
55  CASE ASC("0") : d0 = 0.0
56  CASE ASC("1") : d0 = 0.1
57  CASE ASC("2") : d0 = 0.2
58  CASE ASC("3") : d0 = 0.3
59  CASE ASC("4") : d0 = 0.4
60  CASE ASC("5") : d0 = 0.5
61  CASE ASC("6") : d0 = 0.6
62  CASE ASC("7") : d0 = 0.7
63  CASE ASC("8") : d0 = 0.8
64  CASE ASC("9") : d0 = 0.9
65  CASE ASC(","), ASC(".") : d0 = 1.0
66  CASE ASC("*") : f0 = IIF(f0 < 500000., f0 * 2 , 1000000.)
67  CASE ASC("/") : f0 = IIF(f0 > 1. , f0 / 2 , .5)
68  CASE ASC("m") : f0 = IIF(f0 > 5.5 , f0 - 5., .5)
69  CASE ASC("p") : f0 = IIF(f0 < 999995., f0 + 5., 1000000.)
70  CASE ASC("+") : f0 = 1000000.
71  CASE ASC("-") : f0 = .5
72  CASE ELSE : EXIT WHILE ' finish
73  END SELECT
74 
75  IF .Pwm->setValue(P_OUT, f0, d0) THEN _ ' set new output
76  ?"failed setting PWM output (" & *.Errr & ")" : EXIT WHILE
77 
78  ?!"\n--> " & LEFT("Frequency: " & f0 & SPACE(10), 20) _
79  & LEFT(", Duty: " & d0 & SPACE(10), 20) ' user info
80  END IF
81 
82  IF .Cap->Value(P_IN, @f1, @d1) THEN _ ' get current input
83  ?"failed reading input @P_IN (" & *.Errr & ")" : EXIT WHILE
84 
85  ?!"\r " & LEFT("Frequency: " & f1 & SPACE(10), 20) _
86  & LEFT(", Duty: " & d1 & SPACE(10), 20); ' user info
87  SLEEP 1
88  WEND : ?
89  LOOP UNTIL 1
90 END WITH
91 
92 DELETE(io)
93 
94 '' help Doxygen to document the main code
95 '&/** The main function. */
96 '&int main() {PruIo::PruIo(); CapMod::config(); PruIo::config(); CapMod::Value(); PwmMod::setValue(); PruIo::~PruIo();}
97