Esempio n. 1
0
        public static void HardwarePwmAndISR()
        {
            const int isrPin = 4;
            const int pwmPin = 18;

            Console.Write("Setup ");

            WiringPiWrapperDirect.WiringPiSetupGpio();

            WiringPiWrapperDirect.pinMode(isrPin, PinType.INPUT);
            WiringPiWrapperDirect.pullUpDnControl(isrPin, PullUpType.PUD_DOWN);
            //WirinPiWrapper.wiringPiISR (isrPin, EdgeType.INT_EDGE_RISING, IsrCounter);

            WiringPiWrapperDirect.pwmSetMode(PwmType.PWM_MODE_MS);
            WiringPiWrapperDirect.pinMode(pwmPin, PinType.PWM_OUTPUT);

            Console.WriteLine("completed.");

            int  loopCount = 1000;
            int  clock     = 2;                                         //Teile den max Prozessortakt in Count Teile
            uint range     = 2;                                         //Mach jedes dieser Teile durch 2 Teilbar

            WiringPiWrapperDirect.pwmSetClock(clock);
            WiringPiWrapperDirect.pwmSetRange(range);

            DateTime start = DateTime.Now;

            m_isrCounter = 0;

            WiringPiWrapperDirect.pwmWrite(pwmPin, 1);                  //Schreibe 1 von 2 Teilen Plus, dann 1/2 0
            while (m_isrCounter < loopCount)
            {
                ;
            }

            DateTime end         = DateTime.Now;
            float    frequenzKhz = (float)(loopCount / (new TimeSpan(end.Ticks - start.Ticks).TotalMilliseconds));

            Console.WriteLine(string.Format("Clock: {0}, Range: {1} Frequenz in KHz: {2}", clock, range, frequenzKhz));
            Console.WriteLine(string.Format("Resultierende PWI Grundfrequez: {0} KHz", clock * frequenzKhz));

            //Hier ist ein Oszi nötig: schreibe ich falsch oder Messe ich falsch?
            //Angeblich ist die interne Clock 19.2MHz
            //Ich komme bei einer Teilung von 64 auf 4,5KHz --> interne Clock 64 * 4,5 = 288KHz?
            //Bei kleinerer Teilung bleibt er stehen (32), danach (ab 16) freeze, der nur mit kaltem reboot zu beenden ist.

            //Vermute, da läuft am ISR ein Stack voll?
            //Stimmt wohl: Ohne ISR schreibt er auch mit clock 2 range 2 data 1: Das sollten dann 10MHZ sein: Oszi??

            //Fazit ISR ist eine feine Sache aber nicht für Hochfrequenz, 3-4 KHz hält das aus, dahinter dann wohl nur primitive Methoden
            //ledoder volle Threadpools etc


            //Console.WriteLine ("completed.");
        }
Esempio n. 2
0
        public static void RotaryEncoder()
        {
            Console.Write("Setup ");

            WiringPiWrapperDirect.WiringPiSetupGpio();
            WiringPiWrapperDirect.pinMode(ClickPin, PinType.INPUT);
            WiringPiWrapperDirect.pinMode(DataPin, PinType.INPUT);
            WiringPiWrapperDirect.pinMode(ClockPin, PinType.INPUT);

            WiringPiWrapperDirect.pullUpDnControl(ClickPin, PullUpType.PUD_UP);                 //!!
            WiringPiWrapperDirect.pullUpDnControl(DataPin, PullUpType.PUD_DOWN);
            WiringPiWrapperDirect.pullUpDnControl(ClockPin, PullUpType.PUD_DOWN);

            Console.WriteLine("completed.");

            Thread rotaryPoller = new Thread(RotaryPoller);

            rotaryPoller.Start();
            bool mouseDown = false;

            Int32 last4Positions = 0;

            do
            {
                Console.WriteLine(BinaryRotaryValue);

                if (BinaryRotaryValue == 4)
                {
                    Console.WriteLine("MouseDown");
                    mouseDown = true;
                    continue;
                }
                if (mouseDown)
                {
                    Console.WriteLine("MouseUp");
                    mouseDown = false;
                }

                //Links = 1320
                //Rechts = 2310
                last4Positions  = last4Positions << 8;
                last4Positions += BinaryRotaryValue;

                if (last4Positions == 0x01030200)
                {
                    Console.WriteLine("LeftRotation");
                }

                if (last4Positions == 0x02030100)
                {
                    Console.WriteLine("RightRotation");
                }
            } while(RotaryChanged.WaitOne());
        }
Esempio n. 3
0
        //Hier wird nicht gechained, sondern nur die Ausgabe gelesen
        //Mit OE wird vermieden, dass die Zwischenzustaände ausgegeben werden und flackern
        private static void     SchieberegisterChained()
        {
            Console.Write("Setup ");

            WiringPiWrapperDirect.WiringPiSetupGpio();

            WiringPiWrapperDirect.pinMode(SerialDataPin, PinType.OUTPUT);
            WiringPiWrapperDirect.pinMode(StorageClockPin, PinType.OUTPUT);
            WiringPiWrapperDirect.pinMode(ShiftClockPin, PinType.OUTPUT);
            WiringPiWrapperDirect.pinMode(NotOutEnabledPin, PinType.OUTPUT);
            WiringPiWrapperDirect.pinMode(ShiftOutPin, PinType.INPUT);
            WiringPiWrapperDirect.pullUpDnControl(ShiftOutPin, PullUpType.PUD_DOWN);

            WiringPiWrapperDirect.digitalWrite(SerialDataPin, 0);
            WiringPiWrapperDirect.digitalWrite(ShiftClockPin, 0);

            Console.WriteLine("completed.");

            WriteByteReturn(0);
            int lastInput = 0;
            int state;
            int output;

            int loopCount = 10000;

            DateTime start = DateTime.Now;

            for (int loop = 0; loop < loopCount; loop++)
            {
                WiringPiWrapperDirect.digitalWrite(NotOutEnabledPin, 1);

                for (int i = 0; i < 8; i++)
                {
                    state  = 1 << i;
                    output = WriteByteReturn(state);

                    if (output != lastInput)
                    {
                        Console.WriteLine("Schätze da hast Du mächtig Scheisse am Hacken.");
                    }
                    lastInput = state;
                }

                WiringPiWrapperDirect.digitalWrite(NotOutEnabledPin, 0);
            }

            DateTime stop = DateTime.Now;

            Console.WriteLine(loopCount + " Loops in " + new TimeSpan(stop.Ticks - start.Ticks).TotalMilliseconds + " ms.");
        }