Author Topic: Programming rapid fire in C ,quick question  (Read 3707 times)

Offline carjason19

  • Guppy
  • *
  • Posts: 4
  • Post quality +0/-0
  • Acidmods User
Programming rapid fire in C ,quick question
« on: October 07, 2012, 10:00:52 AM »
If the micro controller try’s to force this signal low to the trigger pot,will it short out the power supply? if then how does rapid fire work?
« Last Edit: October 07, 2012, 10:48:07 AM by carjason19 »
xbox live: carjason19

Offline SethMods

  • Registered BST
  • King of the Wii-tards
  • *
  • Posts: 189
  • Post quality +17/-1
  • Gender: Male
  • Acidmods User
Re: Programming rapid fire in C ,quick question
« Reply #1 on: October 07, 2012, 11:31:58 AM »
No, it won't short out the power supply. Theoretically it could, but I can tell you from experience that it won't.

You should be able to drive them high or low without any problems. The exception comes in with the Matrix2 board. Driving too high can cause some "erratic" behaviour. The controller expects a voltage between 0V and 1.6V. Driving to Vdd (~3V) is just too much some times.


As far as how rapid fire works,...

There are a few different ways. If you are only wanting to do rapid fire, then the easiest and probably most popular approach (at least on this site) is to toggle between Input and Output(Trigger Release).

So for instance let's say you are using a CG/CG2 style controller. Then driving the trigger high will simulate a trigger pull while driving the pin low will simulate a trigger release. We don't care about driving it high in this case though, because we are toggling between input and output-low.

So to simulate 10 Shots per second rapid fire you would have something like this.
while(1)
{
  //Set RT to output
  TRISIObits.TRISIOX = 0;
  //Force trigger release
  GPIObits.GPIOX = 0;
 
  //Wait 50 ms
  __delay_ms(50);

  //Set RT to input
  TRISIObits.TRISIOX = 1;

  //Wait 50 ms
  __delay_ms(50);

}


When the trigger is NOT being pulled then the mod toggles between "Releasing the trigger" and whatever the state of the trigger really is...which is a released trigger. So nothing happens.

When the trigger IS being pulled then the mod toggles between "Releasing the trigger" and the state of the trigger (which is pulled).

So this gives you rapid fire.


There are three other approaches that I know of though.
One is to use the Comparator to detect trigger pulls and then to respond in a macro fashion accordingly.

The another way is to use Analog to Digital conversion to detect the trigger pulls and then to respond.

And the last way is to use regular digital inputs to read the trigger pulls. (I don't recommend this way though.)

Note: Matrix/Matrix2 controllers are opposite of CG/CG2 for the triggers. Driving them high represents a trigger release while driving them low represents a trigger pull.

I hope this helps.

Offline carjason19

  • Guppy
  • *
  • Posts: 4
  • Post quality +0/-0
  • Acidmods User
Re: Programming rapid fire in C ,quick question
« Reply #2 on: October 07, 2012, 01:29:05 PM »
Thanks SethMods your awesome. your work is phenomenal.
xbox live: carjason19

Offline SethMods

  • Registered BST
  • King of the Wii-tards
  • *
  • Posts: 189
  • Post quality +17/-1
  • Gender: Male
  • Acidmods User
Re: Programming rapid fire in C ,quick question
« Reply #3 on: October 07, 2012, 03:33:16 PM »
No problem. Let us know if you have any other questions.

And I appreciate the compliment. What I have done pales in comparison to some of the guys on here though.

Offline carjason19

  • Guppy
  • *
  • Posts: 4
  • Post quality +0/-0
  • Acidmods User
Re: Programming rapid fire in C ,quick question
« Reply #4 on: October 09, 2012, 03:15:03 PM »
I just do not understand what is going on with the trigger circuit as it is both an input and an output together at the same time?
xbox live: carjason19

Offline SethMods

  • Registered BST
  • King of the Wii-tards
  • *
  • Posts: 189
  • Post quality +17/-1
  • Gender: Male
  • Acidmods User
Re: Programming rapid fire in C ,quick question
« Reply #5 on: October 10, 2012, 12:55:48 PM »
I keep rewriting this reply, and everytime I get about halfway through I think you might be asking a different question so I start all over.

The triggers are potentiometers as Matt stated. What that means is that of the three terminals for the trigger the two outside posts represent the + and - voltage that is being fed into the potentiometer itself.

The middle post is going to reflect a voltage somewhere in the middle of the + and - based on how far the trigger is pulled.

On a CG controller with the trigger all the way pulled the middle post is going to be very close to the + voltage being fed in. With the trigger released the middle post is going to be very close to the - voltage being fed into that potentiometer.

The important thing to note is that the middle post goes directly back to the microcontroller that runs the controller itself and is always being "listened to" by the microcontroller.

When we make our mods we override whatever voltage the potentiometer is "trying" to show and impose our own. The microcontroller "hears" our voltage that we made with our PIC and thinks it is coming from the trigger. The voltage made by the potentiometer in the trigger is (theoretically) completely overriden. (Real life is messier than that, but fortunately we don't have to bother ourselves with it.)

Comparators are a popular approach to reading the trigger and then having the mod jump in to respond, but I think they may be the most complicated.

Whichever method you decide to use, let me know and I will try to help you work through the coding aspect.
« Last Edit: October 10, 2012, 01:46:41 PM by SethMods »

 

SMF spam blocked by CleanTalk
SimplePortal 2.3.5 © 2008-2012, SimplePortal