fuuton
Advanced Member level 4
- Joined
- Jul 21, 2010
- Messages
- 104
- Helped
- 9
- Reputation
- 18
- Reaction score
- 2
- Trophy points
- 1,298
- Location
- Pakistan, Rawalpindi
- Activity points
- 1,881
Hi all,
I need to generate variable delays in mikroC in micro seconds for PIC 18F4550. I am trying to generate a PWM signal for servos that I need to vary continuously depending on the values I obtain from my sensors. I have used many techniques but none has worked so far. Please help me out.
I recently used timers for this purpose but it was no good as well. The following code is supposed to generate a 600us delay inside the timer loop. Kindly help me fix it.
Thanks in advance.
-------------------------------------------------------------------------------
--------------------------------------------
I need to generate variable delays in mikroC in micro seconds for PIC 18F4550. I am trying to generate a PWM signal for servos that I need to vary continuously depending on the values I obtain from my sensors. I have used many techniques but none has worked so far. Please help me out.
I recently used timers for this purpose but it was no good as well. The following code is supposed to generate a 600us delay inside the timer loop. Kindly help me fix it.
Thanks in advance.
-------------------------------------------------------------------------------
Code C - [expand] 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 unsigned int on_time_high; unsigned int on_time_low; void main() { TRISD = 0x00; RD1_bit = 1; on_time_high = 61760/0x100; on_time_low = 61760-(on_time_high*0x100); TMR0H = on_time_high; TMR0L = on_time_low; // Values calculated for 1 second delay with 12MHz crystal while(1) { T0CON.TMR0ON = 1; // Timer0 On RD0_bit = 1; while(TMR0H<0xFF & TMR0L<0xFF); // Wait until TMR0IF gets flagged T0CON.TMR0ON=0; // Timer0 Off //INTCON.TMR0IF=0; // Clear Timer0 interrupt flag*/ delay_us(1000); RD0_bit = 0; TMR0H = on_time_high; TMR0L = on_time_low; } }
--------------------------------------------
Last edited by a moderator: