In SX Microcontrollers, SX/B Compiler and SX-Key Tool, _BPM_ wrote: [quote="Three of Them"]The following program generates pulses on the RB.0 pin. The circuit uses a mosfet transistor to amplify the pulses for electric motor control. For speed adjustment, it takes a value on the RA port and converts it into pulse widths. It supports ten speeds including a full off (zero). Is their a way to shorten it? [code] DEVICE SX18, OSC4MHZ, TURBO, STACKX, OPTIONX FREQ 4_000_000 tris_b = 0 'Set RB port to outputs plp_a = 0 'Enable pullup resistors for RA port lowdur var byte 'Stores the length of time the signal is low. ctr var byte 'Incrementing variable for loops. Main: if ra = 15 then 'The default value is 15 hence the pullups are enabled. rb.0 = 0 'Signal is completely low. goto Main 'Infinate loop. endif if ra = 0 then 'Zero represents the same value as 15. rb.0 = 0 'Signal is completly low. goto Main 'Infinate loop. endif if ra = 10 then 'Ten represents motor running at full speed. rb.0 = 1 'Signal is completely high. goto Main 'Infinate loop endif lowdur = 10 - ra 'Calculate the time the signal is low. rb.0 = 1 'Enable RB.0 which is the PWM pin. for ctr = 0 to ra 'Loop number of times pulse is high. pauseus 100 'Wait 100 microseconds. next ctr rb.0 = 0 'Disable RB.0 for ctr = 0 to lowdur 'Loop number of times pulse is low. pauseus 100 'Wait 100 microseconds. next ctr goto Main 'Infinate loop [/code] Thank you :)[/quote] Instead of using multiple IF value = X then You can use lookup or lookdown, and also you can use branch.. Not too sure if lookup lookdown and branch would make your ASSEMBLY code faster (shorter) but you can try. ---------- End of Message ---------- You can view the post on-line at: http://forums.parallax.com/forums/default.aspx?f=7&p=1&m=127925#m127972 Need assistance? Send an email to the Forum Administrator at forumadmin@parallax.com The Parallax Forums are powered by dotNetBB Forums, copyright 2002-2006 (http://www.dotNetBB.com)