Skip to content

pwm fails with file not found error On BeagleBoneBlack #97

@rickblair

Description

@rickblair

I am trying to run the PWM example. I run as root. System is BeagleBoard.org Debian Image 2015-11-12 Bulldog version is latest.

Here is the error:
[java] -- listing properties --
[java] First
[java] Exception in thread "main" java.lang.RuntimeException: java.io.IOException: No such file or directory
[java] at io.silverspoon.bulldog.linux.sysfs.SysFs.echoAndWait(Unknown Source)
[java] at io.silverspoon.bulldog.beagleboneblack.sysfs.BBBSysFs.createSlotIfNotExists(Unknown Source)
[java] at io.silverspoon.bulldog.beagleboneblack.pwm.BBBPwm.setupImpl(Unknown Source)
[java] at io.silverspoon.bulldog.core.pin.AbstractPinFeature.setup(Unknown Source)
[java] beagleboneblack.dogtag=BeagleBoard.org Debian Image 2015-11-12
[java]
[java] at io.silverspoon.bulldog.core.pin.Pin.activateFeature(Unknown Source)
[java] at io.silverspoon.bulldog.core.pin.Pin.as(Unknown Source)
[java] at com.honeywell.spsd.deliveryTruck.PWMTest.main(PWMTest.java:20)
[java] Caused by: java.io.IOException: No such file or directory
[java] at java.io.FileOutputStream.writeBytes(Native Method)
[java] at java.io.FileOutputStream.write(FileOutputStream.java:326)
[java] at sun.nio.cs.StreamEncoder.writeBytes(StreamEncoder.java:221)
[java] at sun.nio.cs.StreamEncoder.implClose(StreamEncoder.java:316)
[java] at sun.nio.cs.StreamEncoder.close(StreamEncoder.java:149)
[java] at java.io.OutputStreamWriter.close(OutputStreamWriter.java:233)
[java] at java.io.BufferedWriter.close(BufferedWriter.java:266)
[java] ... 7 more
[java] Java Result: 1

Here is the code I am trying to run:

import io.silverspoon.bulldog.core.gpio.DigitalOutput;
import io.silverspoon.bulldog.core.platform.Board;
import io.silverspoon.bulldog.core.platform.Platform;
import io.silverspoon.bulldog.core.pwm.Pwm;
import io.silverspoon.bulldog.core.pwm.SoftPwm;
import io.silverspoon.bulldog.core.util.BulldogUtil;
import io.silverspoon.bulldog.beagleboneblack.pwm.;
import io.silverspoon.bulldog.beagleboneblack.
;

public class PWMTest
{

public static void main(String[] args)
{
final Board board = Platform.createBoard();

  //These will always share the same frequency - same pwm group! 
  Pwm pwm1 = board.getPin(BBBNames.EHRPWM0A_P9_21).as(Pwm.class); 
  Pwm pwm2 = board.getPin(BBBNames.EHRPWM0B_P9_22).as(Pwm.class); 
  pwm1.setFrequency(50.0f);  // 50 Hz 
  pwm1.setDuty(0.5f);    // 50% duty cycle 
  pwm1.enable(); 
   
  pwm2.setFrequency(50.0f);  // 50 Hz 
  pwm2.setDuty(0.3f);    // 30% duty cycle*/ 
  pwm2.enable(); 
   
  //These will always share the same frequency - same pwm group! 
  Pwm pwm3 = board.getPin(BBBNames.EHRPWM1A_P9_14).as(Pwm.class); 
  Pwm pwm4 = board.getPin(BBBNames.EHRPWM1B_P9_16).as(Pwm.class); 
  pwm3.setFrequency(1000.0f);  // 1000 Hz 
  pwm3.setDuty(0.5f);    // 50% duty cycle 
  pwm3.enable(); 
   
  pwm4.setFrequency(1000.0f);  // 1000 Hz 
  pwm4.setDuty(0.9f);    // 90% duty cycle 
  pwm4.enable(); 
  
  //These will always share the same frequency - same pwm group! 
  Pwm pwm5 = board.getPin(BBBNames.EHRPWM2A_P8_19).as(Pwm.class); 
  Pwm pwm6 = board.getPin(BBBNames.EHRPWM2B_P8_13).as(Pwm.class); 
  pwm5.setFrequency(10000.0f); // 10 kHz 
  pwm5.setDuty(0.25f);   // 25% duty cycle 
  pwm5.enable(); 
   
  pwm6.setFrequency(10000.0f); 
  pwm6.setDuty(0.75f);   // 75& duty cycle 
  pwm6.enable(); 
   
  //On some pins there are conflicts with hdmi 
  if(!board.hasProperty(BBBProperties.HDMI_ENABLED)) { 
   Pwm pwm7 = board.getPin(BBBNames.ECAPPWM0_P9_42).as(Pwm.class); 
   pwm7.setFrequency(100.0f); 
   pwm7.setDuty(0.5f); 
   pwm7.enable(); 
   
   Pwm pwm8 = board.getPin(BBBNames.ECAPPWM2_P9_28).as(Pwm.class); 
   pwm8.setFrequency(100.0f); 
   pwm8.setDuty(0.9f); 
   pwm8.enable(); 
  } 
   
  // This is a software pwm. It has kind of high cpu costs  
  // and is far from precise, but it can be used to drive  
  // motors for example and can be set up on any digital output 
  Pwm softPwm = new SoftPwm(board.getPin(BBBNames.P8_12)); 
  softPwm.setFrequency(50.0f); 
  softPwm.setDuty(0.2f); 
  softPwm.enable(); 
   
  for(int i = 0; i < 10; i++) { 
   for(double d = 0.0; d < 1.0; d += 0.01) { 
    pwm5.setDuty(d); 
    pwm6.setDuty(d); 
    
    BulldogUtil.sleepMs(1); 
   } 
    
   for(double d = 1.0; d > 0.0; d -= 0.01) { 
    pwm5.setDuty(d); 
    pwm6.setDuty(d); 
     
    BulldogUtil.sleepMs(1); 
   } 
  } 
   
  System.out.println("You can exit with ctrl + c"); 
  while(true) { 
   BulldogUtil.sleepMs(100); 
  } 

}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions