mirror of
https://github.com/cnlohr/lolra.git
synced 2026-06-15 07:19:25 +00:00
Functioning w/ speaker
This commit is contained in:
@@ -91,17 +91,18 @@ SOFTWARE.
|
||||
Calculated to use the 19.75th harmonic @ 27.08571429MHz, but ideal found at 27.08643MHz
|
||||
*/
|
||||
|
||||
#define Q 1800
|
||||
#define Q 2080
|
||||
|
||||
|
||||
// For Quadrature - use 30
|
||||
// For nonquadrature use 40.
|
||||
|
||||
#define PWM_PERIOD (40-1) //For 27MHz
|
||||
//#define QUADRATURE
|
||||
#define PWM_PERIOD (28-1) //For 27MHz
|
||||
#define QUADRATURE
|
||||
//#define TIGHT_OUT
|
||||
//#define DUMPBUFF
|
||||
#define PWM_OUTPUT 1
|
||||
|
||||
#define PWM_OUTPUT 9
|
||||
|
||||
//#define PWM_PERIOD (32-1)
|
||||
//#define QUADRATURE
|
||||
@@ -124,12 +125,13 @@ void SetupADC()
|
||||
// Set up single conversion on chl 7
|
||||
ADC1->RSQR1 = 0;
|
||||
ADC1->RSQR2 = 0;
|
||||
ADC1->RSQR3 = 7; // 0-9 for 8 ext inputs and two internals
|
||||
ADC1->RSQR3 = 6; // 0-9 for 8 ext inputs and two internals /// 7 or 6 means one of the ADC inputs.
|
||||
|
||||
// Not using injection group.
|
||||
|
||||
// PD4 is analog input chl 7
|
||||
// PD4 is analog input chl 7 + 6
|
||||
GPIOD->CFGLR &= ~(0xf<<(4*4)); // CNF = 00: Analog, MODE = 00: Input
|
||||
GPIOD->CFGLR &= ~(0xf<<(4*6)); // CNF = 00: Analog, MODE = 00: Input
|
||||
|
||||
// Sampling time for channels. Careful: This has PID tuning implications.
|
||||
// Note that with 3 and 3,the full loop (and injection) runs at 138kHz.
|
||||
@@ -282,13 +284,14 @@ void InnerLoop()
|
||||
s = (s + is/s)/2;
|
||||
|
||||
|
||||
#ifdef TIGHT_OUT
|
||||
printf( "%d\n", s );
|
||||
#elif defined( PWM_OUTPUT )
|
||||
int tv = (s>>PWM_OUTPUT) + (PWM_PERIOD/2);
|
||||
int tv = (i>>PWM_OUTPUT) + (PWM_PERIOD/2);
|
||||
if( tv < 0 ) tv = 0;
|
||||
if( tv >= PWM_PERIOD ) tv = PWM_PERIOD-1;
|
||||
TIM1->CH3CVR = tv;
|
||||
|
||||
#ifdef TIGHT_OUT
|
||||
printf( "%d\n", tv );
|
||||
#elif defined( PWM_OUTPUT )
|
||||
TIM1->CH4CVR = tv;
|
||||
#else
|
||||
|
||||
printf( "%8d I:%7d Q:%7d [%d %d %d %d] / %d\n",s, i ,q, adc_buffer[0], adc_buffer[1], adc_buffer[2], adc_buffer[3], (int)(SysTick->CNT - tstart) );
|
||||
|
||||
Reference in New Issue
Block a user