Toggle Pin vs. High/Low

Discussion about the ZBasic language including the System Library. If you're not sure where to post your message, do it here. However, do not make test posts here; that's the purpose of the Sandbox.
Post Reply
pjc30943
Posts: 220
Joined: 01 December 2005, 18:45 PM

Toggle Pin vs. High/Low

Post by pjc30943 »

zxOutputToggle does something slightly different than switching to the complementary output state: there seems to be a decay in one direction, making for transitions that are not sharp and don't reach logic level thresholds for quick toggles.

Just curious why this occurs...
Paul
dkinzer
Site Admin
Posts: 3120
Joined: 03 September 2005, 13:53 PM
Location: Portland, OR

Re: Toggle Pin vs. High/Low

Post by dkinzer »

pjc30943 wrote:there seems to be a decay in one direction
That description strongly suggests that the pin wasn't an output before the call to toggle the pin. If the pin is an input, calling PutPin() with zxOutputToggle simply toggles the state of the pullup resistor (enabled or not). The description of PutPin() clearly states that the pin must be an output prior to the call.

The sample code below demonstrates that the DDR and Port registers are set correctly by a call to PutPin() with zxOutputToggle. If you comment out the first two lines of Main(), you'll see that the pin remains an input.

Code: Select all

Dim pin as Byte = 12

Sub portStatus(ByVal s as String)
  Debug.Print s
  Debug.Print "DDRC = 0x"; CStrHex(Register.DDRC); ", PortC = 0x"; CStrHex(Register.PortC)
  Debug.Print
End Sub

Sub Main()
  Call portStatus("Before zxOutputLow")
  Call PutPin(pin, zxOutputLow)
  Call portStatus("After zxOutputLow")
  Call PutPin(pin, zxOutputToggle)
  Call portStatus("After zxOutputToggle")
  Call PutPin(pin, zxOutputToggle)
  Call portStatus("After zxOutputToggle")
End Sub
- Don Kinzer
pjc30943
Posts: 220
Joined: 01 December 2005, 18:45 PM

Post by pjc30943 »

You're right, that's what it sounds like. However, the pin was set to 0 beforehand.
A 100k pulldown solves the problem, however.

I'll look through the code again later and post again.
Paul
Post Reply