1

I have used Pigpio library to generate pulses on rasp pi2 since last year. The all thing have worked quite good. But 3 days ago, the my rasp appear faults and it don't accept me use more. So I must install programming again as well as format SD card. But when I generate 40khz pules is that oscilloscope only dislay about 32.55khz. I using wavePWM library of pigpio. Please give me how to resolve this problem. This is code that I used:

 /*
   import pigpio
   import wavePWM
   from socket import*
   import numpy
   import numpy as np
   import pickle
   import operator
   import sys, struct
   pi = pigpio.pi()

      if not pi.connected:
      exit(0)

   """
   This code demonstrates four different methods of setting
   the pulse start and length.
   """
   pwm = wavePWM.PWM(pi) # Use default frequency

   pwm.set_frequency(40000)

   cl = pwm.get_cycle_length()
   # Method 2.
   pwm.set_pulse_start_and_length_in_micros(2,0, 12.5) // 2 is GPIO pin that generate 40khz, 0 is time delay  and 12.5 is duty cycle 50%.
   pwm.update() # Apply all the changes.

   time.sleep(120)

   for g in GPIO:

     pwm.set_pulse_length_in_micros(g, 0)

     pwm.update()

     time.sleep(1)


   pwm.cancel()

   pi.stop() 
  • At the very least we are going to need to see the code you are using. – Steve Robillard Jun 16 '17 at 6:51
  • @Steve Robillard , It simple as code in this thread: raspberrypi.stackexchange.com/questions/56794/… – Gab Jun 16 '17 at 7:14
  • Please be more specific about your problem, including - as Steve pointed out - the code. Please do not link to a deleted question as a reference - that is not going to help anyone. – Ghanima Jun 17 '17 at 9:01
  • @Ghanima, I have added code. Thanks Ghanima for your suggestion. – Gab Jun 18 '17 at 11:59
1

This is a known "bug". I put bug in quotes because it seems to only affect some Pi configurations and is something I have not been able to duplicate.

I think the kernel has altered the way the clocks are used which has the rather unfortunate side effect of screwing up the PWM clock (and the SPI clock, and the I2C clock).

The best I can suggest is try adding core_freq=250 to /boot/config.txt.

Also see https://github.com/joan2937/pigpio/issues/137 and https://github.com/raspberrypi/linux/issues/2060

  • I tried to add core_freq=250 as you suggested but it seems not fixed. The frequency about 35.5 kHz (not 40khz as I want to). I using Raspi 2 mode B. and an Ethernet port via putty to control it. Whether that can the ethernet port lead to this problem? My Rasp was failed last week, so I formatted SD card and re-install Raspian for it. But before it worked quite well. Any recommend for me now? thanks Joan very much – Gab Jun 17 '17 at 5:43
  • I am aware of no fix at the moment. It only affects PWM peripheral timing (I believe). If general PWM and servos aren't that important start the pigpio daemon with the -t0 option which will then use the PCM peripheral for wave timing. – joan Jun 17 '17 at 7:42
  • If I change a new raspberry pi, this problem can be fixed? – Gab Jun 18 '17 at 12:10
  • @Gab Given that no one understands the problem I'd have to say nobody knows. – joan Jun 18 '17 at 15:14
  • 1
    This programming quite important with me since It's my thesis. This September I must defend so I really sad. Can you give me a specific method to can resolve this problem? It seems to be stretched about 5 us for all case (For example if 40 kHz (T=25us) is that T got = 30 us). – Gab Jun 19 '17 at 8:41

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.