PWM pins in jumpers

All technical discussions and projects around startKIT
User avatar
mon2
XCore Legend
Posts: 1913
Joined: Thu Jun 10, 2010 11:43 am
Contact:

Post by mon2 »

Hi @Schatz143. The website was reformatted a bit so some links have been broken but believe your requested project(s) may be found here:

https://www.xcore.com/viewforum.php?f=21


User avatar
mon2
XCore Legend
Posts: 1913
Joined: Thu Jun 10, 2010 11:43 am
Contact:

Post by mon2 »

Also, study the examples here:

https://github.com/xcore/sw_startkit_examples

Even though the kit used is the older (EOL) Startkit, the source code is still applicable to all current XMOS CPU devices. Just target your current kit and use the port pins to suit the project.
Schatz143
Member++
Posts: 31
Joined: Mon Jan 20, 2020 9:54 am

Post by Schatz143 »

HI mon2!
Thanks for the links.
I tried to generate a clock signal found in programming guide on xcore200 explorer kit.Its like this#include <xs1.h>
#include <timer.h>
#include<platform.h>
#include <stdio.h>

out port p_out = XS1_PORT_8A;
out port p_clock_out = XS1_PORT_1A;
clock clk = XS1_CLKBLK_1; /*identifier for clock named clk*/


int main(void)
{
configure_clock_rate(clk, 100, 8); /*configures clock to 100/8 =12.5Mhz*/
configure_out_port(p_out, clk, 0);/* configures outputport p_out with 0*/
configure_port_clock_output(p_clock_out , clk);
start_clock(clk);

for (int i=0; i<5; i++)
p_out <: i;

}
I get the error "Binary (xs1_revb) does not match architecture (xs2_re)" Where am i missing ?.would be much appreciated.I would like to connect external osciloscope to check the generated clock signal frequency. How can i do that? Please guide me.Thanks
User avatar
mon2
XCore Legend
Posts: 1913
Joined: Thu Jun 10, 2010 11:43 am
Contact:

Post by mon2 »

Hi. Here are some pointers:

1) Please use the code markers in your posts to format the code to be easier to view.

Here is the same code using the code markers ("CODE DISPLAY" above the post form tool):

Code: Select all

out port p_out = XS1_PORT_8A;
out port p_clock_out = XS1_PORT_1A;
clock clk = XS1_CLKBLK_1; /*identifier for clock named clk*/


int main(void)
{
configure_clock_rate(clk, 100, 8); /*configures clock to 100/8 =12.5Mhz*/
configure_out_port(p_out, clk, 0);/* configures outputport p_out with 0*/
configure_port_clock_output(p_clock_out , clk);
start_clock(clk);

for (int i=0; i<5; i++)
p_out <: i;

}
2) A little trick I like to use when working with the various XMOS CPU devices is as follows:

a) launch a fresh workspace
b) upon reaching the IDE -> select the EXAMPLES icon on left side bar -> allow the tool to populate
c) select from an example that is closest to your CPU -> for your immediate project, I selected XCORE-200 Explorer Kit -> AN00155 (SIMPLE GPIO example -> double click to import this project
d) once back in EDIT perspective -> Project (top bar) -> Build All -> this project build will generate some errors that will auto-resolve as the project will demand some extra libraries to be imported and/or updated -> allow for the tool to auto resolve the issues. In the end, the AN00155 will build correctly and generate an executable binary with the .XE suffix.
e) After the above confirmation of a successful build, proceed to locate the main.xc file and massage this file to be your own.

Here is your code inside the same GPIO project:

Code: Select all

// Copyright (c) 2016, XMOS Ltd, All rights reserved

#include <xs1.h>
#include <platform.h>
#include <gpio.h>


out port p_out = XS1_PORT_8A;
out port p_clock_out = XS1_PORT_1A;
clock clk = XS1_CLKBLK_1; /*identifier for clock named clk*/


int main(void)
{
configure_clock_rate(clk, 100, 8); /*configures clock to 100/8 =12.5Mhz*/
configure_out_port(p_out, clk, 0);/* configures outputport p_out with 0*/
configure_port_clock_output(p_clock_out , clk);
start_clock(clk);

for (int i=0; i<5; i++)
p_out <: i;

}
/*
// GPIO port declarations
on tile[0] : in port explorer_buttons = XS1_PORT_4E;
on tile[0] : out port explorer_leds = XS1_PORT_4F;

// GPIO handler routine
void gpio_handler(client input_gpio_if button_1, client input_gpio_if button_2,
                  client output_gpio_if led_green, client output_gpio_if rgb_led_blue,
                  client output_gpio_if rgb_led_green, client output_gpio_if rgb_led_red) {

  // LED state
  unsigned int green_led_state = 0;
  unsigned int rgb_led_state = 0;

  // Initial button event state, active low
  button_1.event_when_pins_eq(0);
  button_2.event_when_pins_eq(0);

  while (1) {
    select {
      // Triggered by events on button 1
      case button_1.event():
        if (button_1.input() == 0) {
          green_led_state = ~green_led_state;
          led_green.output(green_led_state);
          // Set button event state to active high for debounce
          button_1.event_when_pins_eq(1);
        } else {
          // Debounce button
          delay_milliseconds(50);
          button_1.event_when_pins_eq(0);
        }
        break;

      // Triggered by events on button 2
      case button_2.event():
        if (button_2.input() == 0) {
          rgb_led_red.output(0);
          rgb_led_green.output(0);
          rgb_led_blue.output(0);
          rgb_led_state++;
          rgb_led_state %= 4;

          switch (rgb_led_state) {
            case 1:
              rgb_led_red.output(1);
              break;
            case 2:
              rgb_led_green.output(1);
              break;
            case 3:
              rgb_led_blue.output(1);
              break;
          }
          // Set button event state to active high for debounce
          button_2.event_when_pins_eq(1);
        } else {
          // Debounce button
          delay_milliseconds(50);
          button_2.event_when_pins_eq(0);
        }
        break;
    }
    // end of event select
  }

}

// The main() function runs a single task which takes the gpio interfaces as parameters
int main() {
  input_gpio_if i_explorer_buttons[2];
  output_gpio_if i_explorer_leds[4];
 
  par {
     on tile[0] : input_gpio_with_events(i_explorer_buttons, 2, explorer_buttons, null);
     on tile[0] : output_gpio(i_explorer_leds, 4, explorer_leds, null);
     on tile[0] : gpio_handler(i_explorer_buttons[0], i_explorer_buttons[1],
                               i_explorer_leds[0], i_explorer_leds[1],
                               i_explorer_leds[2], i_explorer_leds[3]);
  } 

   return 0;
}

*/
Project -> Build All again.

