Skip to content

Instantly share code, notes, and snippets.

@benpeoples
benpeoples / main.c
Created July 29, 2023 14:54
avr dmx implementation
#define F_CPU 8000000UL
#include <avr/io.h>
#include <inttypes.h>
#include <util/delay.h>
#include <avr/interrupt.h>
volatile uint8_t universe[513];
uint16_t i;
/*
If systemclock is 144MHz, this generates an interrupt every millisecond
*/
void init_millis() {
RCC_APB1PeriphClockCmd(RCC_APB1Periph_TIM6, ENABLE);
TIM6->PSC = 2; // 144MHz / (65536 - 48000) / (2+1) = 1 milliseconds per tick
TIM6->DMAINTENR = TIM_UIE;
@benpeoples
benpeoples / dmx.c
Created May 27, 2022 20:39
ch32v307 DMX output!
#include "board.h"
#include "ch32v30x.h"
#include "dmx.h"
#include "debug.h"
uint8_t output_buffer[513];
/*
dmx_init();
dmx_send_break();
/*
enable_task outputs a 38.400MHz clock on GPIO 0.
Writing 0 into its queue will turn this output off
Writing 1 into its queue will turn the output on
*/
static void enable_task(void *ignore)
{
@benpeoples
benpeoples / readme.txt
Created June 1, 2020 16:03
ESP32 LEDC Maximum frequency by resolution
Per this forum post: https://esp32.com/viewtopic.php?t=6701
The way to calculate max PWM frequency is integer (log 2 (LEDC_APB_CLK / frequency))
With a LEDC_APB_CLK == 80MHz, these are the following maximum values, in Hz:
LEDC_TIMER_1_BIT, 40000000
LEDC_TIMER_2_BIT, 20000000
LEDC_TIMER_3_BIT, 10000000
LEDC_TIMER_4_BIT, 5000000
LEDC_TIMER_5_BIT, 2500000
@benpeoples
benpeoples / dmx.c
Created April 10, 2020 18:01
ESP32 DMX transmitting task
#define DMX1_IO (0)
#define DMX1_TX (16)
#define DMX1_RX (32)
#define BUF_SIZE (512)
uint8_t data[513]; // This is a global in this case
/*
So this is an incredibly simple transmit-only DMX task for ESP32 ESP-IDF V4
@benpeoples
benpeoples / time.diff
Created March 28, 2018 17:05
ESP32 newlib patch for adjtime
100a101,146
> //// CHANGES TO MAKE ADJTIME EXIST
>
> static uint64_t get_time_since_boot(); // FIXME: Is there a better way to do this?
>
> // adjtime_start stores the start time of the slew
> // adjtime_total is how many microseconds total to slew
> // Maximum is 2^31 microseconds, or about 35 minutes.
> // Typically 500,000 microseconds max for NTP
> // Rate is the speed at which we add data.