Skip to content
Snippets Groups Projects
Commit a3567998 authored by Patrick John Grosch Obregon's avatar Patrick John Grosch Obregon
Browse files

rx28 firmware interrupt ctrl cycle and read potenciometer work (faltaba en...

rx28 firmware interrupt ctrl cycle and read potenciometer work (faltaba en CFG_HW file activar timer)
parent c69d22fc
No related branches found
No related tags found
No related merge requests found
...@@ -44,9 +44,9 @@ void Config_Hardware(void) { ...@@ -44,9 +44,9 @@ void Config_Hardware(void) {
1 0 0 Clock / 256 1 0 0 Clock / 256
1 0 1 Clock / 1024 */ 1 0 1 Clock / 1024 */
/*TCCR0 |= (1 << CS02)| (0<<CS01)| (0<<CS00); // clk src with prescaler 256 TCCR0 |= (1 << CS02)| (0<<CS01)| (0<<CS00); // clk src with prescaler 256
TIMSK |= (1 << TOIE0); // Enable interrupt timer 0*/ TIMSK |= (1 << TOIE0); // Enable interrupt timer 0
/* timer/counter0 limitations.. no CTC mode. /* timer/counter0 limitations.. no CTC mode.
* so move starting point to where needed * so move starting point to where needed
......
#include <avr/io.h> #include <avr/io.h>
#include <util/delay.h> #include <util/delay.h>
#include <avr/interrupt.h> #include <avr/interrupt.h>
//#include <avr/eeprom.h> #include <avr/eeprom.h>
#include "CFG_HW_Dynamixel.h" #include "CFG_HW_Dynamixel.h"
//#include "TXRX_Dynamixel.h" //#include "TXRX_Dynamixel.h"
#include "CTRL_Dynamixel.h" #include "CTRL_Dynamixel.h"
...@@ -18,26 +18,19 @@ ISR( TIMER0_OVF_vect) { ...@@ -18,26 +18,19 @@ ISR( TIMER0_OVF_vect) {
//cli(); // disable all interrupts just to make sure //cli(); // disable all interrupts just to make sure
TorqueEnable = Read_byte_Dynamixel_RAM(Torque_Enable); TorqueEnable = Read_byte_Dynamixel_RAM(Torque_Enable);
if (TorqueEnable == 1) { if (TorqueEnable == 1) {
//if (0) { ENABLE_MOTOR;
//ENABLE_MOTOR;
DISABLE_MOTOR;
count++; count++;
count2=Read_Sensor(CTRL_Encoder_Port); if (count == 1) {
//if (count == 1) { //LedTOGGLE;
if (count > count2) { Control_Cycle();
LedTOGGLE; HW_Security();
//Control_Cycle(); Write_Actuator();
//HW_Security();
//Write_Actuator();
count = 0;
}
if (count == 1023) {
count = 0; count = 0;
} }
} else { } else {
DISABLE_MOTOR; DISABLE_MOTOR;
SET_CCW_PWM_MOTOR(0); //PB1 => set PWM for X% duty cycle max 0x3ff o 1023 // funciona SET_CW_PWM_MOTOR(0); //PB1 => set PWM for X% duty cycle max 0x3ff o 1023 // funciona
SET_CW_PWM_MOTOR(0); //PB2 => set PWM for Y% duty cycle max 0x3ff o 1023 // funciona SET_CCW_PWM_MOTOR(0); //PB2 => set PWM for Y% duty cycle max 0x3ff o 1023 // funciona
//LedTOGGLE; //LedTOGGLE;
} }
} }
...@@ -46,22 +39,21 @@ ISR( TIMER0_OVF_vect) { ...@@ -46,22 +39,21 @@ ISR( TIMER0_OVF_vect) {
int16_t main(void) { int16_t main(void) {
unsigned char data[128], id, length, instruction, answer[2], status, unsigned char data[128], id, length, instruction, answer[2], status,
en_vector, i, j; en_vector, i, j;
uint16_t ii, jj;
// list of read only registers - to exclude from write // list of read only registers - to exclude from write
/*unsigned char read_only_vector[30] = { 0, 1, 2, 36, 37, 38, 39, 40, 41, 42, /*unsigned char read_only_vector[30] = { 0, 1, 2, 36, 37, 38, 39, 40, 41, 42,
43, 44, 45, 46, 67, 68, 71, 72, 73, 74, 75, 76, 77, 78, 79, 80, 83, 43, 44, 45, 46, 67, 68, 71, 72, 73, 74, 75, 76, 77, 78, 79, 80, 83,
84, 85, 86 };*/ 84, 85, 86 };*/
// ini eeprom if first time after run reflash system // ini eeprom if first time after run reflash system
/*if (eeprom_read_byte((uint8_t*) Gate_Restore_Eeprom) != 0xCC) { if (eeprom_read_byte((uint8_t*) Gate_Restore_Eeprom) != 0xCC) {
Restore_Eeprom_Factory_Values(); //once this procedure is held, no more initialization is performed Restore_Eeprom_Factory_Values(); //once this procedure is held, no more initialization is performed
//blinkLedN(3); }
}*/
//------EEPROM initial values------------- //------EEPROM initial values-------------
/*Restore_EepromVAR(); Restore_EepromVAR();
//blinkLedN(5); // get value of Motor ID
// get value of Motor ID //rs485_address = eepromVAR[ID];
rs485_address = eepromVAR[ID];*/
// configure AVR chip i/o // configure AVR chip i/o
Config_Hardware(); Config_Hardware();
...@@ -72,8 +64,20 @@ int16_t main(void) { ...@@ -72,8 +64,20 @@ int16_t main(void) {
// end of inicialization // end of inicialization
LedOFF; LedOFF;
ii = 0;
jj=1;
while (1) { while (1) {
Write_word_Dynamixel_RAM(Goal_Position_L,ii);
_delay_ms(500); // funciona
//ii=500;
ii = ii + 100*jj;
LedTOGGLE;
if (ii == 900) {jj=-1;}
if (ii == 100) {jj=1;}
/*status = RxRS485Packet(&id, &instruction, &length, data); /*status = RxRS485Packet(&id, &instruction, &length, data);
if (status == CHECK_ERROR) { if (status == CHECK_ERROR) {
TxRS485Packet(rs485_address, CHECKSUM_ERROR, 0, NULL); TxRS485Packet(rs485_address, CHECKSUM_ERROR, 0, NULL);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment