Visar inlägg med etikett Computers. Visa alla inlägg
Visar inlägg med etikett Computers. Visa alla inlägg

måndag 29 april 2013

Stegmotor+Raspberry Pi

Med hjälp av http://www.raspberrypi-spy.co.uk/2012/07/stepper-motor-control-in-python/ och http://www.raspberrypi-spy.co.uk/2013/04/berryclip-6-led-board-testing-in-c/ petade jag ihop följande


#include <wiringPi.h>
#include <stdlib.h>
#include <stdio.h>
#include <unistd.h>

int pin[]={ 5, 6, 10, 11 };
int delaytime=1;

void init_pins ();
void step_forward ();
void step_backward ();
void closedown ();

int main(void) {
        int step;

        if (wiringPiSetup () == -1) {
                printf ("problem med wiringPi\n");
                exit (1);
        }
        init_pins();
// 2038-2039 verkar innebära ett varv/360 grader 2038/4=509,5
// Kanske 512 är nära nog, isf blir
// 180:256, 90:128, 45:64, 22.5:32, 11.25:16, _5.625_:8,
// 2.8125:4, 1.40625:2 och 0,703125:1
// Varje step_xxx() innebär en cykel, dvs 8 signaler och 8 step_xxx =
// 5.625 grader; 8x8=64
// Kortet har spec "stride angle 5.625 grader/64"...

        for (step=0; step<509; step++)
                step_forward();
        for (step=0; step<509; step++)
                step_backward();
        closedown();
        exit(0);
}

// Functions

void init_pins () {
        int c;

        for (c=0; c<4; c++)
                pinMode(pin[c], OUTPUT);
}
void step_forward () {
        int bit, pos, c;
        int a=8, b=4;

        for (c=0; c<4; c++, b=(b==1)?8:b/2, a=(a==1)?8:a/2) {
                for (bit=8, pos=0; bit>=1;bit/=2, pos++) {
                        digitalWrite (pin[pos], a&bit);
                        delay (delaytime);
                }
                for (bit=8, pos=0; bit>=1;bit/=2, pos++) {
                        digitalWrite (pin[pos], (a+b)&bit);
                        delay (delaytime);
                }
        }
}
void step_backward () {
        int bit, pos, c;
        int a=1, b=8;

        for (c=0; c<4; c++, b=(b==8)?1:b*2, a=(a==8)?1:a*2) {
                for (bit=8, pos=0; bit>=1;bit/=2, pos++) {
                        digitalWrite (pin[pos], (a+b)&bit);
                        delay (delaytime);
                }
                for (bit=8, pos=0; bit>=1;bit/=2, pos++) {
                        digitalWrite (pin[pos], a&bit);
                        delay (delaytime);
                }
        }
}
void closedown () {
        int c;

        for (c=0;c<4;c++)
                digitalWrite (pin[c], 0);
}

I exemplet kör jag den ett varv medurs och sedan tillbaka ett varv.

Det jag inte fattar är det som jag skriver i kommentaren i mitten:
Om 512 cykler blir ett varv (vilket mina tester inte riktigt visar) så gör 8 cykler om 8 signaler att motorn snurrar 5,625 grader, vilket sammanfaller med specen på kortet att den har "Stride Angle: 5,625 grader/64" eller, på en annan PDF "Step Angle: 5,625 grader/64".

Nu vet jag inte vad det betyder, men det är inget minimum för hur mycket man kan snurra motorn iaf då en cykel blir ~0,7 grader.

(Siffran 2038-2039 har jag från innan jag hade for-loopen som snurrar 4 ggr inne i step-xxx-funktionerna)

Ett annat och allvarligare problem jag har är att resurser käkas upp på nåt mysko sätt.
Sitter jag och editerar, bygger, kör, editerar, bygger, kör osv så börjar det sakta gå segare och segare tills jag tappar kontakten och måste starta om.

Jag har testat med script att köra programmet 100 ggr utan att samma skedde.
Jag har också testat att med script bygga programmet 200 ggr utan problem.
Återstår editorn, nano, men jag är lite skeptisk till att den skulle orsaka sådana problem...

Kan nämnas att jag har en Raspberry till, där jag inte sett motsvarande trots idogt editerande.

torsdag 1 juli 2010

Teamviewer

We arrived safe in Shenyang, China around noon today (local time) after about 20 hours in the air and in the Amsterdam and Beijing airports.
It is raining so only around 30 degrees but quite humid.
Since Facebook and Google are blocked I had to do something to get around that.
gmail actually worked fine, I just had to go to google.hk, but google reader only worked for some of the sites, and of course Facebook didn't work at all.
Also, google reader is fine for reading blogs but not for writing...

Knowing all this before I went, I installed TeamViewer on my PC at home and I'm using it right now to get this post written.
I'm fairly satisfied with their remote control solution, but I had expected a little bit more from their VPN solution, which only be used to open a explorer window on the remote host, not what I'd call VPN.

måndag 15 februari 2010

Mapping network drives with Windows 7

I had some big problems mapping up my NAS on my new mini-PC that runs Windows 7.
It was very weird, because it just wouldn't accept the user name or password, which I knew were correct.

A number of hits on google suggested that the only solution was to upgrade to Premium.
But after a while I found this suggestion
Enable XP compatible mode, or some such by...
Create this new value in the registry:
[HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Lsa]
"lmcompatibilitylevel"=dword:00000002
And voila, it works just like it ought to.
Apparently M$ changed how networking works but left no information about this where one actually use it. So everything looks just right, except that the password won't work.

I wonder how many actually upgrades without any reason, just because it said so on the interwebs...

onsdag 27 maj 2009

Number Pads

I remember that I have read somewhere as to why there are two standards in how the numbers are positioned on numeric key pads, but I cannot for the life of me remember...

What am I talking about?
Well, take a look on the numeric keypad on your computer keyboard and then on your phone; on the computer keypad the numbers go 7, 8, 9; 4, 5, 6; 1, 2, 3; and 0. On the phone they go 1, 2, 3; 4, 5, 6; 7, 8, 9; and 0.

Now, why are there two standards, and why have not one of them taken over yet?

Computer-like devices:
Computer keyboards (from DEC VT52 to modern PCs)
Calculators

Phone-like devices:
ATM machine keypads
Pads for Bank errands via Internet
Port code devices (Code locks to enter the Server room or the building where you live)
Credit Card pads (when you pay in your local store)

I got some sort of answer when googling for examples of these two standards:
http://www.vintagecalculators.com/html/frequently_asked_questions.html#keyPads

It seems it's all Bell Labs' fault.

Still it doesn't explain why one standard hasn't taken over completely yet...