Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

this code is for line robot robot using stm in keil u version

Status
Not open for further replies.

Noor Us Sabah

Newbie level 4
Joined
Jun 15, 2014
Messages
5
Helped
0
Reputation
0
Reaction score
0
Trophy points
1
Activity points
16
bt this code is not working point out mistake in it
#define RCC_APB2ENR ( * ((volatile unsigned long*) 0x40021018))
#define GPIOA_CRL ( * ((volatile unsigned long*) 0x40010800))
#define GPIOA_CRH ( * ((volatile unsigned long*) 0x40010804))
#define GPIOA_ODR ( * ((volatile unsigned long*) 0x4001080C))
#define GPIOB_CRL ( * ((volatile unsigned long*) 0x40010C00))
#define GPIOB_CRH ( * ((volatile unsigned long*) 0x40010C04))
#define GPIOB_ODR ( * ((volatile unsigned long*) 0x40010C0C))
#define GPIOC_CRL ( * ((volatile unsigned long*) 0x40011000))
#define GPIOC_CRH ( * ((volatile unsigned long*) 0x40011004))
#define GPIOC_ODR ( * ((volatile unsigned long*) 0x4001100C))


void Delay(void)
{
volatile unsigned int i;
for (i = 0; i < 325000; i++) //DELAY OF 1 SECOND
{

}

}

void SystemInit(void)
{
}

int main(void)
{
RCC_APB2ENR |= 0x00000018;
volatile unsigned short k;
GPIOC_CRH &=0x11111111;
GPIOC_CRL &=0x11111111;
GPIOA_CRH &=0x11111111;
GPIOB_CRH &=0x11111111;
volatile unsigned int A =0x0000;
volatile unsigned int B =0x8000;
volatile unsigned int C =0x2000;
volatile unsigned int D =0x0800;
volatile unsigned int E =0x0200;
volatile unsigned int F =0x0080;
volatile unsigned int G =0x0020;
volatile unsigned int H =0x0008;
volatile unsigned int I =0x0002;




while(1)
{

for(k=1;k<17;k++)
{
Delay();
Delay();

if(k>=1 && k<=4)
{
GPIOA_ODR =A;
GPIOB_ODR =A;

if(k==1)
{
GPIOC_ODR =B;
}

else if(k==2)
{
GPIOC_ODR =C;
}

else if(k==3)
{
GPIOC_ODR =D;
}

else
{
GPIOC_ODR =E;
}

}

if(k>=5 && k<=8)
{
GPIOC_ODR =A;
GPIOB_ODR =A;


if(k==5)
{
GPIOA_ODR =B;
}

else if(k==6)
{
GPIOA_ODR =C;
}

else if(k==7)
{
GPIOA_ODR =D;
}

else
{
GPIOA_ODR =E;
}

}
if(k>=9 && k<=12)
{
GPIOA_ODR =A;
GPIOB_ODR =A;



if(k==9)
{
GPIOC_ODR =F;
}

else if(k==10)
{
GPIOC_ODR =G;
}

else if(k==11)
{
GPIOC_ODR =H;
}

else
{
GPIOC_ODR =I;
}

}

if(k>=13 && k<=16)
{
GPIOA_ODR =A;
GPIOC_ODR =A;


if(k==13)
{
GPIOB_ODR =B;
}

else if(k==14)
{
GPIOB_ODR =C;
}

else if(k==15)
{
GPIOB_ODR =D;
}

else
{
GPIOB_ODR =E;
}

}



}
}

}
above file are main file below file r pwm
#include "main.h"
#include "PWM.h"

void PWM_Init(void)
{
RCC_APB2ENR |= 0x00000804; //enable clock to GPIO port A and Timer 1
GPIOA_CRH &= 0xFFFFF000; //clear previous config for port A pin 8,9,10
GPIOA_CRH |= 0x00000999; //config port A pin 8,9,10 as 10Mhz push pull alternate purpose output.
TIM1_CR1 = 0x0080;
TIM1_CNT = 0;
TIM1_PSC = 7;
TIM1_ARR = (20000-1);
TIM1_CCMR1 = 0x6868;
TIM1_CCMR2 = 0x0068;
TIM1_CCER = 0x0111;
TIM1_CCR1 = 1000;
TIM1_CCR2 = 1000;
TIM1_CCR3 = 1000;
TIM1_EGR = 0x0001;
TIM1_BDTR = 0x8000;
TIM1_CR1 |= 1;
}

void PWM_Ch1_drive_motor(const uint16_t PERIOD)
{
if((PERIOD>=10)&&(PERIOD<=19950))
{
TIM1_CCR1 = PERIOD;
}
else if(PERIOD<10)
{
TIM1_CCR1=10;
}
else
{
TIM1_CCR1=19950;
}


}


help to pont out the mistake or changing the code....
 

First thing I see is: There has got to be a better way to implement your delay function. You are wasting cycles when you could have the same result using a timer and an interrupt routine. Also no need for the iterator variable to be volatile, unless you are using that memory address in some other way.
 

Status
Not open for further replies.

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top