Help with pots/interrupts

Arg! I’ve hit the wall. Unfortunately, the responsibility of getting all of our electronics/programming is heavily on me, and I’ve come to a dead end. I’ve gotten about 3 hours of sleep in as many days, and the deadline is approaching … and the only reason I have time to post here is because I’m about to take a linear algebra test, and had to stop working on the robot temporarily for the night, so I’m somewhat streched for nerves, but here goes:

We’re trying to use pots to get finer control. I put a multimeter on the ground/signal leads of the pwm cable it is attached to, and I get 0-10k Ohms varying like it should – so it seems to me that the wiring is okay. It is plugged into analog input 1. In the program I say:

printf ("The pot value is: %d
", (int) rc_ana_in01);

Yet the print statement prints the same value over and over again, even when the pot is being turned! Any insight, or debugging suggestions would be greatly appreciated.

And, being held up in that matter, I turned to work on the autonomous mode. I had it working fine for the EduBot. I changed out the version for the FRC, and tried to get that working. After a while, I isolated the problem to figuring out that the Clock variable is 0 – and never increases. The timer 1 interrupt is programmed, straight from Ken Watson as a matter of fact … yet it doesn’t increment. I realize some code might help, but as I said, I’m about to take a test and the code is on the team laptop, so I’ll get around to it sometime tomorrow maybe.

Thank you,
A much distressed programmer.

printf ("The pot value is: %d
", (int) rc_ana_in01);

You need to use:

unsigned int pot_value;
pot_value = Get_Analog_Value(rc_ana_in01);
printf ("The pot value is: %d
", (int) pot_value);

Edit: Hey Ken, I’m only a two finger typist. I work on too many different types of keyboards to type the normal way anymore. Those vendors keep moving the keys around, so I have to hunt and peck.

two things with your pot.

it has to be wired to the +5V pin on one end, gnd at the other, with the signal on the middle terminal of the pot - at the analog in connector on the RC, the wires are black= gnd, red (middle) = +5 and white = signal.

if you put a voltmeter on the center and gnd pins of the pot you should see it range from 0 to 5 VDC as you turn the pot (with the RC on)

the RC is different from wireing pots to the OI - the RC needs to see an actual voltage.

the other problem is you must use the ‘get_analog_value’ function to read the analog inputs - check the analog input section of the default users guide - the correct syntax is in there. (or just read Marks post for the right code cause he types faster than I do :c)

Thanks for the help. Who would have thought that sleep depravation, loud noise, small rooms, and flying metal sparks wouldn’t have been the optimum environment for programming? It is sad, sad day …

Anyway, I’ll post that code now.

  static unsigned int Old_Clock = 0;
  static unsigned char drive_timer = 0;
    /* Add your own autonomous code here. */
    if (Clock > Old_Clock)
	switch (Navigator_State) { ... }
    Old_Clock = Clock; // take a snapshot of the clock

For some reason the clock is not increasing. Now, since we are presently making our auton switch, I did some kludging to get it called; I called User_Autonomous_Mode (where this code is at) from Process_Data_From_Local_uP, and edited as such:

//  while (autonomous_mode)   /* DO NOT CHANGE! */
   while (1) // just so auto is executed now, for testing
    if (statusflag.NEW_SPI_DATA)      /* 26.2ms loop area */
        Getdata(&rxdata);   /* DO NOT DELETE, or you will be stuck here forever! */



        Putdata(&txdata);   /* DO NOT DELETE, or you will get no PWM outputs! */

I think the problem might be that I have the code in the 26.2ms loop area – or at least I have an inclination I don’t want it there. But would that explain why the timer interrupt doesn’t appear to be interrupting? Maybe I copied the code down incorrectly when switching from Edu to RC. Thanks for all the help …

Also, I don’t know if it is a typo or not, but you should be using 100K ohm pots, not 10K, unless you only want 1/10th the resolution.

You can get some sleep after the robot ships.
Oh, wait you’re a programmer!
No sleep until after Nationals!!!

As for your Clock…

A likely reason for the non-interrupting interrupt is incorrect initialization.
I assume you are using Kevin’s edu_clock_demo_2 example?
I’ll run through the obvious. Since you are sleep deprived double check all these even if you are sure you did them already.

  • Are you calling Initialize_Timer_2(); from User_Initialization()?
  • Are you using any other code that might be trying to utilize Timer 2 as well(e.g., beacon s/w)?
  • Calling Timer_2_Int_Handler() from the interrupt handler in user_routines_fast.c?
  • Clearing the timer interrupt flag?
  • Make any mods to the clock_demo_2.c file?
  • Including “clock_demo_2.h” in user_routines.c?

Just a side note about pots, we experimented with some different values, and the 10k pots seem to work fine, with about the same resolution as the 100k ones. You might get some slightly different scaling, but as long as all of your pots are the same value you shouldn’t run into many problems.

Actually, it doesn’t alter the amount of resolution you have. What it does do is raise the amount of current flowing through the potentiometer. As the currents involved in both cases are miniscule (100K = 50uA, 10K = 500uA), I’d go ahead and use the 10K.


Yep, I realized that after I posted. I had a brainfart and originally was thinking that the RC somehow measured resistance. But of course, it measures the voltage, and that will be the same for the 100K and 10K.

Err…, I was thinking 10 turn pot when I wrote 10K (it is 100K for the record).

And it was a silly, stupid mistake. I realized it sitting in english, that when transferring the Edu Code to the RC code I didn’t change the User Init function to call Initialize_Tracker(). Thanks for all the help. It sure would be a lot easier if I didn’t have a million tests this week (just finished one right now, and off to the robot, where we found out we have a bad speed controller) … oh well, it always works out … right? err…

About competition: Bring Spares. Lots of them. And backup code. And the computer to download from. And docs. And… :slight_smile: