Skip to content

Commit

Permalink
final
Browse files Browse the repository at this point in the history
  • Loading branch information
omarwalid96 committed Jul 22, 2017
1 parent b7c21c9 commit 943c9f9
Show file tree
Hide file tree
Showing 88 changed files with 3,341 additions and 3,109 deletions.
239 changes: 148 additions & 91 deletions Robot 1 tiva/ADC.c

Large diffs are not rendered by default.

11 changes: 7 additions & 4 deletions Robot 1 tiva/ADC.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,20 @@
#include "MotorInit.h"

extern uint32_t ADC0Value[8] ;
extern uint32_t SHARP[1] ;

extern uint32_t IR[3] ;
extern uint32_t V_L[2] ;
extern int sensor_lifter1 , sensor_lifter3;
extern int ls1 ,ls2 , ls3 ,ls4 ,ls5 ,ls6 ,ls7 ,ls8;
extern int VL ;
extern uint32_t V1,V2,V3,V4,V5,V6,V7,V8;
extern uint32_t previous[8];



void calibration();
void init_adc();
void data_get_SS0 (uint32_t *pt , int i );
void data_get_SS1 (uint32_t *pt , int i );
void data_get_ss0 (uint32_t *pt , int i );
void data_get_ss1 (uint32_t *pt , int i );
void digital_reads(uint32_t *ADC );
void line ();
void VerticalLines();
Expand Down
59 changes: 32 additions & 27 deletions Robot 1 tiva/MotorInit.c
Original file line number Diff line number Diff line change
Expand Up @@ -184,19 +184,21 @@ void PWME_Init()
{
//RCGCPWM |=0x01; // enable clock to PWM0
RCGCGPIO |= 0x10; // activate clock for Port E
// RCGCADC |= 0x01; //adc0 Module clock clock
GPIODATA_PORTE &= ~0x3F; // Initialize data register
GPIOAMSEL_PORTE &= ~0x33; // disable analog
GPIOAFSEL_PORTE |= 0x3C; // activate alternate function for 2,3,4,5
GPIOAFSEL_PORTE |= 0x30; // activate alternate function for 3,4,5
// GPIODEN_PORTE &= ~0x04;
//GPIOAMSEL_PORTE |= 0x04;
GPIOPCTL_PORTE &= ~0x00FF0000; //initialize pctl
GPIOPCTL_PORTE |= 0x00440000; //enable pctl PWMMO pin 4,5
GPIODEN_PORTE &= ~0x0C; // digital disable for 2,3 GPIOAMSEL_PORTE |= 0x0C; // enable analog function for 2,3
GPIODIR_PORTE |= 0x03; // set direction of 0,1 as outputs
GPIODIR_PORTE |= 0x03; // set direction of 0,1,2 as outputs
GPIODIR_PORTE &= ~0x04;
GPIODR8R_PORTE |= 0x3D;
GPIOPUR_PORTE |=0x33;
GPIOPUR_PORTE |=0x37;
GPIOSLR_PORTE |= 0xFF;
// GPIOODR_PORTE |= 0x01;
GPIODEN_PORTE |= 0x33; // digital enable for 0,1,4,5
// RCGCADC |= 0x01;
GPIODEN_PORTE |= 0x37; // digital enable for 0,1,4,5

PWM0_CTL_2 = 0x00; // stop counter generator 3
PWM0_GENA_2 |= 0x0000008C ; // M0PWM4 output set when reload clear when match PWM CMP A ch4
Expand Down Expand Up @@ -226,7 +228,7 @@ void PWME_Init()
GPIODIR_PORTB &= ~0xC0; // set direction of 6,7 as inputs
GPIOAFSEL_PORTB |= 0x30; // enable alternate function for 4,5
GPIODEN_PORTB &= ~0x30; // digital disable for 4,5
//GPIOAMSEL_PORTB |= 0x30; // enable analog function for 4,5
GPIOAMSEL_PORTB |= 0x30; // enable analog function for 4,5
GPIODEN_PORTB |= 0xC3; // digital enable for 0,1,6,7

/*
Expand All @@ -251,7 +253,6 @@ void PWME_Init()
GPIODIR_PORTC |= 0xC0; // set direction of 6,7 as outputs
GPIODR8R_PORTC |= 0x30;
GPIOPUR_PORTC |=0x30;
// GPIOSLR_PORTC |= 0x30;
GPIODEN_PORTC |= 0xF0; // digital enable for 4,5,6,7

PWM0_CTL_3 = 0x00; // stop counter generator 3
Expand Down Expand Up @@ -321,6 +322,8 @@ void PortF_Init()
GPIOCR_PORTF = 0x1F; // allow changes to 0 and 4
GPIOAFSEL_PORTF |= 0xF; // Alternate function pins select 0,1,2,3
GPIODIR_PORTF |= 0x10; // set direction of 4 as output
//GPIODR8R_PORTF |= 0x1F;
// GPIOPUR_PORTF |=0x1F;
GPIODEN_PORTF |= 0x1F; // Digital enable pins 0,1,2,3,4
GPIOPCTL_PORTF &= ~0x0000FFFF ; // Initialize PCTL
GPIOPCTL_PORTF |= 0x00002222 ; // set alternate functions SSI
Expand Down Expand Up @@ -359,7 +362,7 @@ RCGCGPIO |=0x3F;
PWMD_Init(); // Direction M5 M6 + ADC
PWME_Init(); // PWM M5 M6 + Direction M3 M7 + ADC
PortF_Init(); // SPI communication slave
// init_adc_3pins();
// init_adc_3pins();
SysTick_Init();
digitalWrite(ServePiston,LOW);
digitalWrite(ServeMotorCW,LOW);
Expand All @@ -370,17 +373,19 @@ digitalWrite(ServeMotorCCW,LOW);

void TIVA2() // initialization of tiva 2 (Base , LINE follower , base sensors)
{
//RCGCGPIO |=0x3E;
RCGCPWM |=0x03; // enable clock to PWM0 & PWM1
RCGCGPIO |= 0x3E; // port D, E clock
RCGCADC |= 0x1; //adc0 clock
RCGCPWM |=0x03; // enable clock to PWM0 & PWM1
RCC &= ~0x00100000 ; // don't use pre-divide for PWM clock (default)
ADCB_Init();
ADCC_Init();
ADCD_Init();
ADCE_Init();
PortF_Init();
//init_adc_8pins();
init_adc_8pins();
//init_adc_2pins();
SysTick_Init();
//SysTick_Init();
calibration();
}


Expand All @@ -393,34 +398,34 @@ void init_adc_3pins()
*/
//RCGCADC |= 0x01; //adc0 Module clock clock
ADCACTSS_ADC0 &=~0x01 ; // disable SS0 during configartion
ADCSSPRI_ADC0 |= 0x3210; // Set the highest piriority for SS0 (the highest pirority 0x0)
ADCSSPRI_ADC0 = 0x3210; // Set the highest piriority for SS0 (the highest pirority 0x0)
ADCEMUX_ADC0 &= ~0x000F; // software trigger for sequencer 0
ADCSSMUX0_ADC0 &= ~0xFFFFFFFF; // mask register bits
ADCSSMUX0_ADC0 = 0x701; //10
ADCSSMUX0_ADC0 = 0x1; //10
/*
if PE3 - (AIN0) ==>> (HEX(0x0000)) (DEC(0))
else if PE2 - (AIN1) ==>> (HEX(0x0001)) (DEC(1))
else if PE2 - (AIN1) ==>> (HEX(0x0001)) (DEC(1))
else if PD1 - (AIN6) ==>> (HEX(0x0006)) (DEC(6))
else if PD0 - (AIN7) ==>> (HEX(0x0007)) (DEC(7))
*/
ADCSSCTL0_ADC0 |= 0x0644; // (0x6) for ending squence and enable interrupt , (0x4) enable interrupt only
ADCSSCTL0_ADC0 |= 0x6; // (0x6) for ending squence and enable interrupt , (0x4) enable interrupt only
ADCACTSS_ADC0 |=0x01 ; // Enable SS0

}

