10 Replies Latest reply on Mar 13, 2015 12:21 PM by Frederic Philips

    Problems with Intel Edison(SPI, PWM and Timer)

    Frederic Philips

      Hi guys,

      I have been trying to interface the Sharp Memory LCD booster pack lately with edison and encounterd a number of problems. I will list them out in the order which they occured.

      (Note: I am using Intel edison with the arduino expansion board and mraa libraries to code in C)

      1. First of all the data for the LCD must be in MSB(little-endian) format. The mraa_spi_lsbmode(spi, 0) doesn't seem to work.

      2. The VCOM bit of the LCD must be toggled at a minimum of 1 Hz to prevent charge build-up. This can be done either by software or hardware. I tried both which ended up in different problems:

          a) Software mode: The timer(kernel) was set to interrupt for every second so that the VCOM bit could be updated through the SPI bus. This didn't go well as the interrupt handler messes up with the current SPI Transmission.

          b) Hardware mode: The EXTCOMIN pin must be toggled at a minimum of 1 Hz. I tried generating a PWM for 1Hz but in vain. The PWM's lowest possible frequency was 20Hz. I used this as an example.

      So either way its impossible to toggle the VCOM bit.

      If any of you guys had some experience with the SHARP Memory Display please make some suggestions. I have been struggling for the past week with no positive results. I am attaching my Source code in the post.

      Thanks in advance and Cheers

       

      Additional links:

      SHARP Memory LCD Datasheet

      SHARP Display Programming Guide

      Timer Code which is used for Interrupt

        • 1. Re: Problems with Intel Edison(SPI, PWM and Timer)
          Intel_Peter

          Hello freddy7phil,

           

          Unfortunately I don't have a Sharp ® Memory LCD BoosterPack - 430BOOST-SHARP96 - TI Tool Folder so I won't be able to test it, but regarding your issues with the PWM frequency, according to Intel® Edison Compute Module Hardware Guide in section 4.8 it says that Edison's PWM has operating frequencies from 0 to 9.6MHz, so this might be an issue with MRAA, which version of the library is installed on your board? Which image is on your board?

          Nevertheless, a frequency of 1Hz it's something a regular GPIO can do, why don't you try using one for the VCOM toggling?


          Peter.

          • 2. Re: Problems with Intel Edison(SPI, PWM and Timer)
            Frederic Philips

            Hi Peter,

            Ya I have already tried toggling the GPIO pin usng a timer Interrupt for 1Hz but it messes up with my SPI communication. The code which I had attached contains the GPIO toggling of the VCOM bit.

            Today I bumped into a new problem with the eclipse IDE. So far I have been Programming and Compiling through the edison kernel. Today I tried the Eclipse IDE but could not even create a new project.

            I have started a new discussion for that:

            Eclipse IDE not functioning

            • 3. Re: Problems with Intel Edison(SPI, PWM and Timer)
              Intel_Peter

              Hi freddy7phil,

               

              I will try to test the PWM frequencies with MRAA, but I'll try to do it on your same circumstances, what image are you using and which version of MRAA do you have installed?

               

              Peter.

              • 4. Re: Problems with Intel Edison(SPI, PWM and Timer)
                Frederic Philips

                Hi Peter,

                My setup:

                PC- Windows 8.1(64-bit)

                Image(latest) and IDE: Eclipse IOT Edition(Installed through the latest Integrated Installer)

                JRE - 8 Update 40(64-bit)

                MRAA Version: v0.6.1

                 

                I use the following code:

                /*
                 * PWM_C_Test.c
                 *
                 *  Created on: 06.03.2015
                 *      Author: Frederic P.
                 */
                #include <unistd.h>
                #include "mraa.h"
                
                #define TIME_PERIOD 1 //Time Period in Hz
                #define DUTY_CYCLE 0.5f //Duty Cycle(0.0f - 1.0f)
                
                int main ()
                {
                    mraa_init();
                    mraa_pwm_context pwm;
                    pwm = mraa_pwm_init(3);
                    if (pwm == NULL)
                    {
                        return 1;
                        printf("PWM Initialization Failed");
                    }
                    mraa_pwm_period(pwm, TIME_PERIOD);
                    mraa_pwm_enable(pwm, 1);
                    mraa_pwm_write(pwm, DUTY_CYCLE);
                    float output = mraa_pwm_read(pwm);
                    return 0;
                }
                }
                
                

                 

                The use of the other PWM functions namely: mraa_pwm_period_ms() and mraa_pwm_period_us() has absolutely no effect. I get a constant frequency of 196.8 Hz(Changing the period value has no effect whatsoever)

                 

                Additional notes:

                I use the Arduino expansion board for testing. The swizzler jumpers are in the factory default. The IOREF is set to 3.3V.

                 

                Please ask me if u require any additional information. Waiting for your reply.

                Thanks in advance.

                 

                P.S.

                What is the diff. bw mraa_pwm_period() and mraa_pwm_pulsewidth()?

                • 5. Re: Problems with Intel Edison(SPI, PWM and Timer)
                  Frederic Philips

                  Hi Peter,

                  I made a few changes to the code. I set the Pin 3(pwm0) as output and enabled it into one as mentioned in the following posts: Activate PWM signals from Linux command line and Sysfs PWM programming

                  I used the following: mraa_pwm_period_ms(pwm, 150)

                   

                  Revised Code:

                  /*
                  * PWM_C_Test.c
                  *
                  *  Created on: 06.03.2015
                  *      Author: Frederic P.
                  */
                  #include <unistd.h>
                  #include "mraa.h"
                  
                  #define TIME_PERIOD 150 //Time Period in Hz
                  #define DUTY_CYCLE 0.5f //Duty Cycle(0.0f - 1.0f)
                  
                  int main ()
                  {
                      mraa_init();
                      mraa_gpio_context gpio;
                      gpio = mraa_gpio_init(3);
                      mraa_gpio_dir(gpio, MRAA_GPIO_OUT);
                      mraa_gpio_write(gpio, 1);
                      mraa_pwm_context pwm;
                      pwm = mraa_pwm_init(3);
                      if (pwm == NULL)
                      {
                          return 1;
                          printf("PWM Initialization Failed");
                      }
                      mraa_pwm_period_ms(pwm, TIME_PERIOD);
                      mraa_pwm_enable(pwm, 1);
                      mraa_pwm_write(pwm, DUTY_CYCLE);
                      float output = mraa_pwm_read(pwm);
                      return 0;
                  }
                  
                  

                   

                  I could achieve a frequency of 4.58 Hz but not below that because any TIME_PERIOD value above 150 made absolutely no change.

                  Maybe you guys Intel_Jesus, AlexanderMerz, rwaldron, Intel_Alvarado, KurtE, CMata_Intel could help me out.

                   

                  Thanks in advance

                  • 6. Re: Problems with Intel Edison(SPI, PWM and Timer)
                    KurtE

                    Sorry I am not really any help in this...  The only things I can tell you is what I see in the MRAA code base.  Things like:

                    TIME_PERIOD - Your usage here is in period in ms not in Hz... (probably just a comment issue above)

                    From the MRAA sources for the Edison board we have:

                    pwm_max_period = 218453;
                    pwm_min_period = 1;
                    

                    These values are in us.  So yes the max value you can pass into mraa_pwm_period_ms is 218, which when you take 1000/218 gives you 4.587155963302752. HZ

                     

                    Now again these defines are in the mraa sources.  I could not tell you if these are actual limits to the underlying hardware or not.

                     

                    Kurt

                    • 7. Re: Problems with Intel Edison(SPI, PWM and Timer)
                      Frederic Philips

                      Hi KurtE and Peter,

                      Thanks for the insight. I am guessing that you found the pwm_max_period & pwm_min_period here: mraa/intel_edison_fab_c.c at 73751462953b9bf36e0dba6403841dee77542270 · intel-iot-devkit/mraa · GitHub

                       

                      I investigated the MRAA code-base and found this section of code here: mraa/pwm.c at 41956b07d65bfaed7e872632a67af385f5fbacc4 · intel-iot-devkit/mraa · GitHub

                      • 8. Re: Problems with Intel Edison(SPI, PWM and Timer)
                        Frederic Philips

                        Hi Intel_Peter

                        Have you tested the PWM signal? Waiting for your response...

                        • 9. Re: Problems with Intel Edison(SPI, PWM and Timer)
                          Intel_Peter

                          Hello Frederic Philips,

                           

                          I've been testing PWM on Edison and found out, as you said, one cannot set the PWM frequencies lower than 4.6Hz, I found that weird, so I wrote my own code, nevertheless nothing changed, so I tried a different approach, I tried to set it up on Linux, and that's when I found out that the period is limited to a maximum of 218453000ns, and that's the reason why the frequency can't be set lower than 4,6Hz. The only solution I can think of right now, as I said before would be to use a regular GPIO.

                           

                          Peter.

                          • 10. Re: Problems with Intel Edison(SPI, PWM and Timer)
                            Frederic Philips

                            Hi Peter,

                            Thanks for the info. I also bumped into the same range error when I tried to echo the period setting through the following script:

                             

                            #!/bin/sh
                            
                            echo 254 > /sys/class/gpio/export
                            echo 222 > /sys/class/gpio/export
                            echo 214 > /sys/class/gpio/export
                            echo low > /sys/class/gpio/gpio214/direction
                            echo high > /sys/class/gpio/gpio254/direction
                            echo in > /sys/class/gpio/gpio222/direction
                            echo mode1 > /sys/kernel/debug/gpio_debug/gpio182/current_pinmux
                            echo high > /sys/class/gpio/gpio214/direction
                            echo 2 > /sys/class/pwm/pwmchip0/export
                            echo 1000000000 > /sys/class/pwm/pwmchip0/pwm2/period
                            echo 500000000 > /sys/class/pwm/pwmchip0/pwm2/duty_cycle
                            echo 1 > /sys/class/pwm/pwmchip0/pwm2/enable 
                            

                             

                            Console error:

                            sh: write error: Device or resource busy[ 7737.287462] pwm-intel-mid 0000:00:17.0: Period (ns) must be in range 104:218453000

                             

                            So, anomalous PWM behaviour solved. But still struggling with the SPI: MRAA SPI transmits wierd data