From: Marq R. <mar...@ya...> - 2008-01-22 02:12:57
|
I am trying to control 6 different servos based on feedback from an IMU and have servos 3A-C up and working. When I use servos 1A-C the robositx powers down and resets so I assume that I am initializing the ports or timers wrong and was wondering if you guys would take a look. -------------------------------------------------------------------------------------------------------------- const char *i2cDevName = "/dev/i2c-0"; int i2cDev; int gI2cAddr = 0x0B; int ch1 = 0x86;// register address for OCR3A int ch2 = 0x84;// register address for OCR3B int ch3 = 0x82;// register address for OCR3C int ch4 = 0x2A;// register address for OCR1A int ch5 = 0x28;// register address for OCR1B int ch6 = 0x78;// register address for OCR1C if (( i2cDev = open( i2cDevName, O_RDWR )) < 0 ) { LogError( "Error opening '%s': %s\n", i2cDevName, strerror( errno )); exit( 1 ); } I2cSetSlaveAddress( i2cDev, gI2cAddr, I2C_USE_CRC ); /*# Set COM mode to 2. This causes the OCR pin to fall when the timer # reaches the value stored in the OCR register and causes the OCR pin # to rise when the counter gets reset to zero. # # Use a divide by 8 prescalar, which gives a 2MHz clock which will # overflow every 32.7 msec, which is suitable for driving R/C servos*/ //Setup timer 1 I2C_IO_WriteReg8( i2cDev, 0x2F, 0xAA ); //REG_IO8("TCCR1A", 0x2F) I2C_IO_WriteReg8( i2cDev, 0x2E, 0x1A ); //REG_IO8("TCCR1B", 0x2E) I2C_IO_WriteReg16( i2cDev, 0x26, 4000 ); //REG_IO8("ICR1", 0x26) I2C_IO_WriteReg16( i2cDev, 0x2C, 0 ); //REG_IO8("TCNT1", 0x2C) //Setup timer 3 I2C_IO_WriteReg8( i2cDev, 0x8B, 0xAA ); //REG_IO8("TCCR3A", 0x8B) I2C_IO_WriteReg8( i2cDev, 0x8A, 0x1A ); //REG_IO8("TCCR3B", 0x8A) I2C_IO_WriteReg16( i2cDev, 0x80, 4000 ); //REG_IO8("ICR3", 0x80) I2C_IO_WriteReg16( i2cDev, 0x88, 0 ); //REG_IO8("TCNT3", 0x88) //Move servos to home position I2C_IO_WriteReg16( i2cDev, ch1, servo1*2 );//ch1= throtle I2C_IO_WriteReg16( i2cDev, ch2, servo2*2 );//ch2= roll left I2C_IO_WriteReg16( i2cDev, ch3, servo3*2 );//ch3= pitch I2C_IO_WriteReg16( i2cDev, ch4, servo4*2 );//ch4= yaw I2C_IO_WriteReg16( i2cDev, ch5, servo5*2 );//ch5= switch I2C_IO_WriteReg16( i2cDev, ch6, servo6*2 );//ch6= roll right //Set DDR registers for ports B and E I2C_IO_SetGPIODir( i2cDev, 0x18, 224, 224 ); //REG_IO8("PORTB",0x18),224 = pins 5,6, and 7 are output I2C_IO_SetGPIODir( i2cDev, 0x18, 56 , 56 ); //REG_IO8("PORTE",0x03),56 = pins 3,4, and 5 are output ---------------------------------------------------------------------------------------------------------------------------------------------------- thanks for your help -Marq -- View this message in context: http://www.nabble.com/Problems-getting-servos-1A-C-working-tp15011216p15011216.html Sent from the Gumstix mailing list archive at Nabble.com. |