Recompiling the Kernel to get PWM on Mx6

Discussion in 'Kernels' started by r3dfish, Nov 19, 2013.

  1. r3dfish

    r3dfish New Member

    Joined:
    Nov 5, 2013
    Messages:
    3
    Likes Received:
    0
    Hi All,

    I'm trying to recompile my kernel to read a PWM value from the Mx6 side. I put together a tutorial here that shows how to drive a PWM function from the SAM side, and I would like to be able to read the PWM value in real time from the Mx6 side.

    http://www.youtube.com/watch?v=4_RR-6JeNIw

    According to the Getting started doc, I needed to rebuild my kernel with proper modifications to board-mx6qd_seco_UDOO.h in order to drop GPIO9 into PWM mode. Here are the steps I took to accomplish this:

    $ cd /usr/src
    $ sudo -s
    # apt-get install ncurses-dev
    # git clone http://github.com/UDOOboard/Kernel_Unico kernel
    # cd kernel
    # make ARCH=arm UDOO_defconfig
    # make ARCH=arm menuconfig
    # cd arch/arm/mach-mx6/
    # vim board-mx6qd_seco_UDOO.h

    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

    COMMENT OUT LINE 280, UNCOMMENT LINE 281
    //MX6Q_PAD_GPIO_9__GPIO_1_9, // pin 11
    MX6Q_PAD_GPIO_9__PWM1_PWMO,
    // MX6Q_PAD_GPIO_9__USDHC1_WP,

    COMMENT OUT LINE 412:
    MX6Q_PAD_SD1_DAT2__GPIO_MODE,
    MX6Q_PAD_GPIO_1__GPIO_MODE,
    //MX6Q_PAD_GPIO_9__GPIO_MODE,
    MX6Q_PAD_GPIO_3__GPIO_MODE,
    MX6Q_PAD_SD4_DAT0__GPIO_MODE,

    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

    # cd ../../..
    # make
    # make modules_install
    # make install

    After rebooting, I still only get a 1 or a 0 from
    ubuntu@imx6-qsdl:/sys/class/gpio/gpio9$ cat value

    Any ideas what I'm doing wrong? Do I need to look for the PWM value on gpio9 elsewhere on the Mx6 side? Did I not install the kernel properly? Thoughts?
     
  2. sled

    sled New Member

    Joined:
    Sep 25, 2013
    Messages:
    5
    Likes Received:
    0
    hi,

    I think you can only output PWM signals (not a 100% sure though)

    What I've found so far is a good thread on the freescale forum:

    https://community.freescale.com/thread/309466

    I'll try to implement the PWM in the kernel this weekend ;)
     
  3. ymilord

    ymilord New Member

    Joined:
    Oct 22, 2013
    Messages:
    5
    Likes Received:
    0
    I am getting this same behavior with the stock ubuntu img. My goal was to read voltages from a solar cell. The console output on the arduino side is reading the values correctly (which matches the readings I was getting from a multimeter). But from the ubuntu cli I get the same behavior as you- the value of "1".
     
  4. Lifeboat_Jim

    Lifeboat_Jim New Member

    Joined:
    Sep 16, 2013
    Messages:
    399
    Likes Received:
    1
    I had a quick look at the Kernel Sources last night on this very topic (as a question was asked on IRC about accessing PWM on i.MX6).

    • * The way it's being done seems that the Analogue Pins are being treated the same as Digital Pins in the code.
    • * The getters/setters have the value being returned declared as INTs.
    • * Now, given the SAM3X8E is capable of 12bit accuracy (they will default to 10bit unless told otherwise) clearly INT won't cut Analogue values.

    This was just a quick code skim through so whilst I believe I'm looking at the right code in the right way, there is a chance of an error on my part. Perhaps someone else can double-check this.

    Clearly there is quite a bit of demand on this issue, so we can ask Team UDOO to put this on the ToDo list... or shuffle it up if it's already on there.
     
  5. firehopper

    firehopper Member

    Joined:
    Jun 10, 2013
    Messages:
    154
    Likes Received:
    1
    if your looking to read analog values. you need an analog to digital converter..
    not sure if the imx chip has built in a2d channels like the arduino chips do.
     
  6. Lifeboat_Jim

    Lifeboat_Jim New Member

    Joined:
    Sep 16, 2013
    Messages:
    399
    Likes Received:
    1
    Good point Fire, never thought about the ADC... took that for granted. You're comment reminds me that I seem to recall the i.MX6 having 4 internal PWM. It may be that some/all are in use. However lets look into that some more, if even 1 or 2 internal PWM's are available that would be very nice.
     
  7. EBrown

    EBrown New Member

    Joined:
    Dec 9, 2013
    Messages:
    48
    Likes Received:
    0
    I'm guessing that, due to the fact that the i.MX and Sam3X have bidirectional communication built-in, you may be able to read the analogue value on the Arduino side, and then send the data across the serial connection to the i.MX side. (This is actually something I am going to be experimenting with soon, as the plan I have for my Udoo requires me to be able to read analogue signals and do some very complex processing with them, and then log them and pass them to various other areas.)

    If (most likely when) I get this working I'll post some code for you all so you can see how to achieve it. (Though it should be very trivial, as examples of using the serial bus for communication are in the documentation on pages 21 and 22, and then it's just a matter of passing the analog values through the serial bus as you desire, and reading them as required.)

    Thanks,
    EBrown
     
  8. r3dfish

    r3dfish New Member

    Joined:
    Nov 5, 2013
    Messages:
    3
    Likes Received:
    0
    That sounds awesome man, looking forward to it.
     
  9. EBrown

    EBrown New Member

    Joined:
    Dec 9, 2013
    Messages:
    48
    Likes Received:
    0
    I should be getting to this on Thursday or Friday. I am suspecting that when I do get the communication working and GPIO data traveling between the two devices, I'll write a simple library so that you can just plug the Arduino library in, and the Udoo library in, and have full GPIO management from the i.MX6 without needing to reprogram the Arduino or change any Arduino code when you want to change something. (I am suspecting that I'll have it monitor all the GPIO's and send data back across the serial when their state changes. I am hoping I can even allow you to change between digital and analogue mode from the Udoo as well. I have a few theories in mind to create this particular system.) If (when) I do complete it I'll post all the source and instructions here on the forums somewhere, and make it as easy to plug'n'play as possible.

    Thanks,
    EBrown
     
  10. fjbrill

    fjbrill New Member

    Joined:
    Nov 27, 2013
    Messages:
    2
    Likes Received:
    0
    Hello,

    I'm new to kernel building. I compiled the kernel based on the steps from r3dfish above, but I'm not really sure how to get it to boot on the new kernel. Can someone please explain? Is there a kernel build tutorial somewhere for udoo?

    Thanks!
    fjbrill
     
  11. miousername

    miousername New Member

    Joined:
    Jun 23, 2013
    Messages:
    73
    Likes Received:
    0
  12. fjbrill

    fjbrill New Member

    Joined:
    Nov 27, 2013
    Messages:
    2
    Likes Received:
    0
    Thank you miousername. I didn't realize that it was in the starting manual :( Should have read it from cover to cover instead of skipping around.

    -fjbrill
     
  13. francescomm

    francescomm Member

    Joined:
    Dec 14, 2013
    Messages:
    80
    Likes Received:
    4
    Take a look at this for data moving over serial from Arduino to Linux sides

    viewtopic.php?f=8&t=650

    The idea is to use some simple protocol for Remote Procedure Calling from any script (I used PHP as an example) to the Arduino with return values.

    If you want to read an analog pin you just call $someClass->get('a',$pinNum) in PHP (but C would be similar), that would send the request over serial, launch a simple doGet('a',pin) on Arduino side, get the results, pack as string, send back over serial and return them as result.

    To adapt it from PHP to other languages you just need to convert one function that sends stuff to the serial port and gets results ( based on fopen, fread, etc.. so it should be easy).

    Have fun.
     
  14. EchoWarp

    EchoWarp New Member

    Joined:
    Feb 3, 2014
    Messages:
    11
    Likes Received:
    0
    If you're wanting to read a PWM signal you can just use the gpio from either processor. You attach an interrupt to the pin you are measuring and get the time it is on and the time it is off. Then it is (on / (off + on))
     
  15. andypugh

    andypugh New Member

    Joined:
    Nov 28, 2013
    Messages:
    26
    Likes Received:
    0
    Reading PWM is likely to be expensive computationally. If you can use interrupts and time-stamp them, that is probably the best way.
    Polling the input to detect the state changes is likely to be difficult to do quickly enough.

    One way to read a voltage using a PWM is to use two pins, one as a pwm _output_ and another to detect the output of a comparator that compares the filtered voltages of the reference pwm and measured pwm.

    Arduino ADC and serial is likely to be a lot easier. (Or consider using the microphone port).
     

Share This Page