PWM Signal 1Hz-5Hz

    Diese Seite verwendet Cookies. Durch die Nutzung unserer Seite erklären Sie sich damit einverstanden, dass wir Cookies setzen. Weitere Informationen

    Aufgrund technischer Veränderungen ist der Mailverkehr innerhalb des Forums (Private Nachrichten) nur noch eingeschränkt möglich. Die Einschränkung ist notwendig, um zusätzliche Betriebskosten für das Forum zu vermeiden. Näheres zu den Hintergründen im Thread "Aktuelles zum Forum".Wir bitten um Verständnis.

    Hinweis kann nach Kenntnisnahme deaktiviert werden!

    • PWM Signal 1Hz-5Hz

      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

      BASCOM-Quellcode

      1. $regfile = "m32def.dat"
      2. $HWStack = 32
      3. $SWStack = 32
      4. $Framesize = 32
      5. $Crystal = 4000000
      6. Config Portd.5 = Output 'OC1A
      7. Const Cpwmfreq = 65535 'for 5Hz or = ? for 1Hz
      8. Dim I As Word
      9. '2. Set Timer1 registers to Fast-PWM Mode with ICR1 as TOP Value (Mode 14),Compare A = Clear down:
      10. TCCR1A = &B10000010 'Bit 7:6 – COM1A1:0: Compare Output Mode for channel A set to 10
      11. ' = Clear OC1A on Compare Match, set OC1A at TOP
      12. 'Bit 5:4 – COM1B1:0: Compare Output Mode for channel B set to 00
      13. ' = Normal port operation, OC1B disconnected.
      14. 'Bit 3 – FOC1A: Force Output Compare for channel A set to 0 - not used in PWM
      15. 'Bit 2 – FOC1B: Force Output Compare for channel B set to 0 - not used in PWM
      16. 'Bit 1:0 – WGM11:0: Waveform Generation Mode set to ..10
      17. ' = lower bits of Mode 14: fast PWM; TOP = ICR1
      18. TCCR1B = &B00011010 'Bit 7 – ICNC1: Input Capture Noise Canceler set to 0 - not used in PWM
      19. 'Bit 6 – ICES1: Input Capture Edge Select set to 0 - not used in PWM
      20. 'Bit 5 – Reserved Bit set to 0
      21. 'Bit 4:3 – WGM13:2: Waveform Generation Mode set to 11..
      22. ' = higher bits of Mode 14: fast PWM; TOP = ICR1
      23. 'Bit 2:0 – CS12:0: Clock Select set to
      24. ' = higher bits of Mode 14: fast PWM; TOP = ICR1
      25. 'Bit 2:0 – CS12:0: Clock Select set to 010 = clkI/O / 8 (From prescaler)
      26. ICR1 = cPWMFreq
      27. I = cPWMFreq / 2 '50%
      28. Pwm1a = I
      29. End
      Alles anzeigen
    • Hi,

      in the other forum you were asking for a 50% duty cycle.
      If that is fixed there is another mode for the timer which is called CTC, that is fully supported by BASCOM.
      And if you can use the corresponding pins OC1A (PD5 of M32) or OC1B (PD4 of M32), you do not need to have an interrupt.
      The generation would be handled by hardware.

      Config Timer1=Timer, prescale=64, clear_timer=1, compare_a=toggle
      OCR1A=31249 ‘for 1Hz
      OCR1A=6249‘for 5Hz


      Calculation is:

      OCR1A=_Xtal/Timer1_Prescale/2 – 1 'value for 1Hz