Cha[@PortD,0] : bit; als Array?

  • 1
  • 2
  • 3
  • Seite 2 von 3
Harry
Moderator
Avatar
Geschlecht:
Herkunft: zwischen Augsburg und Ulm
Alter: 60
Beiträge: 2155
Dabei seit: 03 / 2003
Betreff:

Re: Cha[@PortD,0] : bit; als Array?

 · 
Gepostet: 06.03.2018 - 11:45 Uhr  ·  #9
Nicht schön, aber es funktioniert :)

Code

Procedure ReadStatus;        // Einlesen und aufbereiten der C&RStatus-Variablen
  Var D1, D2, Counter : Byte;
  Begin
    D1:=PinB;                // --> R8 C8 R7 C7 R6 C6 R5 C5
    D2:=PinF;                // --> C4 R4 C3 R3 C2 R2 C1 R1
    SetBit(CStatus.7,D1.1);  // CStatus --> Charge Slot 8,7,6,5,4,3,2,1
    SetBit(CStatus.6,D1.3);
    SetBit(CStatus.5,D1.5);
    SetBit(CStatus.4,D1.7);
    SetBit(CStatus.3,D2.0);
    SetBit(CStatus.2,D2.2);
    SetBit(CStatus.1,D2.4);
    SetBit(CStatus.0,D2.6);
    
    SetBit(RStatus.7,D1.0);  // RStatus --> Ready Slot 8,7,6,5,4,3,2,1
    SetBit(RStatus.6,D1.2);
    SetBit(RStatus.5,D1.4);
    SetBit(RStatus.4,D1.6);
    SetBit(RStatus.3,D2.1);
    SetBit(RStatus.2,D2.3);
    SetBit(RStatus.1,D2.5);
    SetBit(RStatus.0,D2.7);

  End ReadStatus;


Dauert ca. 32µs auf einem XMega256 @ 32 MHz.

Gruss
Harry
Merlin
Administrator
Avatar
Geschlecht:
Alter: 25
Beiträge: 1474
Dabei seit: 03 / 2005
Betreff:

Re: Cha[@PortD,0] : bit; als Array?

 · 
Gepostet: 06.03.2018 - 18:03 Uhr  ·  #10
Shame the bits of RStatus and CStatus are that way round wrt to port pins. Were they the other way round you could have used

Code

    CStatus := ( D1 and %10101010) or (D2 and %01010101);
    RStatus := ( D1 and %01010101) or (D2 and %10101010);


The following uses a lookup table to reverse the bits.

Code
const
  cReverse : array[0..15] of byte = (%0000, %1000, %0100, %1100,
                                     %0010, %1010, %0110, %1110,
                                     %0001, %1001, %0101, %1101,
                                     %0011, %1011, %0111, %1111);

function ReverseByte( pByte : byte ) : byte;
begin
  Return( (cReverse[ pByte and $0F ] shl 4) or (cReverse[ pByte shr 4 ]) );
end;

Procedure ReadStatus; // read in and prepare the C & R status variables
  Var D1, D2, Counter: Byte;
  Begin
    D1: = PinB; // -> R8 C8 R7 C7 R6 C6 R5 C5
    D2: = PinF; // -> C4 R4 C3 R3 C2 R2 C1 R1
    CStatus := ReverseByte(( D1 and %10101010) or (D2 and %01010101));
    RStatus := ReverseByte(( D1 and %01010101) or (D2 and %10101010));

  End ReadStatus;
Harry
Moderator
Avatar
Geschlecht:
Herkunft: zwischen Augsburg und Ulm
Alter: 60
Beiträge: 2155
Dabei seit: 03 / 2003
Betreff:

Re: Cha[@PortD,0] : bit; als Array?

 · 
Gepostet: 06.03.2018 - 19:46 Uhr  ·  #11
Hello Merlin,

thanks i will test it :). Because the circuit does not yet exist (i am waiting for a component delivery), this is a good way to play with the simulator ;).

Harry
Harry
Moderator
Avatar
Geschlecht:
Herkunft: zwischen Augsburg und Ulm
Alter: 60
Beiträge: 2155
Dabei seit: 03 / 2003
Betreff:

Re: Cha[@PortD,0] : bit; als Array?

 · 
Gepostet: 07.03.2018 - 07:23 Uhr  ·  #12
Hello merlin,

