Hi All,
I am trying to change PWM DUTY via a varying voltage on an input
Then CHANGE FREQUENCY from 1000Hz when another input is HIGH --100Hz
I do NOT want the PWM DUTY to change when switched to the alternate frequency
I have applied a formula to the read ADC value but does not appear to work
The output is ramdom Duty but the frequency does change
Does anyone have some constructive thoughts
Thank you
Daniel
I am trying to change PWM DUTY via a varying voltage on an input
Then CHANGE FREQUENCY from 1000Hz when another input is HIGH --100Hz
I do NOT want the PWM DUTY to change when switched to the alternate frequency
I have applied a formula to the read ADC value but does not appear to work
The output is ramdom Duty but the frequency does change
Does anyone have some constructive thoughts
Thank you
Daniel
Code:
' PWM_1.Bas
'Uses 8M2
'
PWMOUT C.2, 249, 0
TOP:
GoSub Flash ' flash the LED on Out0
READADC10 C.4, W0 'read the 0-5vdc voltage and put the value into W0 (0 - 255)
If W0 <= 2 then let W0 = 0 endif
if pinc.3 = 0 then
W0 = W0 * 1024/1049 '// Do the math to map the value for 0 - 100 percent duty
pwmout pwmdiv4, C.2, 249, W0 ' 1000Hz
else
W0 = W0 * 1024/1678 '// Do the math to map the value for 0 - 100 percent duty
pwmout pwmdiv64, C.2, 155, W0 ' 100Hz
endif
GoTo TOP ' continually loop
Flash: ' flash LED on Out0
High C.1
Pause 5
Low C.1
Pause 45
Return
Attachments
-
80 KB Views: 14