Circuits Playground now has a scope

Practice embedded systems, from registers to RTL.

250+ problems in embedded C, Verilog, VHDL and Assembly, compiled and checked against test cases from your browser. Interview questions from real hiring loops, and a circuit simulator with a working scope.

Interrupt-Safe Ring Buffer

A 64-byte buffer the UART interrupt fills and main() drains. Volatile indices, no locks, no malloc.

Hard C
ring_buffer.c gcc -std=c11
1#include <stdint.h>2 3#define RB_SIZE 64u  /* power of two: wrap is a mask */4 5static uint8_t buf[RB_SIZE];6static volatile uint8_t head, tail;7 8/* Runs in the UART RX interrupt. */9int rb_push(uint8_t d)10{11    uint8_t next = (head + 1u) & (RB_SIZE - 1u);12    if (next == tail) return -1;  /* full */13    buf[head] = d;14    head = next;           /* publish after the write */15    return 0;16}17 18int rb_pop(uint8_t *d)19{20    21}

RC low-pass filter

1 kΩ and 1 µF put the cutoff at 159 Hz. Drive it there and the output sits 3 dB down and 45° behind.

Playground
CH1 CH2 V1 5 V 159 Hz R1 1 kΩ C1 1 µF
CH1 2.00 V/div CH2 2.00 V/div 2.00 ms/div CH2 3.54 Vpk

Also on DeetCode

  • Study

    Nine modules, from Embedded C and MCU architecture to RTOS, protocols and PCB design.

  • Interview Vault

    Interview experiences written up by the engineers who sat them.

  • Discuss

    Questions, openings and design reviews from people doing the same work.

  • Leaderboard

    Every accepted solution earns XP: 15 for Easy, 30 for Medium, 55 for Hard.