summaryrefslogtreecommitdiff
path: root/macros/Hardware/RasberryPi/pwm
diff options
context:
space:
mode:
Diffstat (limited to 'macros/Hardware/RasberryPi/pwm')
-rwxr-xr-xmacros/Hardware/RasberryPi/pwm/RPI_pwmClock.sci40
-rwxr-xr-xmacros/Hardware/RasberryPi/pwm/RPI_pwmMode.sci46
-rwxr-xr-xmacros/Hardware/RasberryPi/pwm/RPI_pwmRange.sci40
-rwxr-xr-xmacros/Hardware/RasberryPi/pwm/RPI_pwmToneWrite.sci41
-rwxr-xr-xmacros/Hardware/RasberryPi/pwm/RPI_pwmWrite.sci45
-rwxr-xr-xmacros/Hardware/RasberryPi/pwm/buildmacros.sce14
-rwxr-xr-xmacros/Hardware/RasberryPi/pwm/names5
7 files changed, 231 insertions, 0 deletions
diff --git a/macros/Hardware/RasberryPi/pwm/RPI_pwmClock.sci b/macros/Hardware/RasberryPi/pwm/RPI_pwmClock.sci
new file mode 100755
index 0000000..d065353
--- /dev/null
+++ b/macros/Hardware/RasberryPi/pwm/RPI_pwmClock.sci
@@ -0,0 +1,40 @@
+// Copyright (C) 2017 - IIT Bombay - FOSSEE
+//
+// This file must be used under the terms of the CeCILL.
+// This source file is licensed as described in the file COPYING, which
+// you should have received as part of this distribution. The terms
+// are also available at
+// http://www.cecill.info/licences/Licence_CeCILL_V2-en.txt
+// Organization: FOSSEE, IIT Bombay
+// Email: toolbox@scilab.in
+
+function RPI_pwmClock(value)
+// Function to set the divisor for the PWM clock.
+//
+// Calling Sequence
+// RPI_pwmClock(value)
+//
+// Parameters
+// value: The divisor for the PWM clock.
+//
+// Description
+// This function sets the divisor for the PWM clock.
+//
+// Examples
+// RPI_pwmClock(100)
+// See also
+// RPI_pwmMode, RPI_pwmRange, RPI_pwmToneWrite, RPI_pwmWrite
+//
+// Authors
+// Jorawar Singh
+//
+// Bibliography
+// http://wiringpi.com/reference/
+
+ commande="pwC#1#"+string(value)+"#";
+ if getos=="Linux" then
+ unix_w("python -c ""import socket;s=socket.socket();s.connect((''"+RPI_piAdress+"'',9077));s.send(''"+commande+"'');print(s.recv(1024));s.close()""");
+ elseif getos=="Windows" then
+ RPI_winR=dos("python -c ""import socket;s=socket.socket();s.connect((''"+RPI_piAdress+"'',9077));s.send(''"+commande+"'');print(s.recv(1024));s.close()""");
+ end
+endfunction
diff --git a/macros/Hardware/RasberryPi/pwm/RPI_pwmMode.sci b/macros/Hardware/RasberryPi/pwm/RPI_pwmMode.sci
new file mode 100755
index 0000000..13d0c36
--- /dev/null
+++ b/macros/Hardware/RasberryPi/pwm/RPI_pwmMode.sci
@@ -0,0 +1,46 @@
+// Copyright (C) 2017 - IIT Bombay - FOSSEE
+//
+// This file must be used under the terms of the CeCILL.
+// This source file is licensed as described in the file COPYING, which
+// you should have received as part of this distribution. The terms
+// are also available at
+// http://www.cecill.info/licences/Licence_CeCILL_V2-en.txt
+// Organization: FOSSEE, IIT Bombay
+// Email: toolbox@scilab.in
+
+function RPI_pwmMode(Mode)
+// Function to set the mode for the PWM generator
+//
+// Calling Sequence
+// RPI_pwmMode(mode)
+//
+// Parameters
+// mode: The mode to set for the PWM generator. 'ms' (for mark:space) or 'bal' (for balanced)
+//
+// Description
+// This function sets the mode for the PWM generator. The PWM generator can run in 2 modes – “balanced” and “mark:space”. The mark:space mode is traditional, however the default mode in the Pi is “balanced”. Switch modes by supplying the parameter: bal or ms
+//
+// Examples
+// RPI_pwmMode('bal')
+// See also
+// RPI_pwmRange, RPI_pwmClock, RPI_pwmToneWrite, RPI_pwmWrite
+//
+// Authors
+// Jorawar Singh
+//
+// Bibliography
+// http://wiringpi.com/reference/
+
+ if Mode=='ms' then
+ commande="pwM#1#0#";
+ elseif Mode=='bal' then
+ commande="pwM#1#1#";
+ else:
+ error("mode should be ""ms"" or ""bal""");
+ end
+ if getos=="Linux" then
+ unix_w("python -c ""import socket;s=socket.socket();s.connect((''"+RPI_piAdress+"'',9077));s.send(''"+commande+"'');print(s.recv(1024));s.close()""");
+ elseif getos=="Windows" then
+ RPI_winR=dos("python -c ""import socket;s=socket.socket();s.connect((''"+RPI_piAdress+"'',9077));s.send(''"+commande+"'');print(s.recv(1024));s.close()""");
+ end
+endfunction
diff --git a/macros/Hardware/RasberryPi/pwm/RPI_pwmRange.sci b/macros/Hardware/RasberryPi/pwm/RPI_pwmRange.sci
new file mode 100755
index 0000000..6a1503a
--- /dev/null
+++ b/macros/Hardware/RasberryPi/pwm/RPI_pwmRange.sci
@@ -0,0 +1,40 @@
+// Copyright (C) 2017 - IIT Bombay - FOSSEE
+//
+// This file must be used under the terms of the CeCILL.
+// This source file is licensed as described in the file COPYING, which
+// you should have received as part of this distribution. The terms
+// are also available at
+// http://www.cecill.info/licences/Licence_CeCILL_V2-en.txt
+// Organization: FOSSEE, IIT Bombay
+// Email: toolbox@scilab.in
+
+function RPI_pwmRange(value)
+// Function to set the divisor for the PWM clock.
+//
+// Calling Sequence
+// RPI_pwmRange(value)
+//
+// Parameters
+// value: maximum of the range for the PWM generator.
+//
+// Description
+// This function sets the range register in the PWM generator. The default is 1024.
+//
+// Examples
+// RPI_pwmRange(512)
+// See also
+// RPI_pwmMode, RPI_pwmClock, RPI_pwmToneWrite, RPI_pwmWrite
+//
+// Authors
+// Jorawar Singh
+//
+// Bibliography
+// http://wiringpi.com/reference/
+
+ commande="pwR#1#"+string(value)+"#";
+ if getos=="Linux" then
+ unix_w("python -c ""import socket;s=socket.socket();s.connect((''"+RPI_piAdress+"'',9077));s.send(''"+commande+"'');print(s.recv(1024));s.close()""");
+ elseif getos=="Windows" then
+ RPI_winR=dos("python -c ""import socket;s=socket.socket();s.connect((''"+RPI_piAdress+"'',9077));s.send(''"+commande+"'');print(s.recv(1024));s.close()""");
+ end
+endfunction
diff --git a/macros/Hardware/RasberryPi/pwm/RPI_pwmToneWrite.sci b/macros/Hardware/RasberryPi/pwm/RPI_pwmToneWrite.sci
new file mode 100755
index 0000000..d7ff6ed
--- /dev/null
+++ b/macros/Hardware/RasberryPi/pwm/RPI_pwmToneWrite.sci
@@ -0,0 +1,41 @@
+// Copyright (C) 2017 - IIT Bombay - FOSSEE
+//
+// This file must be used under the terms of the CeCILL.
+// This source file is licensed as described in the file COPYING, which
+// you should have received as part of this distribution. The terms
+// are also available at
+// http://www.cecill.info/licences/Licence_CeCILL_V2-en.txt
+// Organization: FOSSEE, IIT Bombay
+// Email: toolbox@scilab.in
+
+function RPI_pwmToneWrite(pin,freq)
+// Function to write a tone of a given frequency to the pin
+//
+// Calling Sequence
+// RPI_pwmToneWrite(pin,freq)
+//
+// Parameters
+// pin : The pin to set the frequency on. Numbering to be followed as initiated using RPI_pinNumbering.
+// freq: frequency to write
+//
+// Description
+// This function write the given frequency tone to the given pin.
+//
+// Examples
+// RPI_pwmToneWrite(0,100)
+// See also
+// RPI_pwmMode, RPI_pwmRange, RPI_pwmClock, RPI_pwmWrite, PRI_pinNumbering
+//
+// Authors
+// Jorawar Singh
+//
+// Bibliography
+// http://wiringpi.com/reference/
+
+ commande="pwT#2#"+string(pin)+"#"+string(freq)+"#";
+ if getos=="Linux" then
+ unix_w("python -c ""import socket;s=socket.socket();s.connect((''"+RPI_piAdress+"'',9077));s.send(''"+commande+"'');print(s.recv(1024));s.close()""");
+ elseif getos=="Windows" then
+ RPI_winR=dos("python -c ""import socket;s=socket.socket();s.connect((''"+RPI_piAdress+"'',9077));s.send(''"+commande+"'');print(s.recv(1024));s.close()""");
+ end
+endfunction
diff --git a/macros/Hardware/RasberryPi/pwm/RPI_pwmWrite.sci b/macros/Hardware/RasberryPi/pwm/RPI_pwmWrite.sci
new file mode 100755
index 0000000..113547a
--- /dev/null
+++ b/macros/Hardware/RasberryPi/pwm/RPI_pwmWrite.sci
@@ -0,0 +1,45 @@
+// Copyright (C) 2017 - IIT Bombay - FOSSEE
+//
+// This file must be used under the terms of the CeCILL.
+// This source file is licensed as described in the file COPYING, which
+// you should have received as part of this distribution. The terms
+// are also available at
+// http://www.cecill.info/licences/Licence_CeCILL_V2-en.txt
+// Organization: FOSSEE, IIT Bombay
+// Email: toolbox@scilab.in
+
+function RPI_pwmWrite(pin,value)
+// Function to write voltage value to the PWM register for the given pin.
+//
+// Calling Sequence
+// RPI_pwmWrite(pin,value)
+//
+// Parameters
+// pin : The pin number set the voltage at. Numbering sequence to be followed as initiated using RPI_pinNumbering function.
+// value: The voltage to set at the given pin. Range is 0-1024.
+//
+// Description
+// Writes the value to the PWM register for the given pin. The Raspberry Pi has one on-board PWM pin, pin 1 (BMC_GPIO 18, Phys 12). Other PWM devices may have other PWM ranges.
+//
+// Examples
+// RPI_pwmWrite(1,500)
+// See also
+// RPI_pwmMode, RPI_pwmRange, RPI_pwmClock, RPI_pwmToneWrite
+//
+// Authors
+// Jorawar Singh
+//
+// Bibliography
+// http://wiringpi.com/reference/
+
+ if [0<value,value<1024] then
+ commande="pwW#2#"+string(pin)+"#"+string(value)+"#";
+ else
+ error("Voltage has to be between 0 and 1024");
+ end
+ if getos=="Linux" then
+ unix_w("python -c ""import socket;s=socket.socket();s.connect((''"+RPI_piAdress+"'',9077));s.send(''"+commande+"'');print(s.recv(1024));s.close()""");
+ elseif getos=="Windows" then
+ RPI_winR=dos("python -c ""import socket;s=socket.socket();s.connect((''"+RPI_piAdress+"'',9077));s.send(''"+commande+"'');print(s.recv(1024));s.close()""");
+ end
+endfunction
diff --git a/macros/Hardware/RasberryPi/pwm/buildmacros.sce b/macros/Hardware/RasberryPi/pwm/buildmacros.sce
new file mode 100755
index 0000000..7d533f7
--- /dev/null
+++ b/macros/Hardware/RasberryPi/pwm/buildmacros.sce
@@ -0,0 +1,14 @@
+// Copyright (C) 2017 - IIT Bombay - FOSSEE
+//
+// This file must be used under the terms of the CeCILL.
+// This source file is licensed as described in the file COPYING, which
+// you should have received as part of this distribution. The terms
+// are also available at
+// http://www.cecill.info/licences/Licence_CeCILL_V2-en.txt
+// Author: Jorawar Singh
+// Organization: FOSSEE, IIT Bombay
+// Email: toolbox@scilab.in
+
+tbx_build_macros(TOOLBOX_NAME, get_absolute_file_path('buildmacros.sce'));
+
+clear tbx_build_macros;
diff --git a/macros/Hardware/RasberryPi/pwm/names b/macros/Hardware/RasberryPi/pwm/names
new file mode 100755
index 0000000..87e7088
--- /dev/null
+++ b/macros/Hardware/RasberryPi/pwm/names
@@ -0,0 +1,5 @@
+RPI_pwmClock
+RPI_pwmMode
+RPI_pwmRange
+RPI_pwmToneWrite
+RPI_pwmWrite