SwitchPort problem

Avra
Schreiberling
Avatar
Gender:
Location: Belgrade, Serbia
Age: 53
Homepage: rs.linkedin.com/in…
Posts: 653
Registered: 07 / 2002
Subject:

SwitchPort problem

 · 
Posted: 20.06.2014 - 02:01  ·  #1
SwitchPort is giving me trouble. In simulator when I change some bits to 0 in PinA, the change is printed once and after a few steps PinA is again $FF and change is lost. I caught it both with single stepping and with breakpoint in OnSysTick. I see nothing in code that should do this. I do not have this behavior when I use direct pins instead of SwitchPort. It looks like around 50 msec after setting any PinA bit to zero something restores $FF (sounds like 5 debouncing systicks each having 10ms?). Is it me or is it some kind of a debouncing bug?

Using 5.04.73

Code
program Test;

Device = mega64, VCC=3.3;

Define_Fuses
  NoteBook   = A;
  COMport    = USB;
  LockBits0  = [];
  FuseBits0  = [];
  FuseBits1  = [SPIEN, JTAGEN, OCDEN];
  FuseBits2  = [];

Import SysTick, SerPort, SerPort2, SwitchPort1;

From System Import Float, Processes, Tasks;


Define
  ProcClock      = 16000000;       {Hertz}
  SysTick        = 10;             {msec}
  StackSize      = $0064, iData;
  FrameSize      = $0064, iData;
  Scheduler      = iData;
  TaskStack      = $0020, iData;
  TaskFrame      = $0010;
  SerPort        = 9600, Stop1;    {Baud, StopBits|Parity}
  RxBuffer       = 8, iData;
  TxBuffer       = 8, iData;
  SerPort2       = 9600, Stop1;    {Baud, StopBits|Parity}
  RxBuffer2      = 8, iData;
  TxBuffer2      = 8, iData;
  SwitchPort1    = PinA;           {debouncing input port}
  PolarityP1     = %00000000;      {Polarity SwitchPort1}
  Debounce       = 5;              {debounce every 5 SysTicks}

Implementation

{$IDATA}

{--------------------------------------------------------------}
type
  PBit = pointer to byte;

  TTagStruct = record
    No : word;
    Tag: pointer;
  end;

var
{$PDATA}

  I    [@PinA]: byte;
  //
{$IDATA}
  DI_1 [@PORT_STABLE1, 0]: bit; // DI_1[@PinA, 0]: bit; // Input PIN
  DI_2 [@PORT_STABLE1, 1]: bit; // DI_2[@PinA, 1]: bit; // Input PIN
  DI_3 [@PORT_STABLE1, 2]: bit; // DI_3[@PinA, 2]: bit; // Input PIN
  DI_4 [@PORT_STABLE1, 3]: bit; // DI_4[@PinA, 3]: bit; // Input PIN
  DI_5 [@PORT_STABLE1, 4]: bit; // DI_5[@PinA, 4]: bit; // Input PIN
  DI_6 [@PORT_STABLE1, 5]: bit; // DI_6[@PinA, 5]: bit; // Input PIN
{$PDATA}
  SW_1 [@PinA, 6]: bit;         // Input PIN
  SW_2 [@PinA, 7]: bit;         // Input PIN
  
{$IDATA}
  SystemTicks: byte;
  
  b: byte;
  p: pointer;

const
  MB: array[1..2] of TTagStruct = ((No: 1; Tag: @I),
                                   (No: 2; Tag: @Port_Stable1));
                                   
{procedure OnSysTick;
begin
  //Push(_ACCEHI);
  PushAllRegs;
  Inc(SystemTicks);
  PopAllRegs;         // breakpoint
  //Pop(_ACCEHI);
end;}

{$IDATA}

begin
  DDRA  := %00000000;
  PORTA := %11000000;
  Start_Processes;
  loop
    b := Port_Stable1;
    p := pointer(MB[1].Tag); // ptr to ram
    Write(Serout, '   (' + IntToStr(Word(MB[1].Tag)));
    Write(Serout, ')='   + ByteToStr(p^));
    p := pointer(MB[2].Tag); // ptr to ram
    Write(Serout, ', ('   + IntToStr(Word(MB[2].Tag)));
    WriteLn(Serout, ')=' + ByteToStr(p^));
  endloop;
end Test.
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   32   46 · Page-Gen-Time: 0.030769s · Memory Usage: 2 MB · GZIP: on · Viewport: SMXL-HiDPI