Update projects with notes. Allow for tuning.
This commit is contained in:
@@ -8,14 +8,21 @@
|
||||
|
||||
uint32_t count;
|
||||
|
||||
#define ABSOLUTE_MAX_ADC_SET 384 //180 volts (definitely do not exceed)
|
||||
#define ENABLE_TUNING
|
||||
#define ABSOLUTE_MAX_ADC_SET 408 //190ish volts (definitely do not exceed)
|
||||
|
||||
// Specifically, 84 and 38 are tuned for this specific circuit.
|
||||
// Do not mess with them unless you know what you are doing.
|
||||
#define PWM_PERIOD 84
|
||||
#define PWM_MAXIMUM_DUTY 38
|
||||
|
||||
#define ERROR_P_TERM 0 // Actually a shift. 0 is rattl-y but averages out and gives tight control.
|
||||
#ifndef ENABLE_TUNING
|
||||
#define PWM_PERIOD 96
|
||||
#define PWM_MAXIMUM_DUTY 48
|
||||
#else
|
||||
int PWM_PERIOD = 96;
|
||||
int PWM_MAXIMUM_DUTY = 48;
|
||||
#endif
|
||||
|
||||
#define ERROR_P_TERM 1 // Actually a shift. 0 is rattl-y but averages out and gives tight control. -1 is EVEN RATTLIER.
|
||||
|
||||
int target_feedback = 0;
|
||||
int lastadc = 0;
|
||||
@@ -44,7 +51,7 @@ void ADC1_IRQHandler(void)
|
||||
TIM1->CH2CVR = 0;
|
||||
else
|
||||
{
|
||||
err = err >> ERROR_P_TERM;
|
||||
err = err << ERROR_P_TERM;
|
||||
if( err > PWM_MAXIMUM_DUTY ) err = PWM_MAXIMUM_DUTY;
|
||||
TIM1->CH2CVR = err;
|
||||
}
|
||||
@@ -198,6 +205,23 @@ static void HandleCommand( uint32_t dmdword )
|
||||
|
||||
break;
|
||||
}
|
||||
case 4:
|
||||
{
|
||||
#ifdef ENABLE_TUNING
|
||||
// this is only for tuning.
|
||||
if( ( dmdword & 0xff00 ) == 0xaa00 )
|
||||
{
|
||||
int period = (dmdword>>16)&0xff;
|
||||
if( period < 20 ) period = 20;
|
||||
PWM_PERIOD = period;
|
||||
TIM1->ATRLR = PWM_PERIOD;
|
||||
int max_duty = (dmdword>>24)&0xff;
|
||||
if( max_duty > period - 14 ) max_duty = period - 14;
|
||||
PWM_MAXIMUM_DUTY = max_duty;
|
||||
}
|
||||
#endif
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
*DMDATA0 = lastadc << 16;
|
||||
|
||||
@@ -5,6 +5,9 @@
|
||||
|
||||
#include "../../ch32v003fun/minichlink/minichlink.h"
|
||||
|
||||
|
||||
#define ENABLE_TUNING
|
||||
|
||||
int targetnum = 0;
|
||||
int lastsettarget = -1;
|
||||
#define VOLTAGE_SCALE 2.01
|
||||
@@ -35,8 +38,8 @@ void HandleKey( int keycode, int bDown )
|
||||
}
|
||||
|
||||
int do_set = 0;
|
||||
int sety = 0;
|
||||
void HandleButton( int x, int y, int button, int bDown ) { }
|
||||
int sety = 0, setx = 0;
|
||||
void HandleButton( int x, int y, int button, int bDown ) { if( bDown ) setx = x; }
|
||||
void HandleMotion( int x, int y, int mask ) { sety = y; do_set = mask; }
|
||||
void HandleDestroy() { }
|
||||
|
||||
@@ -46,6 +49,7 @@ int volthisthead = 0;
|
||||
|
||||
int main()
|
||||
{
|
||||
char cts[128];
|
||||
void * dev = TryInit_ESP32S2CHFUN();
|
||||
if( !dev )
|
||||
{
|
||||
@@ -70,15 +74,49 @@ int main()
|
||||
CNFGClearFrame();
|
||||
CNFGGetDimensions( &w, &h );
|
||||
|
||||
|
||||
static int set_period = 96;
|
||||
static int set_max_duty = 48;
|
||||
static int last_set_v = 0;
|
||||
{
|
||||
CNFGColor( 0x303030ff );
|
||||
CNFGTackSegment( w-100, 65, w-100, h );
|
||||
#ifdef ENABLE_TUNING
|
||||
CNFGTackSegment( w-200, 65, w-200, h );
|
||||
CNFGTackSegment( w-300, 65, w-300, h );
|
||||
#endif
|
||||
CNFGColor( 0xD0D0D0FF );
|
||||
CNFGPenX = w-100+2; CNFGPenY = 67; sprintf( cts, "VTG %d", last_set_v ); CNFGDrawText( cts, 2 );
|
||||
#ifdef ENABLE_TUNING
|
||||
CNFGPenX = w-200+2; CNFGPenY = 67; sprintf( cts, "Per %d", set_period ); CNFGDrawText( cts, 2 );
|
||||
CNFGPenX = w-300+2; CNFGPenY = 67; sprintf( cts, "Duty %d", set_max_duty ); CNFGDrawText( cts, 2 );
|
||||
#endif
|
||||
}
|
||||
|
||||
if( do_set )
|
||||
{
|
||||
do_set = 0;
|
||||
float set_v = 450 - sety;
|
||||
set_v = set_v/2;
|
||||
if( set_v > 0 && set_v < 195 )
|
||||
float set_v = (450 - sety)/2;
|
||||
if( setx > w - 100 )
|
||||
{
|
||||
rmask = ( ( (uint32_t)(set_v * VOLTAGE_SCALE) ) << 16 ) | 0x41;
|
||||
if( set_v > 0 && set_v < 220 )
|
||||
{
|
||||
last_set_v = (uint32_t)(set_v * 3);
|
||||
rmask = ( last_set_v << 16 ) | 0x41;
|
||||
}
|
||||
}
|
||||
#ifdef ENABLE_TUNING
|
||||
else if( setx > w - 200 )
|
||||
{
|
||||
set_period = set_v;
|
||||
rmask = (set_period<<16) | (set_max_duty<<24) | 0xaa44;
|
||||
}
|
||||
else if( setx > w - 300 )
|
||||
{
|
||||
set_max_duty = set_v;
|
||||
rmask = (set_period<<16) | (set_max_duty<<24) | 0xaa44;
|
||||
}
|
||||
#endif
|
||||
}
|
||||
else if( targetnum == -1 )
|
||||
{
|
||||
@@ -113,14 +151,13 @@ int main()
|
||||
if( ( status & 0xc0 ) == 0x40 ) goto retry;
|
||||
if( r ) { printf( "R: %d\n", r ); status = 0; goto retry; }
|
||||
|
||||
printf( "%08x\n", status );
|
||||
//printf( "%08x\n", status );
|
||||
float voltage = ((float)(status>>16))/VOLTAGE_SCALE;
|
||||
volthist[volthisthead] = voltage;
|
||||
volthisthead = (volthisthead + 1) % VOLTHISTSIZE;
|
||||
CNFGColor( (voltage > 183)?0xff0000ff:GLOW );
|
||||
CNFGColor( (voltage > 192)?0xff0000ff:GLOW );
|
||||
CNFGPenX = 1;
|
||||
CNFGPenY = 1;
|
||||
char cts[128];
|
||||
sprintf( cts, "HV Line: %3.0f V\nRStatus: %d", voltage, r );
|
||||
CNFGDrawText( cts, 4 );
|
||||
|
||||
@@ -136,11 +173,11 @@ int main()
|
||||
float vl = voltage;
|
||||
|
||||
CNFGColor( 0xff0000ff );
|
||||
CNFGTackSegment( 0, 450-180*2-6, w, 450-180*2-6 );
|
||||
CNFGPenX = w - 250; CNFGPenY = 450-180*2-10-6;
|
||||
CNFGDrawText( "WARNING: DO NOT EXCEED THIS LINE (183V)", 2 );
|
||||
CNFGTackSegment( 0, 450-192*2-6, w, 450-192*2-6 );
|
||||
CNFGPenX = w - 250; CNFGPenY = 450-192*2-10-6;
|
||||
CNFGDrawText( "WARNING: DO NOT EXCEED THIS LINE (192)", 2 );
|
||||
|
||||
for( i = 0; i < 9; i++ )
|
||||
for( i = 0; i < 10; i++ )
|
||||
{
|
||||
CNFGColor( (i == 0 )?0xD0D0D0FF:0x303030ff );
|
||||
CNFGPenX = 1;
|
||||
@@ -152,10 +189,10 @@ int main()
|
||||
}
|
||||
|
||||
|
||||
for( i = 0; i < w; i++ )
|
||||
for( i = 0; i < w*2; i++ )
|
||||
{
|
||||
float v = volthist[vhp];
|
||||
CNFGTackSegment( i, 450 - vl*2, i+1, 450 - v*2 );
|
||||
CNFGTackSegment( i/2, 450 - vl*2, i/2+1, 450 - v*2 );
|
||||
vhp = (vhp - 1 + VOLTHISTSIZE*100)%VOLTHISTSIZE;
|
||||
//printf( "%f\n", v );
|
||||
vl = v;
|
||||
|
||||
@@ -1011,8 +1011,8 @@
|
||||
(effects (font (size 1.27 1.27)) (justify left bottom))
|
||||
(uuid 47c5a941-5ea6-4692-87af-c0393bd2065d)
|
||||
)
|
||||
(text "Changes in RevA\n * Probably remove HVIMON >> DEFINITELY\n * Include pull-down on HVCTL >> DEFINITELY.\n * Monitor ripple on HVP (NOT AN ISSUE)\n\nTODO:\nMod HW per Ivan.\n * Ripple is TINY. Can use smaller output cap. 100nF?\n * Output reverse-V is baaad. Maybe add a diode & cap to inverse rail of flyback?\n * Keep P7 on DIG_AUX.\n * Shrink binding post holes.\n * Mark off which pin on header is PGM\n * Reduce power to comma\n * Switch resistors to 15k"
|
||||
(at 16.51 166.37 0)
|
||||
(text "Changes in RevA\n * Probably remove HVIMON >> DEFINITELY\n * Include pull-down on HVCTL >> DEFINITELY.\n * Monitor ripple on HVP (NOT AN ISSUE)\n\nTODO:\nMod HW per Ivan.\n * Ripple is TINY. Can use smaller output cap. 100nF?\n * Output reverse-V is baaad. Maybe add a diode & cap to inverse rail of flyback?\n * Keep P7 on DIG_AUX.\n * Shrink binding post holes.\n * Mark off which pin on header is PGM\n * Reduce power to comma\n * Switch resistors to 15k\n * Transformer should have both rails tied to 5V\n * DO NOT CHANGE R3."
|
||||
(at 16.51 175.26 0)
|
||||
(effects (font (size 1.27 1.27)) (justify left bottom))
|
||||
(uuid 5c570b8c-e31c-47bd-a56b-23a2e3a9d6d7)
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user