Jump to content
flickertail

I/O SWCHA and SWACNT

Recommended Posts

I am trying to figure out out to drop Pin 1 of each controller port to 0V by setting the pin to output.

 

This is my understanding of how it's done:

 

lda 0

sta SWCHA

lda #%00010001

sta SWACNT

 

At this point the pins should have 0V. Then I want to return it to 5V. It's my understanding that I can do this by:

lda #%00000000

sta SWACNT

 

Is this correct or do I not understanding how I/O works?

 

I'm basically trying to control some transistors in an external device connected to the control ports.

 

Share this post


Link to post
Share on other sites

By writing a 0 to SWACNT you set the bits back to input mode, and they're at logical "1" in that mode, so it should work.

 

But typically, you initially just set to '1' the bits corresponding  to the pins you want to use as outputs in SWACNT, then you control the output value by only writing to SWCHA.

So, to return them to 5v, while leaving the pins in output mode, you can write #%00010001 to SWCHA.

 

I think there are differences in how much current you can source from the pins when in input mode compared to output mode, but I'm not expert here, and it might not matter for your application, anyway.

 

Share this post


Link to post
Share on other sites
8 hours ago, alex_79 said:

By writing a 0 to SWACNT you set the bits back to input mode, and they're at logical "1" in that mode, so it should work.

 

But typically, you initially just set to '1' the bits corresponding  to the pins you want to use as outputs in SWACNT, then you control the output value by only writing to SWCHA.

So, to return them to 5v, while leaving the pins in output mode, you can write #%00010001 to SWCHA.

 

I think there are differences in how much current you can source from the pins when in input mode compared to output mode, but I'm not expert here, and it might not matter for your application, anyway.

 

Thanks for the reply. Will do some breadboard testing as I am not sure it will work.

 

I basically want to deactivate an external motor and set the pin back to input at the end of the frame. Pulling the Pin low in output mode is the only way I can think to do it without causing the Pin to register a button press at the same time.

 

The ASM code will actually swap between pins 1 and 2. If there is a collision detected while the JS is pushed up, then the motor will activate on pin 2. If the collision happens while the JS is pushed down, the motor will activate on pin 1.

 

This has to be reset at the end of every frame. I believe the worst case scenario in the form of directional lag is a delay of 1 frame before the Joystick direction is detected. But otherwise I think this will work to implement a rumble feature on a joystick.

 

As I will be using transistors that will only allow power to flow from the emitter to the collector, pin 7 power will only flow to the motor if either the pin 1 or pin 2 is pulled low (I don't know if I'm using the proper terminology - if the pin drops to 0V), and thus, when playing existing games, the joystick would act as originally intended as the power to the motor will always be off.

Share this post


Link to post
Share on other sites
16 hours ago, flickertail said:

... pin 7 power will only flow to the motor if either the pin 1 or pin 2 is pulled low (I don't know if I'm using the proper terminology - if the pin drops to 0V), and thus, when playing existing games, the joystick would act as originally intended as the power to the motor will always be off.

I don't think that would work: the joystick pulls either pin 1 or 2 low when moved 'up' or 'down',  therefore it will be activating the motor when moving it in those directions.

Doesn't matter if the pins are pulled low by the RIOT or by the switch inside the joystick: the result is the same.

 

I only have basic skills in electronics, so take the following with a grain of salt:


I think a way to make it work is to connect both pin 1 and 2 as inputs of an 'OR' gate (e.g a 7432 IC) and use the output of that gate as the signal to activate the motor (low=on, as before).
The output will be low only if both pin 1 and 2 are low at the same time, and while you can do that by setting those pins as output, it cannot accidentally happen simply by moving the stick.


As before, you cannot read the joystick and keep the motor running at the same time: you need to (briefly) set the pins as inputs to read the stick and during that time the motor would switch off. But that would take only a few CPU cycles, so shouldn't be a problem.


You can put another OR gate on pins 3 and 4 ('left' and right' directions) to add another function to the controller, or maybe combine it with the other gate to control a SR latch so that the motor can run continuously even while you're reading the stick...

 

Share this post


Link to post
Share on other sites
8 hours ago, alex_79 said:

I only have basic skills in electronics, so take the following with a grain of salt:


I think a way to make it work is to connect both pin 1 and 2 as inputs of an 'OR' gate (e.g a 7432 IC) and use the output of that gate as the signal to activate the motor (low=on, as before).
The output will be low only if both pin 1 and 2 are low at the same time, and while you can do that by setting those pins as output, it cannot accidentally happen simply by moving the stick.


As before, you cannot read the joystick and keep the motor running at the same time: you need to (briefly) set the pins as inputs to read the stick and during that time the motor would switch off. But that would take only a few CPU cycles, so shouldn't be a problem.


You can put another OR gate on pins 3 and 4 ('left' and right' directions) to add another function to the controller, or maybe combine it with the other gate to control a SR latch so that the motor can run continuously even while you're reading the stick...

 

Thanks for the advice. My electronic skills are less than basic. :D I appreciate the help.

Share this post


Link to post
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...