From schematic diagram, switch S2 is a push button, which one should i use?
http://www.cytron.com.my/listProductGroup.php?pid=AQkyOTc2Gj0JCRYYAD0qItz/Y1sZ!!!!!oQalykjLb!!!!!FBoU=
void adc_start_conversion(void)
{
// Turn off PWM and let the back EMF become stable.
// While waiting, we will sample the other channels first.
OC1CONbits.OCM = 0;
OC2CONbits.OCM = 0;
// Select AN0 (Vin).
ADCHSbits.CH0SA = 0;
// Start sampling.
ADCON1bits.SAMP = 1;
// Delay 100uS.
__delay32(_XTAL_FREQ/40000);
// Stop sampling and start conversion.
ADCON1bits.SAMP = 0;
// Wait for conversion to finish.
while (ADCON1bits.DONE == 0);
// Save the value.
sui_adc_supply = (signed int)ADCBUF0;
// Select AN1 (Acc - X).
ADCHSbits.CH0SA = 1;
// Start sampling.
ADCON1bits.SAMP = 1;
// Delay 100uS.
__delay32(_XTAL_FREQ/40000);
// Stop sampling and start conversion.
ADCON1bits.SAMP = 0;
// Wait for conversion to finish.
while (ADCON1bits.DONE == 0);
// Save the value.
sui_adc_acc_x = (signed int)ADCBUF0;
// Select AN3 (Gyro).
ADCHSbits.CH0SA = 3;
// Start sampling.
ADCON1bits.SAMP = 1;
// Delay 100uS.
__delay32(_XTAL_FREQ/40000);
// Stop sampling and start conversion.
ADCON1bits.SAMP = 0;
// Wait for conversion to finish.
while (ADCON1bits.DONE == 0);
// Save the value.
sui_adc_gyro = (signed int)ADCBUF0;
// Select AN4 (Left Motor Voltage - 1).
ADCHSbits.CH0SA = 4;
// Start sampling.
ADCON1bits.SAMP = 1;
// Delay 100uS.
__delay32(_XTAL_FREQ/40000);
// Stop sampling and start conversion.
ADCON1bits.SAMP = 0;
// Wait for conversion to finish.
while (ADCON1bits.DONE == 0);
// Save the value.
si_adc_left_motor_1 = (signed int)ADCBUF0;
// Select AN5 (Left Motor Voltage - 2).
ADCHSbits.CH0SA = 5;
// Start sampling.
ADCON1bits.SAMP = 1;
// Delay 100uS.
__delay32(_XTAL_FREQ/40000);
// Stop sampling and start conversion.
ADCON1bits.SAMP = 0;
// Wait for conversion to finish.
while (ADCON1bits.DONE == 0);
// Save the value.
si_adc_left_motor_2 = (signed int)ADCBUF0;
// Select AN6(Right Motor Voltage - 1).
ADCHSbits.CH0SA = 6;
// Start sampling.
ADCON1bits.SAMP = 1;
// Delay 100uS.
__delay32(_XTAL_FREQ/40000);
// Stop sampling and start conversion.
ADCON1bits.SAMP = 0;
// Wait for conversion to finish.
while (ADCON1bits.DONE == 0);
// Save the value.
si_adc_right_motor_1 = (signed int)ADCBUF0;
// Select AN7 (Right Motor Voltage - 2).
ADCHSbits.CH0SA = 7;
// Start sampling.
ADCON1bits.SAMP = 1;
// Delay 100uS.
__delay32(_XTAL_FREQ/40000);
// Stop sampling and start conversion.
ADCON1bits.SAMP = 0;
// Wait for conversion to finish.
while (ADCON1bits.DONE == 0);
// Save the value.
si_adc_right_motor_2 = (signed int)ADCBUF0;
// Turn on PWM.
OC1CONbits.OCM = 0b110;
OC2CONbits.OCM = 0b110;
// At last, before we exit, we start sampling AN0 (Vin) as it has a low output impedance.
ADCHSbits.CH0SA = 0;
// Start sampling.
ADCON1bits.SAMP = 1;
}
Return to ROBOT. Head to Toe Magazine
Users browsing this forum: No registered users and 1 guest