Can I pulse one digital out at 1khz and run other code at the same time

I need one output to do a 1khz pulse all of the time to a chop single to part of my circuit and I need to check for other inputs to move some servos at the same time. can the I multitask like that?

Yes.
Do a simple void loop, this will toggle an output bit hi, lo, every 500uS (0.5mS)

// all time related elements are type 'unsigned long'
previous_time = micros();
void loop(){
current_time = micros();
elapsed_time = current_time - previous_time();

if (elapsed_time >=500){
previous_time = current_time;
toggle = 1 - toggle;  // results in 1,0,1,0
digitalWrite (1KHzPin, toggle);
}

// do other code stuff, read sensors, etc

} // end void loop

Thanks will this work if
go from the main to a sub with a while loop some thing like this

or should I not make it a sub just put it in the main with in the if statement

void loop() 
{ 
  
   ~~~ I will put your code here
   
   scanswitchread = digitalRead(scanswitch);
   analogswitchread = digitalRead(analogswitch);
   
   if (scanswitchread == HIGH){
     testscan();
   }
   
   if (analogswitchread == HIGH){
     anlaogtest();
   }
     
   



} 


void anlaogtest(){
  digitalWrite(gainled,HIGH);      //turns on led soild so i know we are in this sub
  while (analogswitchread == HIGH) {    // will stay in this subuntill switch is turned off
       
    analogsensensorread= analogRead (analogsensensor);   //reading the analog vlaue
    Serial.println(analogsensensorread); 
  digitalWrite(intigrationreset, HIGH);    // setting intigration reseth high
  
   Serial.println("high");
 
    analogsensensorread= analogRead (analogsensensor);   //reading the analog vlaue
     Serial.println(analogsensensorread);    //printing the value
     delay(100);                    // waits 30ms for the servo to reach the position
 
  
  
  digitalWrite(intigrationreset, LOW);    // setting intigration reseth high
  Serial.println("low");
  delay(500);  
    analogsensensorreadt1= analogRead (analogsensensor);   //reading the analog vlaue
     Serial.println(analogsensensorreadt1);    //printing the value
 
     Serial.println("diffrence");
     
       directiondetermination=  analogsensensorread-analogsensensorreadt1; // calualates if it is + or -
    
      Serial.println(directiondetermination);
      Serial.println("------");
       
       
        if (directiondetermination > 0)
           {
             pospan=pospan+1;
             if (pospan >170){ pospan =170;}
             panservo.write(pospan);
           }
      if (directiondetermination < 0)
           {
             pospan=pospan-1;
             if (pospan <10){ pospan =10;}
             panservo.write(pospan);
           }
     
       
       
       analogswitchread = digitalRead(analogswitch); // reading the switch 
  }
}

You can also use an interrupt.

Edit: an example to set timer 1 to a specific speed

void setup() {
    // Calculate the speed. On my board, the line below results in 1200Hz.
    // Check F_CPU to know your clock speed. 
    long ocr1a = F_CPU / 1200;

    // WGM12 sets the waveform generation mode to 2 which means Clear Timer on Compare Match (the CompA value)
    // CS10 means no prescaling.
    // TCCRxA/B are used to set these bits (they are registers)
    TCCR1A = 0;
    TCCR1B = _BV(WGM12) | _BV(CS10);

    // The OCR1A value tells when the counter should reset (The CompA value). When the clock ticks, a counter adds one, 
    // until it hits your calculated value and resets. When that value is hit, an interrupt will occure, more precisely
    // the TIMER1_COMPA_vect interrupt.
    OCR1A = ocr1a;

    // The next lines enable the interrupt on different processor types.
#ifdef TIMSK1
    TIMSK1 |= _BV(OCIE1A);
#else
    TIMSK |= _BV(OCIE1A);
#endif
}

void loop()
{
//...
}

SIGNAL(TIMER1_COMPA_vect)
{
  // Handle the interrupts.
}

I would go with how I had it.
I do the same for a fencing (touche!) machine I have, only toggled faster - every 100uS.
After every write I read a bunch of other stuff, including checking for serial inputs (but if I get that, I generally don't care about the toggled output as something else has occurred instead).
I set two outputs hi or low, read several inputs to see if the outputs made it back on a different inputs or if it was shorted to ground, start 2ms & 40mS timers depending on what happened, turn on & off some LEDs.
That if statement & digitalWrite will take up very, very little time.

tbscope,
Can you modify that with some comments? Hard to tell what its doing for those of us coming from hardware design background vs seasoned C programmers.

Why not use this: http://arduino.cc/en/Reference/Tone?

Udo

Doesn't that keep you from doing other stuff at the same time?
I know it acts like a delay while I play a quick warble in my code.

Ah correct. Then go for PWM as already suggested. The explanations at Secrets of Arduino PWM are really good.

Udo

I tried to add some comments to the code above.
Note that I first learned about this a few days ago, so the comments might not be 100% correct but it's what I currently think it is.

You can do it with interrupts. But it is definitely better to do it as described in the PWM guideline. The timer can directly togle the output.

Udo

Thank you everyone. my code is running slow and I am not getting the 1k I am getting less. I will have to play with it. this is the first time I am using the arduino and the community is awesome.

Post the code you are running, lets see what is going on.

Use timer 0 or timer 2, its simple to setup a timer to output a nice 1Khz square wave.