element14 Community
element14 Community
    Register Log In
  • Site
  • Search
  • Log In Register
  • Community Hub
    Community Hub
    • What's New on element14
    • Feedback and Support
    • Benefits of Membership
    • Personal Blogs
    • Members Area
    • Achievement Levels
  • Learn
    Learn
    • Ask an Expert
    • eBooks
    • element14 presents
    • Learning Center
    • Tech Spotlight
    • STEM Academy
    • Webinars, Training and Events
    • Learning Groups
  • Technologies
    Technologies
    • 3D Printing
    • FPGA
    • Industrial Automation
    • Internet of Things
    • Power & Energy
    • Sensors
    • Technology Groups
  • Challenges & Projects
    Challenges & Projects
    • Design Challenges
    • element14 presents Projects
    • Project14
    • Arduino Projects
    • Raspberry Pi Projects
    • Project Groups
  • Products
    Products
    • Arduino
    • Avnet Boards Community
    • Dev Tools
    • Manufacturers
    • Multicomp Pro
    • Product Groups
    • Raspberry Pi
    • RoadTests & Reviews
  • Store
    Store
    • Visit Your Store
    • Choose another store...
      • Europe
      •  Austria (German)
      •  Belgium (Dutch, French)
      •  Bulgaria (Bulgarian)
      •  Czech Republic (Czech)
      •  Denmark (Danish)
      •  Estonia (Estonian)
      •  Finland (Finnish)
      •  France (French)
      •  Germany (German)
      •  Hungary (Hungarian)
      •  Ireland
      •  Israel
      •  Italy (Italian)
      •  Latvia (Latvian)
      •  
      •  Lithuania (Lithuanian)
      •  Netherlands (Dutch)
      •  Norway (Norwegian)
      •  Poland (Polish)
      •  Portugal (Portuguese)
      •  Romania (Romanian)
      •  Russia (Russian)
      •  Slovakia (Slovak)
      •  Slovenia (Slovenian)
      •  Spain (Spanish)
      •  Sweden (Swedish)
      •  Switzerland(German, French)
      •  Turkey (Turkish)
      •  United Kingdom
      • Asia Pacific
      •  Australia
      •  China
      •  Hong Kong
      •  India
      •  Korea (Korean)
      •  Malaysia
      •  New Zealand
      •  Philippines
      •  Singapore
      •  Taiwan
      •  Thailand (Thai)
      • Americas
      •  Brazil (Portuguese)
      •  Canada
      •  Mexico (Spanish)
      •  United States
      Can't find the country/region you're looking for? Visit our export site or find a local distributor.
  • Translate
  • Profile
  • Settings
Raspberry Pi
  • Products
  • More
Raspberry Pi
Raspberry Pi Forum Occidentalis Kernel Module for PWM
  • Blog
  • Forum
  • Documents
  • Quiz
  • Events
  • Polls
  • Files
  • Members
  • Mentions
  • Sub-Groups
  • Tags
  • More
  • Cancel
  • New
Join Raspberry Pi to participate - click to join for free!
Featured Articles
Announcing Pi
Technical Specifications
Raspberry Pi FAQs
Win a Pi
Raspberry Pi Wishlist
Actions
  • Share
  • More
  • Cancel
Forum Thread Details
  • State Not Answered
  • Replies 16 replies
  • Subscribers 664 subscribers
  • Views 2203 views
  • Users 0 members are here
  • raspberry
  • raspberry_pi
  • raspberry-pi
  • kernel
  • raspbian
Related

Occidentalis Kernel Module for PWM

Former Member
Former Member over 11 years ago

Hello!

I'm new to RaspbPi usage and i need to make PWM with a DC Motor.  I have an SD card with NOOBS and have installed Raspbian.

I have a kernel module from the Occidentalis distribution ( from Adafruit) that enables the PI to do that but i don't know how to install it in my PI.

