Difference between revisions of "Hw output pwm add"

From Sim Innovations Wiki
Jump to navigation Jump to search
 
(3 intermediate revisions by the same user not shown)
Line 1: Line 1:
== Description ==
== Description ==


'''hw_output_pwm_id = hw_output_pwm_add(name, frequency_hz, initial_duty_cycle)''' (from AM/AP 3.5)
  '''hw_output_pwm_id = hw_output_pwm_add(hw_id, frequency_hz, initial_duty_cycle)'''
  '''hw_output_pwm_id = hw_output_pwm_add(hw_id, frequency_hz, initial_duty_cycle)'''


'''hw_output_pwm_add''' is used to add a hardware PWM output to your instrument.
'''hw_output_pwm_add''' is used to add a hardware PWM output to your instrument.


== Return value ==  
== Named ==
{{tip| Available from AM/AP 3.5.}}
 
Give your hardware objects a name (.e.g. 'Power button' or 'Strobe LED').<br/>
Air Manager will present the user with a view where the assignment of pins can be done.
 
=== Arguments ===
 
'''hw_output_pwm_id = hw_output_pwm_add(name, frequency_hz, initial_duty_cycle)'''
 
{| class="wikitable"
|-
! # !! Argument !! Type !! Description
|-
| 1 || '''name''' || ''String'' || A functional name to define the PWM output.
|-
| 2 || '''frequency_hz''' || ''Number'' || The frequency of the PWM output signal, in Hz.
|-
| 3 || '''initial_duty_cycle''' || ''Number'' || The initial PWM duty cycle. Range 0.0 - 1.0, 0.0 being off, and 1.0 on.
|-
|}
 
=== Return value ===  


{| class="wikitable"
{| class="wikitable"
Line 14: Line 37:
|}
|}


== Arguments ==
=== Example ===


<source lang="lua">
-- Create new PWM pin
-- PWM frequency is set to 1 kHz, with a duty cycle of 50%.
output_id = hw_output_pwm_add("Heading servo", 1000, 0.5)
-- We can change the duty cycle runtime, in this case 20%
hw_output_pwm_duty_cycle(output_id, 0.2)
</source >
== Hardware Id's ==
{{warning| Hardware Id's are not preferred, try to use named hardware instead. }}
Define the used pin(s) right away.
This is not preferred, since changing of pin assignment can only be done by changing the instrument/panel lua script.
=== Arguments ===
'''hw_output_pwm_id = hw_output_pwm_add(hw_id, frequency_hz, initial_duty_cycle)'''


{| class="wikitable"
{| class="wikitable"
Line 29: Line 70:
|}
|}


== Example ==
=== Return value ===
 
{| class="wikitable"
|-
! Argument !! Type !! Description
|-
| '''hw_output_pwm_id''' || ''ID'' || This value can be used for further reference.
|}
 
=== Example ===


<source lang="lua">
<source lang="lua">
-- Bind to Raspberry Pi 2, Header P1, Pin 40
-- Bind to Raspberry Pi 2, Header P1, Pin 40
-- PWM frequency is set to 1 kHz, with a duty cycle of 50%.
-- PWM frequency is set to 1 kHz, with a duty cycle of 50%.
Line 39: Line 88:
-- We can change the duty cycle runtime, in this case 20%
-- We can change the duty cycle runtime, in this case 20%
hw_output_pwm_duty_cycle(output_id, 0.2)
hw_output_pwm_duty_cycle(output_id, 0.2)
</source >
</source >

Latest revision as of 19:34, 11 October 2018

Description

hw_output_pwm_id = hw_output_pwm_add(name, frequency_hz, initial_duty_cycle) (from AM/AP 3.5)
hw_output_pwm_id = hw_output_pwm_add(hw_id, frequency_hz, initial_duty_cycle)

hw_output_pwm_add is used to add a hardware PWM output to your instrument.

Named

Info Available from AM/AP 3.5.

Give your hardware objects a name (.e.g. 'Power button' or 'Strobe LED').
Air Manager will present the user with a view where the assignment of pins can be done.

Arguments

hw_output_pwm_id = hw_output_pwm_add(name, frequency_hz, initial_duty_cycle)
# Argument Type Description
1 name String A functional name to define the PWM output.
2 frequency_hz Number The frequency of the PWM output signal, in Hz.
3 initial_duty_cycle Number The initial PWM duty cycle. Range 0.0 - 1.0, 0.0 being off, and 1.0 on.

Return value

Argument Type Description
hw_output_pwm_id ID This value can be used for further reference.

Example

-- Create new PWM pin
-- PWM frequency is set to 1 kHz, with a duty cycle of 50%.
output_id = hw_output_pwm_add("Heading servo", 1000, 0.5)

-- We can change the duty cycle runtime, in this case 20%
hw_output_pwm_duty_cycle(output_id, 0.2)

Hardware Id's

Info Hardware Id's are not preferred, try to use named hardware instead.

Define the used pin(s) right away. This is not preferred, since changing of pin assignment can only be done by changing the instrument/panel lua script.

Arguments

hw_output_pwm_id = hw_output_pwm_add(hw_id, frequency_hz, initial_duty_cycle)
# Argument Type Description
1 hw_id String The is the reference to the input. You can choose to bind to an existing Hardware ID (Hardware_id_list).
2 frequency_hz Number The frequency of the PWM output signal, in Hz.
3 initial_duty_cycle Number The initial PWM duty cycle. Range 0.0 - 1.0, 0.0 being off, and 1.0 on.

Return value

Argument Type Description
hw_output_pwm_id ID This value can be used for further reference.

Example

-- Bind to Raspberry Pi 2, Header P1, Pin 40
-- PWM frequency is set to 1 kHz, with a duty cycle of 50%.
output_id = hw_output_pwm_add("RPI_V2_P1_40", 1000, 0.5)

-- We can change the duty cycle runtime, in this case 20%
hw_output_pwm_duty_cycle(output_id, 0.2)