Embedded Systems Notes: PIC and ARM
PIC
Interrupts
Interrupts can be grouped, masked, and managed through a common entry point. The handler checks pending flags to distinguish the sources. Clear stale flags before enabling a source. External interrupt inputs may support selectable triggering edges. The falling edge can be sharper on circuits that drive low more strongly, so choose based on the actual signal. A change interrupt can use an XOR comparison between successive port states.
Power, configuration, and I/O
The original PIC example uses a lower internal voltage and a higher port voltage for reliability. Hardware configuration words establish options such as reset and oscillator settings before ordinary execution. Compared with the 80C51, these PIC examples add clamp diodes, analog/digital selection, direction selection, and configurable pull-ups. Internal oscillators can be calibrated externally. The available choices trade off response speed, power, and noise immunity.
- The voltage examples use A=5 V, B=3.3 V, and C=1.8 V. Example general I/O thresholds are 70% of Vcc for high and 30% for low. Reset examples use 80% and 12%. Thresholds depend on the part.
- Rise time is commonly measured from 10% to 90% of Vcc, and fall time from 90% to 10%. The original rule of thumb is to keep each transition within 4% of the signal period. A lower signal frequency increases the available time.
- Clock control at the component level reduces dynamic power and can help manage interference. A hardware watchdog detects stalled software and can reset the device. Reset reason flags help firmware choose a recovery path.
- Push-pull outputs actively drive both levels. Open-collector and open-drain outputs require a pull-up for the high level. Their switching behavior depends on the load and pull-up.
ARM architecture
Instruction set extensions and processor families
- T: Thumb uses compact encodings. The original notes estimate typical code size at roughly 65% of ARM code. Smaller code can improve fetch efficiency, while some operations need additional instructions. Classic exception entry has its own instruction-state requirements. Classic Thumb appears in ARMv4T and later variants.
- D: On-chip debug support can halt execution on debugger request.
- M: Enhanced multiplication supports a 64-bit result from two 32-bit operands, with long multiply and multiply-accumulate instructions.
- I: EmbeddedICE provides breakpoint and watchpoint facilities.
- E: Enhanced DSP instructions include 16-bit multiply or multiply-accumulate and signed saturating arithmetic.
- J: Jazelle accelerates some Java bytecode execution in historical ARM implementations.
- S: A synthesizable design can be supplied in an HDL such as VHDL or Verilog.
Architecture revisions balance performance improvements and compatibility. Thumb-2 was introduced with ARMv6T2. ARMv7 profiles include A for application processors, R for real-time workloads, and M for microcontrollers. Cortex product lines span several architecture generations.
Buses and execution modes
AMBA defines on-chip buses. AHB connects higher-performance blocks and supports single, burst, and split transactions in applicable variants. ASB supports burst transfers. APB provides a simpler interface for low-bandwidth peripherals.
Classic ARM modes include user, FIQ, IRQ, supervisor, abort, system, and undefined-instruction modes. Software and exception entry can change mode. ARM and Thumb are instruction states. In classic configurations, reset enters ARM state, and interworking instructions select the target state. Assembly directives such as CODE16 and CODE32 select instruction encoding during assembly.
Classic ARM has 31 general-purpose registers and six status registers when banked copies are counted. R0–R7 are unbanked, R8–R14 are banked in some modes, and R15 is the program counter. The CPSR includes the interrupt masks, Thumb state, and mode bits. Classic Thumb emphasizes R0–R7 and also uses registers such as SP and LR.
Exception vectors cover reset, undefined instructions, software interrupts, prefetch and data aborts, IRQ, and FIQ. ARM implementations can support little- and big-endian data. Alignment constraints vary with instruction and architecture. I/O commonly uses ordinary load and store instructions on memory-mapped device registers.
Memory and flash
Primary storage includes ROM and RAM. Secondary storage includes disks and flash-based media such as CF and SD cards. An illustrative latency hierarchy runs from registers and cache through SRAM, DRAM, and ROM. NAND flash reads and programs pages and erases blocks. The K8F1208 example organizes 4,096 blocks into 32 pages per block, with 512 data bytes and 16 spare bytes per page. An address selects the block, page, and location within the page.
The MMU translates virtual to physical addresses and checks access permissions. Broad memory-management schemes include segmentation, paging, and combinations of both. ARM architectural translation uses page tables with multiple supported mapping sizes.
S3C2410 clocks and power
FCLK feeds the CPU, HCLK feeds AHB devices, and PCLK feeds APB devices. PLLs multiply an external reference clock. The example has a main system PLL and a USB PLL, and software can gate clocks where supported to save power.
- Idle stops the CPU core clock.
- Normal operation allows software clock control.
- Slow operation can bypass the PLL.
- Sleep or power-down can wake on an external EINT[15:0] or RTC alarm when the wake logic has power.
The example uses a 1.8 V core and 3.3 V processor and memory I/O. Power-on delays and supply sequencing give rails time to settle before initialization. Hardware configuration provides flexibility while software libraries can simplify development and portability.
Timers
- The watchdog uses PCLK or an implementation-specific clock. It can provide a timer interrupt or reset the system. Typical components include prescalers, WTDAT, WTCNT, WTCON, and reset logic. Configure it before starting it.
- The real-time clock can have its own clock or supply. Reads across a rollover can produce inconsistent fields, so software can verify a stable reading or use hardware latching if available. The RTC also supports alarms.
- Timer hardware can generate PWM and manage dead time for power electronics. Some timers generate DMA requests. DMA and CPU accesses can contend for the same bus, so software delay loops may become less predictable.
Interrupts and DMA
Peripherals can use polling, interrupts, or DMA. Interrupts provide good response without constant polling and require careful debugging when nested. IRQ and higher-priority FIQ are distinct classes. Controllers can group or vector sources and use masks, pending flags, and priorities.
DMA transfers data directly between supported peripherals and memory or between memory regions. It reduces CPU instruction overhead and supports fast devices that would be impractical to service byte by byte with interrupts. A controller may offer single-service requests, single-service handshake, or full-service handshake. Features to check include priorities, valid source and destination pairs, sustained throughput, block and burst modes, and completion interrupts. Shared bus use can change CPU timing.