Jump to content
IGNORED

Need Help with SWACNT - Port I/O


Recommended Posts

I'm trying to use SWACNT to activate a 3.3V vibrating motor when GPR0/GPR1 collides with the Playfield. Either I'm not understanding how I/0 works over the controller ports or my code is wrong.

 

I'd appreciate any pointers on what I'm doing wrong.

 

Here is the code:

On lines 92-93 in the attached ASM file, I'm setting SWACNT to a byte value of 10001000 for the purpose of setting D7 and D3 of the Data Direction Register to output, and the remaining bits to input.

        ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
        ;;; Setup Rumble Support for Hypothetical Controllers
        ;;; Set I/O on Pin 4 of Ports to Output
        ;;; Set I/O on Pins 1-3 to Input
        ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
        lda #%10001000
        sta SWACNT

On lines 252-276, I'm checking for collisions and attempting to set the SWA

Collisions
	ldy #%00000000
CheckP0PF
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;; Check to see if there is a collision
;;; Between Player 0 and the Playfield
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
	ldx #%10000000
	bit CXP0FB
	bmi SetP0PF
	sty SWCHA   ;;; If not, then turn off vibrate for player 0
	jmp CheckP1PF
SetP0PF
	stx SWCHA   ;;; turn on vibrate for player 0
CheckP1PF
	ldx #%00001000
	bit CXP1FB
	bmi SetP1PF
	sty SWCHA  ;;; if not, then turn off vibrate for player 1
	jmp DoneCollisions
SetP1PF
	stx SWCHA ;;; turn on vibrate for player 1
DoneCollisions
	sta CXCLR ;;; reset collisions
CollisionsEnd

I've tested a version of this code that changes playfield color when collisions occur. I've also tested the vibrating motor connected to my joystick prototype by connecting it directly to Pin 7 power and Pin 8 ground, and the motor works.

 

So the only thing I can think is that I'm not understanding how I/O works, or the amount of power flowing over pin 4. But possibly, I guess, my code is just wrong too.

 

This is for my Hypothetical Controller project. I've implemented the controller on breadboard, and eventually, this will be implemented in software as part of the Mr. Boehm project. I've also attached a video of me using the prototypes. The pot controlled directional hat works, the four fire buttons work.

 

You can see the size of the vibrating motor used in the video.

 

The only thing that doesn't appear to work is the rumble feature. I'd really like some help on what am I doing wrong.

 

Thanks,

 

Aaron

hypothetical.asm

Link to comment
Share on other sites

5 minutes ago, alex_79 said:

The input/output pins provide very little current and are designed to interface with other logic ICs, not to drive a load.
You need to build a driving circuit.

Similar to the examples in this page (for Arduino)

http://www.thebox.myzen.co.uk/Workshop/Motors_1.html

 

 

Thanks, I appreciate the insight. I will see what I can put together for a driving circuit.

 

I will do some more documentation reading to see if there would enough power on the 4 pin to control a transistor that would serve as a switch to pull power from the 7 pin to drive the motor without affecting the capacitors charging on Pins 5 and 9.

 

In my testing today, I noticed that when the 4 pin was set to output, power running through it was nearly 0, but when it was set to input, it was enough to move the sprite around the screen even though the current was passing through the motor.

 

It would be easy enough to set the 4 pin to output to cause the driving circuit to remain open, and then set the 4 pin to input to activate the transistor and close the driving circuit between the 7 pin and the motor going to ground.

 

Connecting the vibrating motor up to pins 7 and 8 today cause the motor to vibrate no problem. Maybe it's too much since pin 7 is 5V and the motors are only 3V.

Link to comment
Share on other sites

Well, I completed a "driving circuit" as my last Atari activity of my 10 day staycation.

 

After viewing the link Alex posted, I chatted with my friend Dave. Previously, David had soldered four mic2091 chips because we had thought that we would need them for the Mr. Boehm project, but ended up not needing them.

 

David sent me a schematic showing how it should be added to the H-Controller layout, and I dug around my parts bin until I found the the chips.

 

My first shot at implementing the driving circuit almost worked, except occasionally, the vibrating motor didn't always turn completely off due to the mic2091 remaining floating. David had me add a capacitor.

 

And now it works. See the attached image for the breadboard prototypes.

 

I also had to alter my code from yesterday some. When there is a collision detection between the Player sprite and the Playfield, then I set the Pin 4 I/O to "input", which turns on the vibrating motor. When the a collision is not detected, I set Pin 4 I/O to "output", which effectively kills the power for that pin, and turns off the vibrating motor.

 

See attached video for it all in action. The vibrating motor is glued to breadboard on the prototype that has the black pop socket, which unfortunately means that you can't see it vibrate. It did buzz, but unfortunately I had the mic turned off when I did the recording.

 

However, the vibrating motor on the other prototype is hanging loose, and you can easily see it vibrating in the video whenever Player1 collides with the playfield.

 

I've attached the updated code. Look for the "RumbleFeature" routine. Comments on how it works can be found in the code.

 

This prototype will be implemented in the Mr. Boehm software. But to be honest, this worked so well, that I might even make a PCB for just the H-Controller as well.

 

 

 

h-controllers.jpg

hypothetical-july-14.asm

  • Like 4
Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...