
Originally Posted by
SteveB
Here is another alternative: Vary the period you increment your speed.
This examply uses PAUSE.
Code:
Incr_Time_ms = (1000 * Duration) / (End_Val - Start_Val)
Current_Val = Start_Val
Do Until Current_Val = End_Val
PAUSE Incr_Time_ms
Current_Val = Current_Val + 1
Loop
What would be ideal is set up a timer and add a value so that it overflows after "Incr_Time_ms". You can then use interrupts, or just poll the flag bit. increment your "Current_Val", clear the flag bit, and then add the value to set up the overflow after "Incr_Time_ms". Wash-Rinse-Repeat until "Current_Val = End_Val"
Hi Steve,
I've used what you said, and I've also included a deceleration ramp:
(sorry for renaming the values, it's for a easier integration in my main program).
Code:
' PIC18F4431 initialization
DEFINE OSC 40
DEFINE LCD_DREG PORTD
DEFINE LCD_EREG PORTB
DEFINE LCD_RSREG PORTB
DEFINE LCD_EBIT 6
DEFINE LCD_RSBIT 7
tacc var BYTE
tdec var BYTE
cacc var word
cdec var word
ref var word
fmin var word
freq var WORD
tacc=1
tdec=10
fmin=10
ref=1200
PAUSE 4000
LCDOUT $fe,$1
cacc = (1000 * tacc) / (ref - fmin)
cdec = (1000 * tdec) / (ref - fmin)
lp:
if freq<ref then PAUSE cacc
if freq>ref then PAUSE cdec
if freq<ref then freq = freq + 1
if freq>ref then freq = freq - 1
LCDOUT $fe,$2,DEC5 freq
if PORTC.0=%1 then ref=500
goto lp
It works quite good, but I cannot exeed 65 seconds (because 66*1000=66000, 16-bit integer is overflowed).
But, more importantly, I want to integrate the loop in a low priority DT interrupt. I really don't understand how you're using flags, etc. (I'm a beginner lol).
Thanks
Bookmarks