Then code should build fine but this time with your custom code.

xmos_pwm_compiled.png
(18.67 KiB) Not downloaded yet
xmos_pwm_compiled.png
(18.67 KiB) Not downloaded yet
Give it a try and post your results.

Also, personally also like to use real external tools to validate the hardware but do note that the XMOS toolchain features a simulator where you can test your code run without actual hardware. There are some code examples on how to use this tool (EXAMPLES (left bar) -> XSCOPE examples).
Schatz143
Member++
Posts: 31
Joined: Mon Jan 20, 2020 9:54 am

Post by Schatz143 »

Hi mon2!
Thanks for the trick.It was succesful to build .
But i tried to check the signal using external osciloscope for ( out port p_out = XS1_PORT_8A;
out port p_clock_out = XS1_PORT_1A;) .I believe i am checking at the wrong I/O PINS ,I cannot see any signal on the scope.
on which I/O Pin should i have the differential probe?.I tried on D1 Pin and D0 with J14 as GND.
I have checked the datasheet of XE216-512-TQ-TQ128 for signal X1D01 -X1D09 can be 4A OR 8A OR 16A .
Which pin should i be checking ? I am sorry if its silly.Would appreciate it.
Attachments
Build finish.png
Build finish.png (91 KiB) Viewed 12228 times
Build finish.png
Build finish.png (91 KiB) Viewed 12228 times
User avatar
mon2
XCore Legend
Posts: 1913
Joined: Thu Jun 10, 2010 11:43 am
Contact:

Post by mon2 »

Hi. Glad to see that you are getting closer! It is exciting when it all works correctly.

1) You are correct on your hunch that you are on the wrong port pins for the probing.

2) Please note from the datasheet that this specific CPU has 2 tiles and each tile features 8 virtual CPU cores. Respectively, the nomenclature used by XMOS is that:

X0 prefix is for the Tile # 0 port pins
X1 prefix is for the Tile # 1 port pins

and so on.

From your code, you are working with Tile # 0 so reference the port pins with the X0 prefix.

Specifically, your p_out block of GPIO pins is XS1_PORT_8A which is a 8 bit port. On Tile # 0, on this device, reference:

X0D02..X0D09 port pins, inclusively.

XMOS_Port_8A.png
(204.36 KiB) Not downloaded yet
XMOS_Port_8A.png
(204.36 KiB) Not downloaded yet

Now do note that if you were to also map out say XS1_PORT_4A in the same code run then you would "wax away" (peel off) the use of 4 bits from the XS1_PORT_8A (8A0, 8A1, 8A6, 8A7) due to this overlap. That is, the LEFT side of the I/O pin table has a higher priority than the right side port labels. You may still continue to use the remainder of the 8 bit port as-is but the noted port pins (8A0, 8A1, 8A6, 8A7) are no longer available as they have been assigned to the higher priority 4 bit port label.

Do try again and post your results.

Hop this helps.
Schatz143
Member++
Posts: 31
Joined: Mon Jan 20, 2020 9:54 am

Post by Schatz143 »

Hi
Its clearly exciting.
And i run the program once again its terminated automatically with in seconds .I attach the screen shot here.I didnt notice from starting.I think after the run its terminated quickly before i use probes(Kit was connected during the time).I dont know the reason surely.
Attachments
terminated quickly.png
(67.04 KiB) Not downloaded yet
terminated quickly.png
(67.04 KiB) Not downloaded yet
User avatar
mon2
XCore Legend
Posts: 1913
Joined: Thu Jun 10, 2010 11:43 am
Contact:

Post by mon2 »

Correct. After 20 iterations of your loop, the code will exit. Keep in mind that this CPU is extremely fast and the code run is done before you can even blink.

Try again but with a permanent loop as follows:

Code: Select all

while(1)
{
 for (int i=0; i<20; i++)
   p_out <: i;
}
Schatz143
Member++
Posts: 31
Joined: Mon Jan 20, 2020 9:54 am

Post by Schatz143 »

Hi there!
The code is running .but no signal at D0 I/ O pin with probes.
As mentioned above X0D02..X0D09 port pins. Doesnt that mean i shoud use probes at D0?
User avatar
mon2
XCore Legend
Posts: 1913
Joined: Thu Jun 10, 2010 11:43 am
Contact:

Post by mon2 »

When you say probes, do you mean external probes on an external tool or XMOS scope software tool?

Can you post your full source code for a review?

Also if using xmos scope tool, attempt one of the XMOS supplied examples to be sure that works before testing your custom code.
Post Reply