博文

How to access register in FPGA Verilog?

图片
 In Verilog, “registers” are just flip-flops you create with sequential logic and then expose/read through signals or a bus. Below is a practical cheat-sheet covering declaring , writing , reading , memory-mapped access , register files/BRAM , and best practices . 1) A register = flip-flop updated on a clock module simple_reg ( input wire clk, input wire rst_n, // active-low reset input wire we, // write enable input wire [7:0] d, output wire [7:0] q ); reg [7:0] r; // Verilog “reg” -> storage (flip-flop) assign q = r; // read: just wire it out always @(posedge clk or negedge rst_n) begin if (!rst_n) r <= 8'h00; // reset value else if (we) r <= d; // write on enable end endmodule Key rules Use non-blocking <= in sequential always @(posedge ...) blocks. Reading a register is just using its signal ( q=r ). Sys...

How to run DuckDNS on Raspberry Pi?

图片
 Here’s a clean, reliable way to run DuckDNS on a Raspberry Pi . You can use either a tiny systemd timer (my pick) or a classic cron job. Both call DuckDNS’s HTTPS update API. 0) Get your DuckDNS domain + token Sign in at DuckDNS, add a subdomain, copy your token .  DuckDNS update API (HTTPS) accepts: https://www.duckdns.org/update?domains=<DOMAINS>&token=<TOKEN>[&ip=][&ipv6=][&verbose=true] Leave ip= blank to auto-detect IPv4; add ipv6= if you want to set IPv6 explicitly.  Option A — systemd service + timer (every 5 minutes) 1) Make the updater script sudo mkdir -p /usr/local/lib/duckdns sudo nano /usr/local/lib/duckdns/update.sh Paste (edit the two variables): #!/usr/bin/env bash DOMAINS= "yourdomain1,yourdomain2" # comma-separated, no .duckdns.org TOKEN= "your-token" # Optional: detect a global IPv6 (uncomment next line if you want IPv6 set too) # IPV6_ADDR=$(ip -6 addr show scope global | awk '/inet6...

How to transmit and receive raw data from a microcontroller to a remote computer?

图片
 Here’s a practical, no-fluff roadmap for sending raw bytes between a microcontroller and a remote computer (over the internet). 1) Pick your transport Direct IP from the MCU: MCU with Ethernet/Wi-Fi (e.g., ESP32, W5500, NINA) → TCP or UDP sockets to a public server. Via a gateway: MCU talks UART/USB to a Raspberry Pi (or similar), and the Pi forwards data over TCP/UDP/SSH/VPN. Cellular/LPWAN: Use LTE-M/NB-IoT modem (PPP/AT or built-in sockets). Same socket idea, just different link. Tip: Inbound connections to a device behind NAT are painful. Easiest: host a public server (cloud VM) and have the MCU dial out to it. 2) Frame your “raw” bytes Raw ≠ structureless. Use a tiny frame so both sides can parse: [0xAA 0x55] [LEN(2B)] [PAYLOAD (LEN bytes)] [CRC16(2B)] Or simpler: [LEN][PAYLOAD] . If you stream without length, at least add a delimiter (e.g., '\n') and escape it when it appears in data. 3) Reliability & security TCP gives ordered...

What communication protocol servo used in Arduino?

图片
  Servos, particularly the standard hobbyist servos used with Arduino ,   do not use a common communication protocol like I2C, SPI, or UART.   Instead, they use a much simpler, proprietary signal called   Pulse Width Modulation (PWM) . It's crucial to understand that the servo motor itself is the receiver, and the Arduino sends a command signal to it. The "Protocol": Pulse Width Modulation (PWM) This isn't the same as the PWM used to dim an LED. For servos, the  information is encoded in the duration of a pulse , not the average voltage. Here’s how it works: Signal Type:  A single control wire carries a repeated pulse. Voltage Level:   5V  is the standard for most hobby servos (always check your servo's datasheet!). While the control signal is 5V, the power supply for the motor itself ( VCC  and  GND ) can sometimes handle higher voltages (e.g., 6V or 7.4V), again, check the datasheet. Frequency (Refresh Rate):  The pulse is repeate...

What are the simulation software to simulate STM32 with other components?

图片
  Simulating an STM32 microcontroller alongside other components is a crucial part of embedded development for validating hardware design, firmware logic, and system integration before physical prototypes are available. Here's a comprehensive overview of the simulation software options, categorized by their approach. Category 1: Full System Simulators (MCU + Peripherals + External Components) These are the most powerful options for simulating the entire system, including the STM32 CPU core, its internal peripherals, and external components. 1.  STM32CubeIDE with Built-in Debug/Simulation Features What it is:  ST's official free IDE, which includes a basic internal cycle-accurate simulator. Capabilities: Simulates the  STM32 Cortex-M core  and  most internal peripherals  (GPIO, UART, I2C, SPI, Timers, ADC, etc.). You can write firmware, run it in the simulator, and see register values change in the SFR (Special Function Register) view. It can model ba...