Skip to content

Instantly share code, notes, and snippets.

// 1 cycle = 62.5ns
int main()
{
DDRD |= _BV(3);
PORTD &= ~_BV(3);
for (;;)
{
PORTD ^= _BV(3); // 5 cycles
const double _F = F_CPU / 38000.0 + 0.5 - 1;
const double _D = _F * 0.33 + 0.5 - 1;
const uint16_t _cv[] = { 40085, 36.39716198 };
const uint16_t _cp[][2] =
{
{ 97, 24 },
{ 24, 24 },
{ 48, 24 },
@dranger003
dranger003 / ATtiny85_PWM
Last active January 12, 2017 14:11
ATtiny85 Hardware PWM, pins 0, 1 & 4
// ATtiny85
// Hardware PWM, pins 0, 1 & 4
int main()
{
sei();
DDRB = _BV(PORTB0); // OC0A
DDRB |= _BV(PORTB1); // OC0B
DDRB |= _BV(PORTB4); // OC1B
using System;
using System.Threading;
namespace FORMATIQUE
{
public class BlockingQueue<T>
{
private int _head = -1;
private int _tail = -1;
private T[] _buffer;
// FormatBytes.h : includes AtlConvertBytes, AtlFormatBytes
//
// Written by "Daniel Ranger" <dranger003@gmail.com>
// Copyright (c) 2009 Daniel Ranger
//
// DESCRIPTION
//
// Utility functions to convert a number of bytes into either a specific
// unit or the unit based on the multiple of the base (1000 or 1024).
//
#pragma once
struct CFileHandleTraits
{
typedef HANDLE HTYPE;
static const HTYPE INVALID_HANDLE;
static BOOL Close(HTYPE h)
{
return ::CloseHandle(h) != FALSE;
// RefObj.h : includes CRefObject, CRefAutoPtr
//
// Written by "Daniel Ranger" <dranger003@gmail.com>
// Copyright (c) 2009 Daniel Ranger
//
// DESCRIPTION
//
// CRefAutoPtr is a smart pointer class to manage reference count within
// a CRefObject class. A normal smart pointer class manages reference
// count within its own class however in this implementation you must
#define TRIAC_PIN 5
#define ZERO_CROSS_PIN 4
#define DEBOUNCE_TIME 9000 //9ms - 10ms is the pulse period
static uint32_t lastPulse = 0;
static uint16_t period = 5000; //5ms - 50% for each half wave
void ICACHE_RAM_ATTR onTimerISR(){
if(GPIP(TRIAC_PIN)){//OUTPUT is HIGH
GPOC = (1 << TRIAC_PIN);//low
@dranger003
dranger003 / ESP8266-ZeroCrossTriac-Timer0
Created June 29, 2017 23:52
ESP8266 (WEMOS D1) Zero Cross Triac using Timer0 (higher resolution/quality than Timer1)
#define TIMR_OVRHD 7000
uint8_t _z = 0;
uint32_t _v = 20000;
void ICACHE_RAM_ATTR _ISR0() {
if (_z == 1) {
_z = 2;
timer0_write(ESP.getCycleCount() + 8000); // 8000 = 100us, 80000 = 1ms
digitalWrite(D2, HIGH);
@dranger003
dranger003 / ffmpeg-hevc-encode-nvenc.md
Created January 21, 2018 19:23
This gist shows you how to encode specifically to HEVC with ffmpeg's NVENC on supported hardware, with a two-pass profile and optional CUVID-based hardware-accelerated decoding.

Encoding high-quality HEVC content with FFmpeg - based NVENC encoder on supported hardware:

If you've built ffmpeg as instructed here on Linux and the ffmpeg binary is in your path, you can do fast HEVC encodes as shown below, using NVIDIA's NPP's libraries to vastly speed up the process.

Now, to do a simple NVENC encode in 1080p, (that will even work for Maxwell Gen 2 (GM200x) series), start with:

ffmpeg  -i <inputfile>  \
-filter:v hwupload_cuda,scale_npp=w=1920:h=1080:format=nv12:interp_algo=lanczos,hwdownload \

-c:v hevc_nvenc -profile main -preset slow -rc vbr_hq \