
Originally Posted by
Melanie
Dave - What is your definition of 'erratic'?
width = mon*1
Oh... Can you tell me what is the point of the *1 part of this line?
Basically your program states that if mon is >2 then your HPWM will be at around 12.5% otherwise it will be solid ON. There's not much else that happens... or at least it would do if you remembered a GOTO MAIN after the last IF statement!!! Because as it is, your code is slamming straight into the OneP section.
You could rewrite your code as...
Code:
Main:
ADCIN 3, mon ' Read channel AN3 to Mon
width = mon
if width > 2 then
hpwm 1,32,2000
else
hpwm 1,255,2000
endif
pause 1000
goto main
I'm also assuming you've set TRISIO and such properly.
Melanie,
Thank you for replying.
Initially, I couldn't get the code to compile without width=mon*1. I've sice removed the *1 and it compiles OK now. No idea why.
Erratic = while it's executing hpwm 1,255,2000 when "width is less than 2" with either version of code, it cycles randomly back and forth to 1,32,2000. While "width is greater than 2" the output is stable.
I'm going to try a while wend in there.
~ Dave
Here's what I'm using since your reply:
Code:
INTCON = %10001000 'internal oscillator
OSCCON = %01110000 ' 8mHz
CMCON0 = 7 'Comparators off
GPIO = %00000000 'outputs low
TRISIO = %00010000 'GP4 as input
ANSEL = %00111000 'AN3 analog
'Define ADCIN parameters
Define ADC_BITS 10 ' Set number of bits in result
Define ADC_CLOCK 3 ' Set clock source (3=rc)
Define ADC_SAMPLEUS 50 ' Set sampling time in uS
' Variables
Mon var Word
Width var byte
Pause 100
Main:
ADCIN 3, mon ' Read channel AN3 to Mon
width = mon
if width > 2 then
hpwm 1,32,2000
else
hpwm 1,255,2000
endif
pause 1000
goto main
end
Bookmarks