Simultaneous Outport Ports?
#1
Posted 24 February 2011 - 04:03 PM
#2
Posted 24 February 2011 - 04:16 PM
#3
Posted 24 February 2011 - 06:22 PM
#4
Posted 24 February 2011 - 07:58 PM
This currently results in a ~50us lag between pulses. Is there a way to eliminate/ reduce that difference?
What about using the Fluent Interop stuff? That can reduce the lag your seeing. I'm honestly not sure how much though.
-dan
#5
Posted 24 February 2011 - 08:58 PM
#6
Posted 25 February 2011 - 02:08 AM
#7
Posted 25 February 2011 - 02:27 PM
#8
Posted 26 February 2011 - 06:45 PM
I think I must reluctantly disagree with our esteemed moderator. Doing what you want is quite easy actually.It's not absolutely critical for me to eliminate the 50us delay, but there's no harm in trying!
Inside a given bank, you can:
- Simultaneously turn on any subset of the 32 pins, or
- Simultaneously turn off any subset of the 32 pins
I have written some sample code which:
- turns on (D0,D1) simultaneously
- turns on (D2,D3) simultaneously (leaving D0,D1 alone)
- then turns (D2,D3) off
- then turns (D2,D3) on again
- and finally turns all four off simultaneously
Here is the screenshot from Salae:
And here is the code, written in Fluent style. It could also be compiled into the firmware, but this was more convenient for me:
using System; using FluentInterop.CodeGeneration; using FluentInterop.Expressions; using FluentInterop.Fluent; using SecretLabs.NETMF.Hardware.Netduino; namespace FluentSandbox { public class Program { public static void Main() { var pins=new[] { Pins.GPIO_PIN_D0, Pins.GPIO_PIN_D1, Pins.GPIO_PIN_D2, Pins.GPIO_PIN_D3, }; //sanity check var firstBank=(int)pins[0]/32; foreach(var pin in pins) { var thisBank=(int)pin/32; if(thisBank!=firstBank) { throw new Exception("all pins must be in same bank"); } } var code=CodeGenerator.Compile(g=> { g.Declare.Function("main", f => { var firmware=f.StandardArgs.firmwareParam16; var d0=f.Declare.PIOReference("bank0"); var mask0=f.Declare.Int("mask0"); var mask1=f.Declare.Int("mask1"); var mask2=f.Declare.Int("mask2"); var mask3=f.Declare.Int("mask3"); //wasteful to write d0 four times, since by definition it will be the same every time, //but this is just a demo firmware.GetPIOAndBitmask((int)pins[0], ref d0, ref mask0); firmware.GetPIOAndBitmask((int)pins[1], ref d0, ref mask1); firmware.GetPIOAndBitmask((int)pins[2], ref d0, ref mask2); firmware.GetPIOAndBitmask((int)pins[3], ref d0, ref mask3); var mask0And1=f.Declare.Int("mask0and1", mask0|mask1); var mask2And3=f.Declare.Int("mask2and3", mask2|mask3); var allMasks=f.Declare.Int("allMasks", mask0And1|mask2And3); d0.PER=allMasks; //enable all 4 pins at once d0.CODR=allMasks; //clear all 4 pins at once d0.OER=allMasks; //enable output on all 4 pins at once d0.SODR=mask0And1; //turn 0 and 1 on d0.SODR=mask2And3; //turn 2 and 3 on d0.CODR=mask2And3; //turn 2 and 3 off d0.SODR=mask2And3; //turn 2 and 3 back on again d0.CODR=allMasks; //turn all 4 off }); }); code.Invoke(0); } } }
#10
Posted 27 February 2011 - 01:00 AM
#11
Posted 27 February 2011 - 07:03 AM
0 user(s) are reading this topic
0 members, 0 guests, 0 anonymous users