void init_adc_8pins()
{
volatile unsigned long delay;
// RCGCGPIO |= 0x18; // port D, E clock
// RCGCADC |= 0x1; //adc0 clock
volatile unsigned long delay;
// RCGCGPIO |= 0x18; // port D, E clock
// RCGCADC |= 0x1; //adc0 clock
// port E initialization
// GPIOAFSEL_PORTE |= 0x0F; // PE 0,1,2,3 alterntae function enable
// GPIODEN_PORTE &= ~0x0F; // PE 0,1,2,3 digital function disable
// GPIOAMSEL_PORTE |= 0x0F; // PE 0,1,2,3 analog function enable
GPIOAFSEL_PORTE |= 0x0F; // PE 0,1,2,3 alterntae function enable
GPIODEN_PORTE &= ~0x0F; // PE 0,1,2,3 digital function disable
GPIOAMSEL_PORTE |= 0x0F; // PE 0,1,2,3 analog function enable
// port D initialization
// GPIOAFSEL_PORTD |= 0x0F; // PD 0,1,2,3 alterntae function enable
// GPIODEN_PORTD &= ~0x0F; // PD 0,1,2,3 digital function disable
// GPIOAMSEL_PORTD |= 0x0F; // PD 0,1,2,3 analog function enable
GPIOAFSEL_PORTD |= 0x0F; // PD 0,1,2,3 alterntae function enable
GPIODEN_PORTD &= ~0x0F; // PD 0,1,2,3 digital function disable
GPIOAMSEL_PORTD |= 0x0F; // PD 0,1,2,3 analog function enable

// ADC 0 init
/* PE0 PD0 PD1 PD2 PD3 PE1 PE2 PE3
Expand All @@ -431,7 +436,7 @@ void init_adc_8pins()
ADCSSPRI_ADC0 |= 0x3210; // Set the highest piriority for SS0
ADCEMUX_ADC0 &= ~0x000F; //software trigger for sequencer 0
ADCSSMUX0_ADC0 &= ~0xFFFFFFFF; // mask register bits
ADCSSMUX0_ADC0 += 0x30124567; // [(AIN3)-(AIN0)-(AIN1)-(AIN2)-(AIN4)-(AIN5)-(AIN6)-(AIN7) ] 0x30124567
ADCSSMUX0_ADC0 = 0x30124567; // [(AIN3)-(AIN0)-(AIN1)-(AIN2)-(AIN4)-(AIN5)-(AIN6)-(AIN7) ] 0x30124567
ADCSSCTL0_ADC0 |= 0x64444444; // enable raw interrupt signal (IE) for all channels and END7(sample 8 is the last sample)
ADCACTSS_ADC0 |= 0x01; //Enable SS0
}
Expand Down
1 change: 1 addition & 0 deletions Robot 1 tiva/MotorInit.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
#include <stdint.h>
#include "MemMap.h"
#include "Serve.h"
#include "ADC.h"
#define Motor1 1
#define Motor2 2
#define Motor3 3
Expand Down
31 changes: 19 additions & 12 deletions Robot 1 tiva/Serve.c
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ unsigned long State=1 ;
unsigned long I=0;
unsigned long state1=0;
unsigned long state2=0;

uint32_t SHARP[]={0};



Expand Down Expand Up @@ -157,15 +157,16 @@ switch (State)
digitalWrite(ServePiston,LOW);
Delay1ms(15);
PD2 &= ~0x04;
analogWrite(Motor10,2000) ;
analogWrite(Motor10,5000) ;
State=2;
Delay1ms(5);
// state1++;
while(1)
{
if((PA5&0x20)==0x20)
if((PA5&0x20)==0x00)
//if(((PE2&0x04)==0))
{
Delay1ms(55);
Delay1ms(70);
digitalWrite(ServePiston,HIGH);
MotorStop(Motor10);
Delay1ms(5);
Expand All @@ -182,15 +183,16 @@ switch (State)
Delay1ms(15);
PD2 |= 0x04;
Delay1ms(15);
analogWrite(Motor10,2000) ;
analogWrite(Motor10,5000) ;
State=1;
Delay1ms(5);
//state2++;
while(1)
{
if((PA5&0x20)==0x20)
if((PA5&0x20)==0x00)
// if(((PE2&0x04)==0))
{
Delay1ms(60);
Delay1ms(75);
digitalWrite(ServePiston,HIGH);
MotorStop(Motor10);
Delay1ms(5);
Expand All @@ -210,13 +212,15 @@ switch (State)
digitalWrite(ServePiston,LOW);
Delay1ms(15);
PD2 &= ~0x04;
analogWrite(Motor10,8000) ;
analogWrite(Motor10,4000) ;
State=2;
Delay1ms(5);
Delay1ms(900);
Delay1ms(570);
digitalWrite(ServePiston,HIGH);
MotorStop(Motor10);
Delay1ms(150);
digitalWrite(ServePiston,LOW);
Delay1ms(5);
state1++;
Expand All @@ -227,16 +231,19 @@ switch (State)
digitalWrite(ServePiston,LOW);
PD2 |= 0x04;
Delay1ms(15);
analogWrite(Motor10,8000) ;
analogWrite(Motor10,4000) ;
State=1;
Delay1ms(5);
Delay1ms(1000);
Delay1ms(570);
digitalWrite(ServePiston,HIGH);
MotorStop(Motor10);
Delay1ms(5);
Delay1ms(150);
digitalWrite(ServePiston,LOW);
break;
}*/


}
1 change: 1 addition & 0 deletions Robot 1 tiva/Serve.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
#include "MotorInit.h"
#include "Motion.h"
#include "spi.h"
#include "ADC.h"
extern unsigned long State ;


