Skip to content

Commit

Permalink
stepped modulator working
Browse files Browse the repository at this point in the history
  • Loading branch information
trentgill committed Jul 6, 2024
1 parent 54e94e6 commit 442e117
Show file tree
Hide file tree
Showing 4 changed files with 90 additions and 4 deletions.
69 changes: 69 additions & 0 deletions lib/stepped.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
#include "stepped.h"

int steps = 12;
int current_step = 0;
int reset = 0;
int twoup = 0;
int down = 0;

int vsteps[12] = {0};

void stepped_init(void){
current_step = 0;
reset = 0;
twoup = 0;
down = 0;

float total_real_volts = (2.5f * 120.f / 24.9f);
float offset_real_volts = (2.5f * 120.f / 49.9f);

float one_volt = (float)(0xfff) / total_real_volts; // ~340 lsbs per volt
float half_range = offset_real_volts * one_volt;

for(int i=0; i<6; i++){
vsteps[i] = (int)(half_range - one_volt * i);
}
for(int i=6; i<12; i++){
vsteps[i] = (int)(half_range - one_volt * (i-12));
}
}

void stepped(float _steps, int _reset, int _twoup, int _down){
// perform reset first so we can wrap & then advance on simultaneous triggers
if(_reset != reset){
reset = _reset;
if(reset == 1){
current_step = 0;
}
}

// adjust playhead
if(_twoup != twoup){
twoup = _twoup;
if(twoup == 1){
current_step += 2;
}
}
if(_down != down){
down = _down;
if(down == 1){
current_step -= 1;
}
}

// wrap to steps
// don't use modulo to correctly handle negative values
// could just add steps, and then modulo for simpler solution
steps = 1 + (int)(_steps*11.999f); // [1,12)
while(current_step < 0){
current_step += steps;
}
while(current_step >= steps){
current_step -= steps;
}
}

int stepped_get(void){
// perform scaling
return vsteps[current_step];
}
7 changes: 7 additions & 0 deletions lib/stepped.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#pragma once

void stepped_init(void);

void stepped(float _steps, int _reset, int _twoup, int _down);

int stepped_get(void);
1 change: 1 addition & 0 deletions ll/din.c
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ static const Pin ds[3] =

static GPIO_InitTypeDef g;

// TODO use EXTI instead of manual scanning
void din_init(void){
__HAL_RCC_GPIOB_CLK_ENABLE();

Expand Down
17 changes: 13 additions & 4 deletions main.c
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,15 @@
#include "ll/adc.h"
#include "ll/dac108.h"
#include "ll/adda.h"
#include "lib/stepped.h"

/*
density, C4, 2_in14
steps, A5, 2_in5
rotate, A6, 2_in6
fold, A7, 1_in7
id, B0, 1_in8
offset, B1, 1_in9
density, C4, 2_in14
steps, A5, 2_in5
rotate, A6, 2_in6
MOSI, A0, SAI2_SD_B, AF10
SCK, A2, SAI2_SCK_B, AF8
Expand All @@ -45,7 +46,7 @@ int main(void){
status_led_fast(LED_SLOW); // slow blink until USB connection goes live
status_led_set(1); // set status to ON to show sign of life straight away

printf("\n\nhi from crow!\n");
printf("\n\nhi from parafocus!\n");

lights_init();
lights_all(0);
Expand All @@ -67,6 +68,8 @@ int main(void){
// ii_init( II_CROW );
// Random_Init();

stepped_init();

DAC_Init(32, 16); // 32 samples per block, 16 channels
DAC_Start();

Expand Down Expand Up @@ -103,6 +106,12 @@ int main(void){
ADDA_set_val(i, ADC_get(i));
}
}

stepped(1.f, din_get(DIN_RESET), din_get(DIN_2UP), din_get(DIN_DOWN));
ADDA_set_val(0, stepped_get());
ADDA_set_val(1, 0x0); // set fine tune to zero position
// NOTE: chan 0 is main stepped cv, chan1 is fine tune

// lights_set(0, din_get(DIN_RESET));
// lights_set(1, din_get(DIN_DOWN));
// lights_set(2, din_get(DIN_2UP));
Expand Down

0 comments on commit 442e117

Please sign in to comment.