Skip to content

PulseGenFirmata #391

Open
Open
@arm22q13

Description

@arm22q13

We have modified Standard Firmata to generate digital pulses. Our current fork is simply an updated .ino file (attached here as a text file). This version is hard-coded for D8 to D13 of the Mega 2560, but could easily be generalize to other devices and I/O ports. Testing has been with Firmata Test and using MWorks (https://mworks.github.io/). Concise details are here.

PulseGenFirmata
Digital bits D8 to D13 are hard coded as single pulse outputs ("pulsers"). Only one pulser can be triggered at a time and the pulse must be allowed to finish before triggering another (retriggering of the same channel can be enabled, see below).

The analogWriteCallback() function is called for Firmata analog out, which is a PWM command on the Arduino. analogWriteCallback takes two parameters: the pin number and a value from 0 to 255. PulseGenFirmata intercepts these values and uses them either as timing values or command values to program and trigger the pulsers.

analogWrite(byte pin, int value) [note, this is implemented in Arduino Firmata as analogWriteCallback()]
pin between 8 and 13 (these are the valid pulsers implemented for a Mega 2560)
The value parameter:
value 0 to 250 sets the pulse duration in milliseconds. No pulse is triggered when the value is set.
value 251 triggers the pulse
value 252 sets the multiplier to 1 (default) => 0 - 250 ms
value 253 sets the multiplier to 2 => 0 - 500 ms
value 254 sets the multiplier to 4 => 0 - 1000 ms
value 255 sets the multiplier to 10 => 0 - 2.5 sec
(Note: timer1 is used and cannot service pulses longer than about 8.3 sec)

     examples:
        analogWrite(9,50)       sets pulse duration to 50 ms
        analogWrite(9,254)      sets pulse multiplier to 4
        analogWrite(9,251)      sends a single pulse of 100 ms duration (50 ms x 4)
        analogWrite(9,250)      sets pulse duration to 250 ms
        analogWrite(9,251)      sends a single pulse of 1 sec (250 ms x 4)

Error condition:
ERROR_LED (default bit 25) is latched ON if a new pulse is triggered before the old pulse is complete. To extinguish that LED, Enable D25 as a digital output. Turn it ON, then turn it OFF. The error condition overrides Firmata commands to the LED to turn it ON.

Servo function disabled.
All calls to the Servo functionality of Firmata have been disabled. This was not entirely necessary, but it does protect timer1 from unexpected use.

PulseGenFirmata.txt

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions