This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

to solve the problem

sir i have written a program to get the delay of 700usec and 20usec i got the exact timing delay here my problem is i want 20usec pulse to be continued.i think u can understand when i paste my code.kindly suggest me how to get the 20usec continuously

#include "stm32f0xx.h"
#include "stm32f0308_Discovery.h"

#define in1 GPIO_Pin_1
#define in2 GPIO_Pin_2
#define in3 GPIO_Pin_3
#define in4 GPIO_Pin_4
#define in5 GPIO_Pin_5
#define in_GPIO GPIOA

#define out1 GPIO_Pin_1
#define out2 GPIO_Pin_2
#define out3 GPIO_Pin_3
#define out4 GPIO_Pin_4
#define out5 GPIO_Pin_5
#define out_GPIO GPIOC

void TM_Delay_Init(void);
void TM_DelayMillis(uint32_t millis);
void TM_DelayMillis1(uint32_t millis);

GPIO_InitTypeDef GPIO_InitStructure ;

int inval;
uint32_t multiplier;

int main(void)
{ SystemInit(); SystemCoreClockUpdate(); TM_Delay_Init();

RCC_AHBPeriphClockCmd(RCC_AHBPeriph_GPIOA, ENABLE); RCC_AHBPeriphClockCmd(RCC_AHBPeriph_GPIOC, ENABLE);

/* Configure PA in input mode */ GPIO_InitStructure.GPIO_Pin = GPIO_Pin_0 ; GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN; GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL; // enable internal Pullup resistors on the GPIO pins GPIO_Init(GPIOA, &GPIO_InitStructure);

/*configure PC in output mode */

GPIOC->MODER |= (GPIO_MODER_MODER1_0) ; //GPIOC-> GPIO_MODER_MODER8_0 = 0x01; GPIOC->OTYPER &= ~(GPIO_OTYPER_OT_1) ; //GPIOC->OTYPER = 0x00; GPIOC->OSPEEDR |= (GPIO_OSPEEDER_OSPEEDR1); //GPIOC->OSPEEDR = 0x00; GPIOC->PUPDR &= ~(GPIO_PUPDR_PUPDR1);

while(1)
{

inval = GPIO_ReadInputDataBit(GPIOA, GPIO_Pin_0);//|GPIO_Pin_2|GPIO_Pin_3|GPIO_Pin_4|GPIO_Pin_5);

if(inval==1) {

GPIO_SetBits(in_GPIO,in1); GPIO_SetBits(out_GPIO,out1); TM_DelayMillis(7); GPIO_ResetBits(in_GPIO, in1); GPIO_ResetBits(out_GPIO,out1); TM_DelayMillis(7);

/*20us delay*/ GPIO_SetBits(in_GPIO,in1); GPIO_SetBits(out_GPIO,out1); TM_DelayMillis1(20); GPIO_ResetBits(in_GPIO, in1); GPIO_ResetBits(out_GPIO,out1); TM_DelayMillis(20); } } }

void TM_DelayMillis(uint32_t millis) { /* Multiply millis with multipler */ /* Substract 10 */ millis = 100 * millis * multiplier - 10; /* 4 cycles for one loop */ while (millis--);
}

void TM_DelayMillis1(uint32_t millis) { /* Multiply millis with multipler */ /* Substract 10 */ millis = 1 * millis * multiplier - 10; /* 4 cycles for one loop */ while (millis--);
}

void TM_Delay_Init(void) { RCC_ClocksTypeDef RCC_Clocks;

/* Get system clocks */ RCC_GetClocksFreq(&RCC_Clocks);

/* While loop takes 4 cycles */ /* For 1 us delay, we need to divide with 4M */ multiplier = RCC_Clocks.HCLK_Frequency / 4000000;
}

kindly help me in repeting the 20usec

  • Congratulations - you managed to make an unreadable post by ignoring the posting instructions. Your code isn't very easy to read after the line breaks have been lost.

    Another thing: The processor has timers. They are much better suited for delays, since don't make assumptions about what processor instructions the compiler will generate. And they don't make assumptions about time lost in interrupt handlers.

    Why go for something easy and reasonably portable, when it's possible to make assumptions that are not backed by any official documentation?

    The net is full of documentation about how to implement delays "the right way".
    The net is also full of debates about the issues with busy-loop delays.