Page 3 of 4

Re: Magazine Mar2010 vol.4 [2 wheeled balancing robot]

PostPosted: Sat Feb 04, 2012 3:50 pm
by choyhong88
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=

Re: Magazine Mar2010 vol.4 [2 wheeled balancing robot]

PostPosted: Sat Feb 04, 2012 9:19 pm
by robosang
Ar? Why need to follow the switch type? Din check the schematic, but does it matter whether I use any of switches available? It just outlook, size and pin count. You can use any switch that connect and disconnect 2 terminal, I can even use mini jumper and header pin.

Re: Magazine Mar2010 vol.4 [2 wheeled balancing robot]

PostPosted: Sat May 12, 2012 6:49 pm
by choyhong88
The circuit schematic is edited based on cytron's balancing robot

correction to the diagram: forget to put +3V3 to MCP602 for this schematic diagram

Re: Magazine Mar2010 vol.4 [2 wheeled balancing robot]

PostPosted: Sat May 12, 2012 7:53 pm
by choyhong88
after assembly and built the circuit based on the above post.
i the compile the code provided by the magazine and load the hex file into the chip, the motor hav no any respond all even i try to turn the circuit board around every axis to see whether the motor turning or not.
Since i dont want to control the robot wirelessly, i remove the uart_initialize(),
may i know what else should i take alert to edit the code? please give some hint, i hav no idea...

Re: Magazine Mar2010 vol.4 [2 wheeled balancing robot]

PostPosted: Tue May 15, 2012 4:21 pm
by ober
Have you check the code? I think the code have a start button. Do you have the start button and have you press the start button?

Re: Magazine Mar2010 vol.4 [2 wheeled balancing robot]

PostPosted: Tue May 15, 2012 10:20 pm
by choyhong88
the switch(start button) is near the bottom of the microcontroller which is also equvalent to the S2 in the schematic diagram ,am i right? i did press the button, but the motor no respond.

Re: Magazine Mar2010 vol.4 [2 wheeled balancing robot]

PostPosted: Wed May 16, 2012 10:23 am
by waiweng83
Have you make sure that your MCU is actually running? You can write a simple LED blinking program to ensure it.
This project is not a plug and play project. Do not expect to simply copy the schematic and download the firmware, it will works out of the box magically.
Furthermore, you are using a different MCU than the example, although this shouldn't be a problem.

So for a good start, write a simple program to test your circuit and make sure it's functioning, part by part. You can start from a LED first, then followed by switch motor and etc.

Re: Magazine Mar2010 vol.4 [2 wheeled balancing robot]

PostPosted: Thu May 17, 2012 10:23 pm
by choyhong88
hav tested with simple LED blinking...................................working
tested with direct driving motor but without PWM............working

Re: Magazine Mar2010 vol.4 [2 wheeled balancing robot]

PostPosted: Fri May 18, 2012 9:55 am
by waiweng83
How about with PWM?
Try using the drive_motor() function in the sample source code. Remember to initialize the PWM before calling the function.

Re: Magazine Mar2010 vol.4 [2 wheeled balancing robot]

PostPosted: Fri May 18, 2012 5:48 pm
by choyhong88
i have some doubt in the provided source code, filename adc.c

why all the adc result is put in (signed int)ADCBUF0? will each of the result overwrite the previous result, then in the end we will only obtain the adc result for si_adc_right_motor_2 and the rest of result is gone? :?


CODE: SELECT_ALL_CODE
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;
}       


should we save the adc value in this way

sui_adc_supply = (signed int)ADCBUF0;
sui_adc_acc_x = (signed int)ADCBUF1;
sui_adc_gyro = (signed int)ADCBUF2;
si_adc_left_motor_1 = (signed int)ADCBUF3;
si_adc_left_motor_2 = (signed int)ADCBUF4;
si_adc_right_motor_1 = (signed int)ADCBUF5;
si_adc_right_motor_2 = (signed int)ADCBUF6;


And another doubt, the circuit diagram show that using 2 out of the 3 axis in accelerometer but in the source code only 1 axis is need. So, acually 1axis + 1 gyro rate are enough for balancing ..