it doesn't work. Look at the Picture.

Harry
Der an diesem Beitrag angefügte Anhang ist entweder nur im eingeloggten Zustand sichtbar oder die Berechtigung Deiner Benutzergruppe ist nicht ausreichend.
Merlin
Administrator
Avatar
Geschlecht:
Alter: 25
Beiträge: 1474
Dabei seit: 03 / 2005
Betreff:

Re: Cha[@PortD,0] : bit; als Array?

 · 
Gepostet: 07.03.2018 - 09:44 Uhr  ·  #13
Yes, of course. Sorry.
Harry
Moderator
Avatar
Geschlecht:
Herkunft: zwischen Augsburg und Ulm
Alter: 60
Beiträge: 2155
Dabei seit: 03 / 2003
Betreff:

Re: Cha[@PortD,0] : bit; als Array?

 · 
Gepostet: 07.03.2018 - 10:01 Uhr  ·  #14
The Picture was wrong - sorry. Now its ok.

I test at this Moment this:
Code

RStatus:= (D1 and %10000000) or ((D1 and %00100000) shl 1) or 
         ((D1 and %00001000) shl 2) or ((D1 and %00000010) shl 3) or 
         ((D2 and %01000000) shr 3)  or ((D2 and %00010000) shr 2) or
         ((D2 and %00000100) shr 1) or (D2 and %00000001);


Harry

[Edit]It works :) ... 2.98µs

Code

Procedure ReadStatus2;       // read in and prepare the C & R status variables
  Var D1, D2 : Byte;
  Begin
    D1:= PinB;               // -> R8 C8 R7 C7 R6 C6 R5 C5
    D2:= PinF;               // -> C4 R4 C3 R3 C2 R2 C1 R1
    RStatus:=$00;
    RStatus:= (D1 and %10000000) or ((D1 and %00100000) shl 1) or
             ((D1 and %00001000) shl 2) or ((D1 and %00000010) shl 3) or
             ((D2 and %01000000) shr 3)  or ((D2 and %00010000) shr 2) or
             ((D2 and %00000100) shr 1) or (D2 and %00000001);

    CStatus:=$00;
    CStatus:=((D1 and %01000000) shl 1) or ((D1 and %00010000) shl 2) or
             ((D1 and %00000100) shl 3) or ((D1 and %00000001) shl 4) or
             ((D2 and %10000000) shr 4) or ((D2 and %00100000) shr 3) or
             ((D2 and %00001000) shr 2) or ((D2 and %00000010) shr 1);
  End ReadStatus2;
Merlin
Administrator
Avatar
Geschlecht:
Alter: 25
Beiträge: 1474
Dabei seit: 03 / 2005
Betreff:

Re: Cha[@PortD,0] : bit; als Array?

 · 
Gepostet: 07.03.2018 - 10:21 Uhr  ·  #15
:-)

Minor improvement - you don't need to set your values to zero, they are completely defined anyway.
Avra
Schreiberling
Avatar
Geschlecht:
Herkunft: Belgrade, Serbia
Alter: 54
Homepage: rs.linkedin.com/in…
Beiträge: 653
Dabei seit: 07 / 2002
Betreff:

Re: Cha[@PortD,0] : bit; als Array?

 · 
Gepostet: 10.03.2018 - 22:41 Uhr  ·  #16
Zitat geschrieben von Harry

Das alles wird ein Akkutester für gebrauchte LiIon-Zellen der Bauform 18650.

I use Litokala Lii-500 for charging and real capacity measurement of NiCD, NiMh and LiIon. With 18650 it even doubles as a nice battery bank. After buying it I found that when chinese write 3000mAh they actually mean 200mAh.
http://lygte-info.dk/review/Re…%20UK.html
  • 1
  • 2
  • 3
  • Seite 2 von 3
Gewählte Zitate für Mehrfachzitierung:   0

Registrierte in diesem Topic

Aktuell kein registrierter in diesem Bereich

Die Statistik zeigt, wer in den letzten 5 Minuten online war. Erneuerung alle 90 Sekunden.
MySQL Queries: 15 · Cache Hits: 14   130   144 · Page-Gen-Time: 0.030342s · Speichernutzung: 2 MB · GZIP: ein · Viewport: SMXL-HiDPI