Can anyone help pls?

  • Sign in to reply
  • Cancel
  • iagorubio
    0 iagorubio over 11 years ago

    You can test if it loads with the insmod command.

     

    You must be root to load kernel modules.

     

    $ sudo su

    $ insmod /path/to/module.ko

     

    If it works you need to add it to your modules path so you can set up the configuration to load it each boot.

     

    You can if you want just add a symbolic link to your module file to the modules directory:

     

    $ sudo ln -s /path/to/module.ko /lib/modules/`uname -r`

    $ sudo depmod -a

     

    After that you can use the modprobe command:

     

    $sudo modprobe module

     

    Or add it to /etc/modules to auto load it at boot:

     

    $ sudo su

    $ echo module >> /etc/modules

    $ reboot

     

    You can test if your modules is loaded with the lsmod command:

     

    $ lsmod

    Module                  Size  Used by

    tcp_lp                 12663  0

    fuse                   86889  3

    bnep                   19624  2

    ....

     

     

    Hope this helps.

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • Verify Answer
    • Cancel
  • Former Member
    0 Former Member over 11 years ago

    Hello Iago. I've checked with the lsmod command u said and it shows the pwm module in that list..but i have the following problem when i run the code for controlling a dc motor:

    Error writing to: delayed value: 0

    Error writing to: frequency value: 500

    Error writing to: active value: 1

    Command, f/r/o/p/s 0..9, E.g. f5 :


    this is the code:

    1. import RPi.GPIO as io
    2. io.setmode(io.BCM)
    3. in1_pin = 4
    4. in2_pin = 17
    5. io.setup(in1_pin, io.OUT)
    6. io.setup(in2_pin, io.OUT)
    7. def set(property, value):
    8.    try:
    9.   f = open("/sys/class/rpi-pwm/pwm0/" + property, 'w')
    10.   f.write(value)
    11.   f.close()
    12.    except:
    13.    print("Error writing to: " + property + " value: " + value)
    14. set("delayed", "0")
    15. set("mode", "pwm")
    16. set("frequency", "500")
    17. set("active", "1")
    18. def clockwise():
    19.   io.output(in1_pin, True)  
    20.   io.output(in2_pin, False)
    21. def counter_clockwise():
    22.   io.output(in1_pin, False)
    23.   io.output(in2_pin, True)
    24. clockwise()
    25. while True:
    26.   cmd = raw_input("Command, f/r 0..9, E.g. f5 :")
    27.   direction = cmd[0]
    28.    if direction == "f":
    29.   clockwise()
    30.    else:
    31.   counter_clockwise()
    32.   speed = int(cmd[1]) * 11
    33.    set("duty", str(speed))

    i think here may be the problem : "/sys/class/rpi-pwm/pwm0/" ... it doesn't know that path....i'm runnig Raspbian not Occidentalis...

    Can you help pls?

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • Verify Answer
    • Cancel
  • iagorubio
    0 iagorubio over 11 years ago in reply to Former Member

    can you write here the output of this command ?

     

    sudo ls -al /sys/class/rpi-pwm/pwm0/

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • Verify Answer
    • Cancel
  • Former Member
    0 Former Member over 11 years ago in reply to iagorubio

    Hey Iago,

    I managed to do the PWM but i've hit another issue...i wanted to control a servomotor and i've pluged it like here:http://learn.adafruit.com/assets/3498 using a 12V power supply...and my Pi just shut down...and now it doesn't boot...my red led stays on and at first the act blinked a little but now nothing...only the red led stays on and i have no output on the monitor...i may have burned it? it was the same power supply used for the dc motor which worked perfectly...

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • Verify Answer
    • Cancel
  • iagorubio
    0 iagorubio over 11 years ago in reply to Former Member

    The servo motor is a completely different beast.

     

    The PWM on the DC motor is used just to limit the voltage on it. So a 50% duty cycle get half the voltage on the motor than a 100% duty cycle.

     

    The PWM on the servo motor, must be a fixed frequency 20ms PWM signal and the high duration on the PWM signal gives the servo the angle it must stay. So if in that 20ms PWM signal the high state is 0.5ms it stays at -90º and if it's 2.5ms it stays at +90º.

     

    Never use a DC motor controller to control servos.

     

    In the other hand 12V seems to be a quite high voltage for a RC servo. They use to go with 6V.

     

    So if the servo was low quality and the 12V voltage "fried" it and it poured into to the the Raspberry's signal wire , there is a high chance of it being dead. The GPIOs on the raspberry are 3.3V tolerant and 12V in there is far too much.

     

    The 12V may be normal for a DC motor as they are more resilient, but the flyback - the EMC voltage when the electric field on the motor coil collapses - can also kill the raspberry, and you may use any kind of IC with built in flyback diodes or some kind of protection.

     

    So what to check:

     

    Is the Servo motor 12V tolerant ?

     

    Is it ok and alive ?

     

    If you don't know if it's 12V tolerant just link it here.

     

    But I am afraid there is a middle to high chance of that Raspberry being dead.

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • Verify Answer
    • Cancel
  • Former Member
    0 Former Member over 11 years ago in reply to iagorubio

    this is the servo http://www.es.co.th/schemetic/pdf/et-servo-s3003.pdf

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • Verify Answer
    • Cancel
  • Former Member
    0 Former Member over 11 years ago in reply to Former Member

    i don't think the servo is dead though...

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • Verify Answer
    • Cancel
  • Former Member
    0 Former Member over 11 years ago in reply to Former Member

    or why does the PWR led still stays on and the ACT for reading the SD card sometimes flashes?

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • Verify Answer
    • Cancel
  • iagorubio
    0 iagorubio over 11 years ago

    The power led D6  will be on if the board is powered.

     

    If the ACT led D5 flashes in a pattern it may mean there is a known error:

     

    • 3 flashes: start.elf not found
    • 4 flashes: start.elf not launched
    • 7 flashes: kernel.img not found
    • 8 flashes: SDRAM not recognised.

     

    http://elinux.org/R-Pi_Troubleshooting#Green_LED_blinks_in_a_specific_pattern

     

    The servo is 4.8V to 6V, you should not connect it to 12V.

     

    I would try first to boot it with a new SD card and see if that changes anything.

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • Verify Answer
    • Cancel
  • Former Member
    0 Former Member over 11 years ago in reply to iagorubio

    the ACT led doesn't blink anymore.

    I have 2 SD's but it doesn't change anything.

    I've tested the voltage between the TP1 and TP2 points with a multimeter and i got a 3V value and between TP2 and polyfuse a 2.7V on a side and a 3.2V on the other...i've read that the polyfuse is self repairing over a few days...problem is i'm on a timetable and i don't know what to do...buy a new one or wait..what do you think?

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • Verify Answer
    • Cancel
>
element14 Community

element14 is the first online community specifically for engineers. Connect with your peers and get expert answers to your questions.

  • Members
  • Learn
  • Technologies
  • Challenges & Projects
  • Products
  • Store
  • About Us
  • Feedback & Support
  • FAQs
  • Terms of Use
  • Privacy Policy
  • Legal and Copyright Notices
  • Sitemap
  • Cookies

An Avnet Company © 2025 Premier Farnell Limited. All Rights Reserved.

Premier Farnell Ltd, registered in England and Wales (no 00876412), registered office: Farnell House, Forge Lane, Leeds LS12 2NE.

ICP 备案号 10220084.

Follow element14

  • X
  • Facebook
  • linkedin
  • YouTube