University of Pennsylvania, ESE 5190: Intro to Embedded Systems, Lab 2A
Sizhe Ma
Tested on: Thinkpad X1, Windows 10 Pro, Intel(R) Core(TM) i7-8650U CPU @ 1.90GHz 2.11 GHz
• Why is bit-banging impractical on your laptop, despite it having a much faster processor than the RP2040?、
The custom hardware components take care of specific tasks that the more general multi-tasking CPU is not designed for.
• What are some cases where directly using the GPIO might be a better choice than using the PIO hardware?
Whilst dealing with something like an LED string is possible using "bit-banging", once your hardware protocol gets faster to the point that it is of similar order of magnitude to your system clock speed, there is really not much you can hope to do. The main case where software GPIO access is the best choice is LEDs and push buttons.
• How do you get data into a PIO state machine?
Put data into the FIFO_TXn register of the PIO state machine.
The pull
instruction takes one data item from the transmit FIFO buffer, and places it in the output shift register (OSR). Data moves from the FIFO to the OSR one word (32 bits) at a time
• How do you get data out of a PIO state machine?
The OSR is able to shift this data out, one or more bits at a time, to further destinations, using an out
instruction
The OSR is a staging area for data entering the state machine through the TX FIFO. Data is pulled fromthe TX FIFO into the OSR one 32-bit chunk at a time.
• How do you program a PIO state machine?
There are two ways to program a PIO state machine: using C++ SDK or directly from MicroPython.
• In the example, which low-level C SDK function is directly responsible for telling the PIO to set the LED to a new color? How is this function accessed from the main “application” code?
pio_sm_put_blocking(pio,sm,data)
• What role does the pioasm “assembler” play in the example, and how does this interact with CMake?
We can use it to build your PIO programs, for you to #include
from your C or C++ program. pioasm can also be used directly, and has a few features not used by the C++ SDK, such as generating programs suitable for use with the MicroPython PIO library.
And CMake function pico_generate_pio_header(TARGET PIO_FILE) takes care of invoking pioasm and adding the generated header to the include path of the target TARGET.
The red notation shows how each lines work, and the blue lines show the logic order start from int main()
We choose the color green with value 0x00ff00:
Here is the list of register.
the code below is the tool we use to measure the value of each register:
int main(){
uint32_t grb = 0x00FF00; //blue
int *rgtr = 0x50200000;
PIO pio = pio0; // select Pio module number
int sm = 0; // select state machine number
uint offset = pio_add_program(pio, &ws2812_program);
while (1)
{
stdio_init_all();
printf("the value of registers used in PIO 0 \n");
ws2812_program_init(pio, sm, offset, WS2812_PIN, 800000, IS_RGBW);
// put_pixel(grb);
for (int i = 0; i < 81; i++)
{
printf("%08x, \tvalue = %08x \n", rgtr+i, *(rgtr+i));
}
sleep_ms(5000);
}
return 0;
}
We applied the code in ws2812.c file but change the main function as above. Then the code will print the value with register address in order.
The model/chart with the code is attached below:
As shown in the model, 10 SM clock cycles take place from when color data is written to the FIFO up until the first full bit is sent, and make a numbered column for each time window.
This link is the complete packet transmission spreadsheet and timing diagram.
The code folder named lab2A includes both usb and ws2812 code.
At the beginning, we are confused about the register/value change/interaction between different code file. But some problems can be solved by carefully checking datasheet for some relavent infos. Datasheets would offer excellent helps. For the modeling parts, we randomly choose green 00ff00, then carefully read the documents before modeling.
1)Strength: easy to draw models, easy to view the change of variables. 2) Weakness: hard for data recording and calculation. Only can do some qualitative analysis(hard for bit change visualization). Time consuming.
- easy for quantitative analysis, easy for data recording and data visualization. Saving time
- need to organize the data, hard for plotting.
Electronic device, which could reduce drawing time, but still easy to execute.