cancel
Showing results for 
Search instead for 
Did you mean: 

Regarding Delay

saiteja
Associate II

Hi..... i am a masters student from india. I have developed a code for RGBW now i want to include strobe effect for that i have give a hal_delay it is working fine now i want to change the PWM of RGBW when it is in strobe effect both has to work simultaneously but it is getting hanged i think this is due to Hal_delay i think this problem will be reduced if i give timer delay or i want to do something if it will solved with timer how to give timer delay in STM Controller.. I am using STM32F407VG controller.. Can someone help me out in this....... Thanks in Advance

13 REPLIES 13
T J
Lead

that's for my OS,

I check if DMAs are done, reissue commands in there...

you don't need it when you use blocking code.

saiteja
Associate II

Ok..... Thank You...... I'll check

saiteja
Associate II
  1. void wait_us(int uS) {
  2. resetTimChanneluSCounter(&htim5, 1, uS);
  3. waitTimChannelComplete(&htim5, 1);
  4. }
  5.  
  6. void resetTimChanneluSCounter(TIM_HandleTypeDef *htim, uint32_t channel, int16_t uS) { // tuned to F767
  7.  
  8. htim->Instance->CCR1 = htim->Instance->CNT
  9. htim->Instance->SR = !TIM_SR_CC1IF; // clear the flag
  10.  
  11. }
  12.  
  13. void waitTimChannelComplete(TIM_HandleTypeDef *htim, uint32_t channel) {
  14.  
  15. uint32_t tmp;
  16. tmp = 0;
  17. while( ! tmp ){
  18.  
  19. tmp = htim->Instance->SR & TIM_SR_CC1IF;
  20.  
  21. }
  22. // used to have &=
  23.  
  24. htim->Instance->SR = ! TIM_SR_CC1IF; // clear the flag
  25. break;
  26.  
  27. }
  28. //******************
  29.  
  30.  
  31. start_Timer5();
  32. while(1){ ....... }
  33. in your code:
  34. SetPWM(x,dutycycle);
  35. SetPWM(y,dutycycle);
  36. SetPWM(z,dutycycle);
  37. wait_us(1000); // blocking code
  38. SetPWM(x,0);
  39. SetPWM(y,0);
  40. SetPWM(z,0);

wait_us(1000);

I have written the code like this blinking also not taken place. What is the mistake

saiteja
Associate II
  1. void wait_us(int uS) {
  2. resetTimChanneluSCounter(&htim5, 1, uS);
  3. waitTimChannelComplete(&htim5, 1);
  4. }
  5.  
  6. void resetTimChanneluSCounter(TIM_HandleTypeDef *htim, uint32_t channel, int16_t uS)
  7. {
  8. htim->Instance->CCR1 = htim->Instance->CNT + uS_Counts;
  9. htim->Instance->SR = !TIM_SR_CC1IF; // clear the flag
  10. }
  11.  
  12. void waitTimChannelComplete(TIM_HandleTypeDef *htim, uint32_t channel) {
  13.  
  14. uint32_t tmp;
  15. tmp = 0;
  16. while( ! tmp ){

  1. tmp = htim->Instance->SR & TIM_SR_CC1IF;
  2. }
  3.  
  4. htim->Instance->SR = ! TIM_SR_CC1IF; // clear the flag
  5. }
  6. //******************
  7.  
  8.  
  9. start_Timer5();
  10. int main()
  11. {
  12. while(1){ SetPWM(x,dutycycle);
  13. SetPWM(y,dutycycle);
  14. SetPWM(z,dutycycle);
  15. wait_us(10); // blocking code
  16. SetPWM(x,dutycycle);
  17. SetPWM(y,dutycycle);
  18. SetPWM(z,dutycycle);
  19. }
  20. }
  21.  

I have written the code like this but it is not working blinking also not happening any mistake