Expand Down
Binary file modified Robot 1 tiva/adc.crf
Binary file not shown.
1 change: 1 addition & 0 deletions Robot 1 tiva/adc.d
Original file line number Diff line number Diff line change
Expand Up @@ -16,3 +16,4 @@
.\adc.o: E:\Keil\TivaWare_C_Series-2.1.2.111\driverlib/uart.h
.\adc.o: E:\Keil\TivaWare_C_Series-2.1.2.111\utils/uartstdio.h
.\adc.o: E:\keil\ARM\ARMCC\bin\..\include\stdarg.h
.\adc.o: ADC.h
Binary file modified Robot 1 tiva/adc.o
Binary file not shown.
Binary file modified Robot 1 tiva/encoders.crf
Binary file not shown.
1 change: 1 addition & 0 deletions Robot 1 tiva/encoders.d
Original file line number Diff line number Diff line change
Expand Up @@ -19,3 +19,4 @@
.\encoders.o: E:\Keil\TivaWare_C_Series-2.1.2.111\driverlib/uart.h
.\encoders.o: E:\Keil\TivaWare_C_Series-2.1.2.111\utils/uartstdio.h
.\encoders.o: E:\keil\ARM\ARMCC\bin\..\include\stdarg.h
.\encoders.o: ADC.h
Binary file modified Robot 1 tiva/encoders.o
Binary file not shown.
Binary file modified Robot 1 tiva/fence.crf
Binary file not shown.
1 change: 1 addition & 0 deletions Robot 1 tiva/fence.d
Original file line number Diff line number Diff line change
Expand Up @@ -16,3 +16,4 @@
.\fence.o: E:\Keil\TivaWare_C_Series-2.1.2.111\driverlib/uart.h
.\fence.o: E:\Keil\TivaWare_C_Series-2.1.2.111\utils/uartstdio.h
.\fence.o: E:\keil\ARM\ARMCC\bin\..\include\stdarg.h
.\fence.o: ADC.h
Binary file modified Robot 1 tiva/fence.o
Binary file not shown.
32 changes: 25 additions & 7 deletions Robot 1 tiva/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
int i=0;
int a=0;
unsigned long servepwm=8000 ;

