Quantcast
Channel: MCS Electronics Forum
Viewing all articles
Browse latest Browse all 20601

BASCOM-AVR : Adc and pwm : REPLY

$
0
0
Try this [code:1:f08c4941c5]$regfile = "m8def.dat" $crystal = 8000000 $hwstack = 128 $swstack = 64 $framesize = 64 ' fast pwm, mode 14, noninverted output, prescaler 1 ' set frequency with register ICR1, duty cycle with OCR1A(Pwm1a), OCR1B(Pwm1b) Tccr1a = Bits(wgm11 , Com1a1 , Com1b1) Tccr1b = Bits(wgm12 , Wgm13 , Cs10) ' ICR1(Capture1) = (F_CPU[Hz] / (freq[Hz] * prescaler)) - 1 (freq=31250) Capture1 = 255 Config Adc = Single , Prescaler = Auto Dim Adc_value As Word Ddrb = Bits(1 , 2) ' output pins OC1A , OC1B '-------------------------------------- Do Adc_value = Getadc(0) Pwm1a = Adc_value / 4 ' use upper 8 bits of adc_value Pwm1b = 127 ' duty cycle 50% Loop End '-------------------------------------- [/code:1:f08c4941c5]

Viewing all articles
Browse latest Browse all 20601

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>