Hi,
with the following code I get a PWM signal with frequency of 7.6Hz
how can I get to have a frequency range of 1Hz - 5Hz?
Thanks
Alles anzeigen
with the following code I get a PWM signal with frequency of 7.6Hz
how can I get to have a frequency range of 1Hz - 5Hz?
Thanks
BASCOM-Quellcode
- $regfile = "m32def.dat"
- $HWStack = 32
- $SWStack = 32
- $Framesize = 32
- $Crystal = 4000000
- Config Portd.5 = Output 'OC1A
- Const Cpwmfreq = 65535 'for 5Hz or = ? for 1Hz
- Dim I As Word
- '2. Set Timer1 registers to Fast-PWM Mode with ICR1 as TOP Value (Mode 14),Compare A = Clear down:
- TCCR1A = &B10000010 'Bit 7:6 – COM1A1:0: Compare Output Mode for channel A set to 10
- ' = Clear OC1A on Compare Match, set OC1A at TOP
- 'Bit 5:4 – COM1B1:0: Compare Output Mode for channel B set to 00
- ' = Normal port operation, OC1B disconnected.
- 'Bit 3 – FOC1A: Force Output Compare for channel A set to 0 - not used in PWM
- 'Bit 2 – FOC1B: Force Output Compare for channel B set to 0 - not used in PWM
- 'Bit 1:0 – WGM11:0: Waveform Generation Mode set to ..10
- ' = lower bits of Mode 14: fast PWM; TOP = ICR1
- TCCR1B = &B00011010 'Bit 7 – ICNC1: Input Capture Noise Canceler set to 0 - not used in PWM
- 'Bit 6 – ICES1: Input Capture Edge Select set to 0 - not used in PWM
- 'Bit 5 – Reserved Bit set to 0
- 'Bit 4:3 – WGM13:2: Waveform Generation Mode set to 11..
- ' = higher bits of Mode 14: fast PWM; TOP = ICR1
- 'Bit 2:0 – CS12:0: Clock Select set to
- ' = higher bits of Mode 14: fast PWM; TOP = ICR1
- 'Bit 2:0 – CS12:0: Clock Select set to 010 = clkI/O / 8 (From prescaler)
- ICR1 = cPWMFreq
- I = cPWMFreq / 2 '50%
- Pwm1a = I
- End