Shop OBEX P1 Docs P2 Docs Learn Events
Basic Stamp 2 SHIFTOUT with clock input? — Parallax Forums

Basic Stamp 2 SHIFTOUT with clock input?

QAHQAH Posts: 13
edited 2011-08-29 11:11 in BASIC Stamp
Hello everyone!

I am trying to interface my Basic Stamp 2 with the controller port on my Super Nintendo System. I've been able to successfully interface Super Nintendo controller to the stamp, but not the stamp to the console.

Here's my problem. The Super Nintendo sends clock pulses to the controllers so that they will shift each button state to its CPU. I am trying to emulate a controller with my Basic Stamp, and I thought about using the SHIFTOUT command to shift button states to the Super Nintendo. The problem is, the Basic Stamp also wants to pulse the clock line, but I need it to "listen" for pulses from the Super Nintendo as a queue to send a bit.

So in a nutshell, how can I make the stamp shift out data bits by listening to clock pulses instead of it sending its own?

Thanks

Comments

  • Mike GreenMike Green Posts: 23,101
    edited 2011-08-29 07:47
    You can't do it with a built-in Stamp statement. If the clock pulses are slow enough, you can write your program to do it a bit at a time like this
    for i = 1 to 8
       out4 = myData.bit0  ' put data on line
       do until in5 = 1 : loop  ' wait for clock
       myData = myData >> 1  ' shift data right
       do while in5 = 1 : loop  ' wait for end of clock
    next
    
    If this is too slow, then you need an external parallel to serial shift register like the 74HC165 that you load in parallel from the Stamp and the Nintendo controls the serial clock line. If you don't have enough I/O pins, then you'll have to use a serial to parallel shift register like the 74HC595 that you'd quickly load from the Stamp using a SHIFTOUT and transfer the data to the 74HC165 in parallel.
  • QAHQAH Posts: 13
    edited 2011-08-29 10:45
    OK that looks like it could work. The clock pulses the Nintendo sends out are supposed to be 12us wide according to the specs online. I was thinking that maybe I could use a PULSIN statement, since it works in units of 2us, and I could have it wait for the 12us pulse before sending out a bit.
  • Mike GreenMike Green Posts: 23,101
    edited 2011-08-29 11:11
    You could use a PULSIN statement and ignore the value returned since any pulse would do there. There's still the issue of speed. Most PBasic statements take 150uS or more to execute. I suspect that the bits (and successive clock pulses) will come in too quickly for the Stamp to handle. We're talking about some code like this
    for i = 1 to 8
       out4 = myData.bit0
       pulsin 5,1,dummyVar
       myData = myData >> 1
    next
    
    This website has good information on execution times. Click on "app-notes". You're probably looking at 2-3ms per loop.
Sign In or Register to comment.