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

  • 1
  • 2
  • 3
  • Page 2 of 3
Harry
Moderator
Avatar
Gender:
Location: zwischen Augsburg und Ulm
Age: 59
Posts: 2087
Registered: 03 / 2003
Subject:

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

 · 
Posted: 06.03.2018 - 11:45  ·  #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
Gender:
Age: 24
Posts: 1373
Registered: 03 / 2005
Subject:

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

 · 
Posted: 06.03.2018 - 18:03  ·  #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
Gender:
Location: zwischen Augsburg und Ulm
Age: 59
Posts: 2087
Registered: 03 / 2003
Subject:

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

 · 
Posted: 06.03.2018 - 19:46  ·  #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
Gender:
Location: zwischen Augsburg und Ulm
Age: 59
Posts: 2087
Registered: 03 / 2003
Subject:

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

 · 
Posted: 07.03.2018 - 07:23  ·  #12
Hello merlin,

it doesn't work. Look at the Picture.

Harry
You must be logged in or your permissions are to low to see this Attachment(s).
Merlin
Administrator
Avatar
Gender:
Age: 24
Posts: 1373
Registered: 03 / 2005
Subject:

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

 · 
Posted: 07.03.2018 - 09:44  ·  #13
Yes, of course. Sorry.
Harry
Moderator
Avatar
Gender:
Location: zwischen Augsburg und Ulm
Age: 59
Posts: 2087
Registered: 03 / 2003
Subject:

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

 · 
Posted: 07.03.2018 - 10:01  ·  #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
Gender:
Age: 24
Posts: 1373
Registered: 03 / 2005
Subject:

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

 · 
Posted: 07.03.2018 - 10:21  ·  #15
:-)

Minor improvement - you don't need to set your values to zero, they are completely defined anyway.
Avra
Schreiberling
Avatar
Gender:
Location: Belgrade, Serbia
Age: 53
Homepage: rs.linkedin.com/in…
Posts: 653
Registered: 07 / 2002
Subject:

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

 · 
Posted: 10.03.2018 - 22:41  ·  #16
Quote by 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
  • Page 2 of 3
Selected quotes for multi-quoting:   0

Registered users in this topic

Currently no registered users in this section

The statistic shows who was online during the last 5 minutes. Updated every 90 seconds.
MySQL Queries: 14 · Cache Hits: 14   130   144 · Page-Gen-Time: 0.028459s · Memory Usage: 2 MB · GZIP: on · Viewport: SMXL-HiDPI