//uint32_t A[100]={0};
//uint32_t B[100]={0};
//uint32_t C[100]={0};
Expand All @@ -42,6 +41,7 @@ int main()
TIVA1();
while(1)
{

Data();
/* if(ReadData()==LIFTall_UP) // UP
{digitalWrite(ServeMotorCW,HIGH);}
Expand Down Expand Up @@ -196,16 +196,16 @@ Delay1ms(5);
a=50;}
//-------------------------------------------------------------
if (ReadData()==POLE2)
{Pole2(2746,3100,1796,9500);}
{Pole2(3250,3650,2630,9500);}
//-------------------------------------------------------------
if (ReadData()==POLE3)
{Pole3(500,500,500,1550);}
{Pole1(500,500,500,1550);}
//-------------------------------------------------------------
if (ReadData()==POLE4)
{Pole4(135,135,135,1550);}
{Pole4(0,0,0,1550);}
//----------------------------------------------------------
if (ReadData()==POLE5)
{Pole5(135,135,135,1550);}
{Pole5(0,0,0,1550);}
//-------------------------------------------------------------
if (ReadData()==LINE) //RIGHT
{while(1)
Expand Down Expand Up @@ -246,14 +246,32 @@ Delay1ms(5);
else if(ReadData()==CCW) // right analog left (CCW)
{CounterClockWise();}
else if(ReadData()==stop)
{Stop();}
{Stop();
MotorStop(Motor10);}
else if(ReadData()==ServeStart) // R1
{serve();}
else if(ReadData()==ServeStop) // L1
{servestop();}
else if(ReadData()==LIFT_STOP)
{liftersStop();}
{liftersStop();
MotorStop(Motor10);}
else if(ReadData()==R2)
{
PD2 &= ~0x04;
analogWrite(Motor10,5000) ;
}
else if(ReadData()==L2) // L2
{
PD2 |= 0x04;
analogWrite(Motor10,5000) ;
}

else if(ReadData()==UP) // L2
{
digitalWrite(ServePiston,HIGH);
Delay1ms(150);
digitalWrite(ServePiston,LOW);
}
if (ReadData()==0x23)
{break;}
}
Expand Down
Binary file modified Robot 1 tiva/main.crf
Binary file not shown.
2 changes: 1 addition & 1 deletion Robot 1 tiva/main.d
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
.\main.o: E:\Keil\TivaWare_C_Series-2.1.2.111\driverlib/uart.h
.\main.o: E:\Keil\TivaWare_C_Series-2.1.2.111\utils/uartstdio.h
.\main.o: E:\keil\ARM\ARMCC\bin\..\include\stdarg.h
.\main.o: ADC.h
.\main.o: PID.h
.\main.o: encoders.h
.\main.o: E:\keil\ARM\ARMCC\bin\..\include\stdio.h
Expand All @@ -24,5 +25,4 @@
.\main.o: pistons.h
.\main.o: Poles.h
.\main.o: E:\keil\ARM\ARMCC\bin\..\include\stdlib.h
.\main.o: ADC.h
.\main.o: fence.h
Binary file modified Robot 1 tiva/main.o
Binary file not shown.
Binary file modified Robot 1 tiva/motion.crf
Binary file not shown.
1 change: 1 addition & 0 deletions Robot 1 tiva/motion.d
Original file line number Diff line number Diff line change
Expand Up @@ -16,3 +16,4 @@
.\motion.o: E:\Keil\TivaWare_C_Series-2.1.2.111\driverlib/uart.h
.\motion.o: E:\Keil\TivaWare_C_Series-2.1.2.111\utils/uartstdio.h
.\motion.o: E:\keil\ARM\ARMCC\bin\..\include\stdarg.h
.\motion.o: ADC.h
Binary file modified Robot 1 tiva/motion.o
Binary file not shown.
Binary file modified Robot 1 tiva/motorinit.crf
Binary file not shown.
1 change: 1 addition & 0 deletions Robot 1 tiva/motorinit.d
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,4 @@
.\motorinit.o: E:\Keil\TivaWare_C_Series-2.1.2.111\driverlib/uart.h
.\motorinit.o: E:\Keil\TivaWare_C_Series-2.1.2.111\utils/uartstdio.h
.\motorinit.o: E:\keil\ARM\ARMCC\bin\..\include\stdarg.h
.\motorinit.o: ADC.h
Binary file modified Robot 1 tiva/motorinit.o
Binary file not shown.
Binary file modified Robot 1 tiva/pid.crf
Binary file not shown.
1 change: 1 addition & 0 deletions Robot 1 tiva/pid.d
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
.\pid.o: E:\Keil\TivaWare_C_Series-2.1.2.111\driverlib/uart.h
.\pid.o: E:\Keil\TivaWare_C_Series-2.1.2.111\utils/uartstdio.h
.\pid.o: E:\keil\ARM\ARMCC\bin\..\include\stdarg.h
.\pid.o: ADC.h
.\pid.o: encoders.h
.\pid.o: E:\keil\ARM\ARMCC\bin\..\include\stdio.h
.\pid.o: E:\keil\ARM\ARMCC\bin\..\include\math.h
Expand Down
Binary file modified Robot 1 tiva/pid.o
Binary file not shown.
Binary file modified Robot 1 tiva/pistons.o
Binary file not shown.
Binary file modified Robot 1 tiva/poles.crf
Binary file not shown.
Loading

0 comments on commit 943c9f9

Please sign in to comment.