Forum Index
HomeZBasic Home   Forum RulesForum Rules   Forum FAQForum FAQ   MemberlistMemberlist   UsergroupsUsergroups   RSS FeedRSS Feed
Site SearchSite Search   LinksLinks   DownloadDownload   Digests and SubscriptionsDigests and Subscriptions
ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in   RegisterRegister
Chip randomly working incorrectly.

 
Post new topic   Reply to topic    Forum Index -> ZX-24
Author Message
cdavis



Joined: 12 Jun 2006
Posts: 9
Location: Garden Grove, CA

Posted: 14 June 2006, 17:21 PM    Post subject: Chip randomly working incorrectly. Reply with quote

[Edit] Reposted by Don due to hosting problems.

I recently bought a zx-24, and began to test it at home using my basicx dev board. I assumed the devboard would work because the zx and bx chips are pin compatible, and it did work. I wrote random programs here and there to test various functions, but something I noticed was quite odd: Sometimes I could run a program and it would behave as expected over and over again, but occasionally, the same code I just ran reliably over and over, would do something different and unexpected. This doesn't make sense to me.

Here is the code:

Code:
option explicit
public sub main()
  dim i as integer
  debug.print "I am smart!"

  for i = 1 to 3
    Call putpin(25,0)
    call delay(0.1)
    call putpin(25,1)
    call delay(0.1)
    Call putpin(26,0)
    call delay(0.1)
    call putpin(26,1)
    call delay(0.1)
  next

  debug.print "the square root of 9 is " & cstr(sqr(9.0))
  for i = 1 to 4
    debug.print "ok"
    if i = 2 then
      debug.print "Not ok"
    end if
  next

  if getpin(6)=0 and getpin(7) = 0 then
    call putpin(26,0)
  end if

  call putpin(6,1)

  if getpin(6)=1 and getpin(7) = 1 then
    call putpin(26,1)
  end if

  debug.print cstr(getpin(7))
end sub

As you can imagine, this program blinks the led's in the beginning, prints ok and not ok a couple of times, then it should turn the green led on because the state of both pins 6 and 7 are 0, then it should leave the green light on because I only changed the state of pin 6 to 1, I didnt change the state of pin 7. The the program should print that the state of pin 7 is zero.

The program did this a few times in a row, but I unplugged the dev board and plugged it back in, and that time the green led turned off at the end and it returned a state of 1 for pin 7. This occurence makes no sense to me, perhaps I am missing something simple.


thanks,
Back to top
dkinzer
Site Admin


Joined: 03 Sep 2005
Posts: 2499
Location: Portland, OR

Posted: 14 June 2006, 17:55 PM    Post subject: Reply with quote

I assert that the program, as written, will produce varying results and is thus working correctly. This is just as true when run on a BX-24 as when run on a ZX-24 but the results may well be different between the two. The results may even be different between two ZX-24 chips or at different times of the day. The results may be different as well depending on what other equipment nearby happens to be running.

The reason that this is so is that the GetPin() function does not return the output state of a pin. Rather, it reconfigures the pin to be an input and then reads the input state. This behavior, described in the documentation, is identical to that of the BX-24. The difference in the actual result is almost certainly due to the effect of reading a floating input - the result can be different from one millisecond to the next because the high impedance input acts like an antenna. It can easily be affected by the local electromagnetic fields.

Also, different chips may exhibit slightly different behavior even if they're sitting side-by-side in the same environment. That's because the impedance and other electrical characteristics of an input pin vary from chip to chip. Two chips that were adjacent on the wafer when manufactured probably will exhibit similar characteristics but a chip from one side of a wafer and one from the opposite side might be slightly different.

The test program can be "fixed" in one of two ways. If you really wanted to read the output state, make the pin an output and add a call to a function like the one below that returns the current output state of a pin. If you intended to read the input state, make sure the pin is an input and connect the pin in question to external devices that provides a signal for the ZX to read. The simplest external device is a pullup/pulldown resistor. Adding a 10K resistor from the pin to either +5 or ground will ensure that consistent values are read. Note that, by default, all ZX input pins are high-impedance inputs (i.e. internal pullup not enabled).

There are two things to note about the code below. Firstly, it is specific to the ZX-24. To use it with the ZX-40 or ZX-44 it would have to be modified to correspond to the pin arrangements of those devices. Secondly, if PinState() is called giving a pin that is not then an output, the result is meaningless. (Actually, the result indicates whether the input pin has its internal pullup enabled or not.)

Code:
' This table, indexed by (pinNumber - 24) gives the PortB bit
' corresponding to pins 25-27.
Private pinTbl as ByteVectorData({ 7, 5, 4 })

'----------------------------------------------------------------------
'
'' PinState
'
' Determine the current state of a ZX-24 output pin.  If an invalid pin number
' is passed, zero is returned.  If the pin number of an input is passed,
' the result is meaningless.
'
Function PinState(ByVal pin as Byte) as Byte
   Select Case pin
   Case 5 To 12
      PinState = GetBit(Register.PortC, 12 - pin)
   Case 13 To 20
      PinState = GetBit(Register.PortA, 20 - pin)
   Case 25 To 27
      PinState = GetBit(Register.PortD, pinTbl(pin - 24))
   Case Else
      PinState = 0
   End Select
End Function
Back to top
cdavis



Joined: 12 Jun 2006
Posts: 9
Location: Garden Grove, CA

Posted: 19 June 2006, 20:52 PM    Post subject: Many thanks Reply with quote

Don,

After considering what you said, and reading a bit more no the forum, it made sense why my chip was acting that way. The pin I was attempting to read the state of was not configured as an input. Since I applied that idea to my programs everything works perfectly. Thanks for the help.


Casen
Back to top
Display posts from previous:   
Post new topic   Reply to topic    Forum Index -> ZX-24 Time synchro. with the server - Timezone/DST with your computer
Page 1 of 1

 


All content Copyright © 2005-2012 Elba Corp. All Rights Reserved.
Opinions expressed in posts are those of the author and not necessarily those of Elba Corp.
Powered by phpBB © 2001, 2005 phpBB Group