In SX Microcontrollers, SX/B Compiler and SX-Key Tool, datacps wrote: Ok guys I changed from high low to pulseout. The output looks a lot better on my scope. I want to set the delay for the pulse width.. I have everything working but I don't know where or how to put delay in another variable. I am also having a problem scaling the encoder. The examples are for RC time. All I need is to be able to change the pulsewith on the PULSOUT RB.4, 600 to PULSOUT RB.4, delay. I want to be able then to change my pulsewidth with encoder 1. I can't figure out what I am doing wrong>>>> Also on the scaling I need 1 to 1000 us and I can't find any examples for encoders scales just RC time. As for the ISR Peter all I need is to be able to control my Pulsewidth with 1 encoder and the frequency with the other. I am working on a power invertor so I don't think I will need to go over 400 hz. SO my range will be 40 to 400 hz. Any suggestions on how I can control the frequency range??????? I am going to turn on 2 mosfet a time so I won't need 4 outputs. I can control my H drive with 2 only.. I am posting the code. Like I mentioned I have the circuit working but I can't change the pulseout width ( delay) and display the setting on my LCD. I am confused on temp , Tempw , ect and also I don't fully understand how the ISR inc and dec work with my encoder???? Bean.. how do I scale the encoder with the */ . It looks simple enough but I can't get it to work.. What am I doing wrong.... ' ------------------------------------------------------------------------- ' Device Settings ' ------------------------------------------------------------------------- DEVICE SX28,TURBO,OPTIONX,STACKX,OSCHS3,BOR42 FREQ 50_000_000 ID "delay.1" ' ------------------------------------------------------------------------- ' IO Pins ' ------------------------------------------------------------------------- led1 VAR RB.4 led2 VAR RB.5 led3 VAR RB.6 ' LED pin EncoderPort PIN RC Encoder1A PIN RC.0 INPUT PULLUP Encoder1B PIN RB.1 INPUT PULLUP INTR_FALL LCD PIN RA.0 OUTPUT ' ------------------------------------------------------------------------- ' Constants ' ------------------------------------------------------------------------- mindelay CON 1 ' Lowest allowable delay maxdelay CON 1000 ' Highest allowable delay LCDBaud CON "T19200" ' LCD Baud rate ClearScreen CON 12 ' Clears LCD screen (Use PAUSE 5 after sending this command) NewLine CON 13 ' Put LCD cursor on the next line Home CON 128 ' Move LCD cursor to upper left without clearing the screen LcdBLon CON 17 'TURN ON LCD BACK LIGHT DELAY2 CON 2000 WAIT CON 100 ' ------------------------------------------------------------------------- ' Variables ' ------------------------------------------------------------------------- delay VAR WORD delayWANTED VAR WORD tempW VAR WORD ' Used by Setdelay, LCDStr, LCDWord temp VAR BYTE ' Used by Setdelay, LCDChar, LCDStr tempW2 VAR WORD ' Used by Setdelay encoder VAR WORD encoder1 VAR WORD encoder1Last VAR WORD ' ------------------------------------------------------------------------- INTERRUPT ' Interrupt caused by falling edge of EncoderB input WKPND_B = 0 ' Clear interrupt flag to enable further interrupts IF Encoder1 = 0 THEN ' Change "0" to "1" if direction is backwards DEC delay delay = delay MIN MinDelay ' Min delay must be > 0 ELSE INC delay delay = delay MAX MaxDelay ENDIF RETURNINT ' ========================================================================= PROGRAM start ' ========================================================================= ' ------------------------------------------------------------------------- ' Subroutine Declarations ' ------------------------------------------------------------------------- LCDChar SUB 1 ' Sends 1 character (byte) to the LCD LCDStr SUB 2 ' Sends a string to the LCD LCDWord SUB 2 ' Sends a value to the LCD as ASCII GetEncoder1 FUNC 1 UpdateEncoders SUB 0 setdelay SUB 1 ' ------------------------------------------------------------------------- ' Program Code ' ------------------------------------------------------------------------- Start: HIGH LCD ' For LCD High is idle state PAUSE 10 ' Let LCD settle LCDChar ClearScreen PAUSE WAIT LCDStr " delay test " PAUSE delay2 LCDChar ClearScreen PAUSE WAIT LCDChar ClearScreen PAUSE WAIT encoder1Last = GetEncoder1 PAUSEUS 100 UpdateEncoders IF delay <> tempW THEN LCDChar Home LCDStr " delay = " LCDWord delay ENDIF DO PULSOUT RB.4, 600 ' pulses from 100 to 1000 µs pauseus 2 pulsout RB.5, 600 pauseus 2 loop ' ------------------------------------------------------------------------- ' Subroutine Code ' ------------------------------------------------------------------------- ' ----------------------------------------------------------------------------- '''''''Problem Problem ''''Bean wrote '' 'When you scale "delay" you'll have to put the result into another variable. '' tempW = delay */ Scale ''' PAUSE tempW ''' I am having a problem here ''''' SUB Setdelay IF __PARAMCNT = 1 THEN DELAY = __PARAM1 ELSE DELAY = __WPARAM12 ENDIF endsub '----------------------------------------------------------------- ' LCD ROUTINE '------------------------------------------------------- SUB LCDChar temp = __PARAM1 SEROUT LCD, LCDBaud, temp UpdateEncoders ENDSUB SUB LCDStr tempW = __WPARAM12 DO READINC tempW, temp IF temp = 0 THEN EXIT LCDChar temp LOOP ENDSUB SUB LCDWord tempW = __WPARAM12 temp = "0" DO IF tempW < 1 THEN EXIT INC temp tempW = tempW - 1 LOOP LCDChar temp temp = "0" DO IF tempW < 10 THEN EXIT INC temp tempW = tempW - 10 LOOP LCDChar temp temp = "0" DO IF tempW < 1 THEN EXIT INC tempw tempW = tempW - temp LOOP LCDChar temp temp = "0" DO IF tempW < 1 THEN EXIT INC temp tempW = tempW - 1 LOOP LCDChar temp temp = "0" + tempW_LSB LCDChar temp ENDSUB '-------------------------------------------------------------------------------- ' ---- encoders------------ FUNC GetEncoder1 temp = EncoderPort AND 3 RETURN temp ENDFUNC SUB UpdateEncoders encoder1 = GetEncoder1 IF encoder1 <> encoder1Last THEN IF encoder1 = 3 THEN IF encoder1Last = 1 THEN delay = delay + 1 delay = delay MAX maxdelay ELSEIF encoder1Last = 2 THEN delay = delay - 1 delay = delay MIN mindelay ENDIF ENDIF encoder1Last = encoder1 ENDIF endsub ---------- End of Message ---------- You can view the post on-line at: http://forums.parallax.com/forums/default.aspx?f=7&p=1&m=226156#m228785 Need assistance? Send an email to the Forum Administrator at forumadmin@parallax.com The Parallax Forums are powered by dotNetBB Forums, copyright 2002-2007 (http://www.dotNetBB.com)