updates
pull/13/head
ArjanteMarvelde 2021-04-07 22:13:13 +02:00
rodzic a060b06065
commit b2c71923a5
5 zmienionych plików z 63 dodań i 23 usunięć

25
dsp.c
Wyświetl plik

@ -64,6 +64,7 @@ uint16_t wave4[64] =
*/
#define DAC_RANGE 250
#define ADC_RANGE 4096
#define ADC_BIAS ADC_RANGE/2
/*
* Callback timeout, determines frequency of TX and RX loops
@ -104,7 +105,7 @@ bool rx(void)
if (q_phase)
{
adc_select_input(1); // Q channel ADC
sample = (int16_t)adc_read() - ADC_RANGE/2;
sample = (int16_t)adc_read() - ADC_BIAS; // Take sample and subtract mid-level
/*
* Shift Q samples
@ -126,7 +127,7 @@ bool rx(void)
else
{
adc_select_input(0); // I channel ADC
sample = (int16_t)adc_read() - ADC_RANGE/2;
sample = (int16_t)adc_read() - ADC_BIAS; // Take sample and subtract mid-level
/*
* Shift I samples
@ -143,7 +144,7 @@ bool rx(void)
// i_s[14] = sample - i_dc; // Calculate output
// i_dc = sample; // Store new i_dc
// sample = i_s[14]; // Get out uncorrected sample
i_s[14] = (sample + i_prev)/2; // Correct phase difference with Q channel
i_s[14] = (sample + i_prev)/2; // Correct for phase difference with Q samples
i_prev = sample; // Remember last sample for next I-phase
/*
@ -164,7 +165,7 @@ bool rx(void)
* Range should be within DAC_RANGE
* Add 250 offset and send to audio DAC output
*/
sample = (i_s[7] - qh)/32;
sample = (i_s[7] - qh)/16;
pwm_set_chan_level(dac_audio, PWM_CHAN_A, DAC_RANGE/2 + sample);
q_phase = true; // Next: Q branch
@ -254,9 +255,9 @@ void dsp_loop()
struct repeating_timer dsp_timer;
bool dsp_callback(struct repeating_timer *t)
{
//if (tx_enabled)
if (tx_enabled)
multicore_fifo_push_blocking(DSP_TX); // Write TX in fifo to core 1
//else
else
multicore_fifo_push_blocking(DSP_RX); // Write RX in fifo to core 1
return true;
@ -269,12 +270,12 @@ void dsp_init()
uint16_t slice_num;
/* Initialize DACs */
gpio_set_function(0, GPIO_FUNC_PWM); // GP0 is PWM for I DAC (Slice 0, Channel A)
gpio_set_function(1, GPIO_FUNC_PWM); // GP1 is PWM for Q DAC (Slice 0, Channel B)
dac_iq = pwm_gpio_to_slice_num(0); // Get PWM slice for GP0 (Same for GP1)
pwm_set_clkdiv_int_frac (dac_iq, 1, 0); // clock divide by 1
pwm_set_wrap(dac_iq, DAC_RANGE); // Set cycle length
pwm_set_enabled(dac_iq, true); // Set the PWM running
// gpio_set_function(0, GPIO_FUNC_PWM); // GP0 is PWM for I DAC (Slice 0, Channel A)
// gpio_set_function(1, GPIO_FUNC_PWM); // GP1 is PWM for Q DAC (Slice 0, Channel B)
// dac_iq = pwm_gpio_to_slice_num(0); // Get PWM slice for GP0 (Same for GP1)
// pwm_set_clkdiv_int_frac (dac_iq, 1, 0); // clock divide by 1
// pwm_set_wrap(dac_iq, DAC_RANGE); // Set cycle length
// pwm_set_enabled(dac_iq, true); // Set the PWM running
gpio_set_function(2, GPIO_FUNC_PWM); // GP2 is PWM for Audio DAC (Slice 1, Channel A)
dac_audio = pwm_gpio_to_slice_num(2); // Find PWM slice for GP2

32
lcd.c
Wyświetl plik

@ -6,6 +6,7 @@
*
* Grove 16x2 LCD, HD44780 chip with JHD1804 I2C interface
* Display RAM addresses 0x00-0x1f for top row and 0x40-0x5f for bottom row
* Character Generator addresses are 0x00-0x07
*
*/
#include <stdio.h>
@ -101,11 +102,19 @@ void lcd_ctrl(uint8_t cmd, uint8_t x, uint8_t y)
i2c_write_blocking(i2c0, I2C_LCD, txdata, 2, false);
sleep_us(39);
break;
case LCD_CURSOR:
if (x==1)
txdata[1] = 0x0e;
else
txdata[1] = 0x0c;
i2c_write_blocking(i2c0, I2C_LCD, txdata, 2, false);
sleep_us(39);
break;
case LCD_GOTO: // 2-row is 0x00-0x27 per row, only 0x00-0x1F are visible
if (y==1)
txdata[1] = x | 0xc0;
txdata[1] = (x&0x0f) | 0xc0;
else
txdata[1] = x | 0x80;
txdata[1] = (x&0x0f) | 0x80;
i2c_write_blocking(i2c0, I2C_LCD, txdata, 2, false);
sleep_us(39);
break;
@ -126,5 +135,22 @@ void lcd_write(uint8_t *s, uint8_t len)
i2c_write_blocking(i2c0, I2C_LCD, txdata, 2, false);
sleep_us(43);
}
}
void lcd_test(void)
{
uint8_t chr[16];
int i, j;
lcd_ctrl(LCD_CLEAR,0,0);
for (i=0; i<16; i++)
{
for(j=0; j<16; j++) chr[j] = (uint8_t)(16*i+j);
lcd_ctrl(LCD_GOTO,0,0);
lcd_write(chr, 16);
sleep_ms(800);
lcd_ctrl(LCD_GOTO,0,1);
lcd_write(chr, 16);
}
lcd_ctrl(LCD_CLEAR,0,0);
}

2
lcd.h
Wyświetl plik

@ -16,10 +16,12 @@
#define LCD_HOME 1
#define LCD_BLINK 2
#define LCD_GOTO 3
#define LCD_CURSOR 4
void lcd_init(void);
void lcd_ctrl(uint8_t cmd, uint8_t x, uint8_t y);
void lcd_write(uint8_t *s, uint8_t len);
void lcd_test(void);
#endif

Wyświetl plik

@ -12,6 +12,7 @@
#include <string.h>
#include "pico/stdlib.h"
#include "lcd.h"
#include "si5351.h"
#include "monitor.h"
@ -29,16 +30,16 @@ uint8_t si5351_reg[200];
/* Commandstring parser */
char delim[] = " ";
#define NCMD 3
char *shell[NCMD] = {"si", "fa", "fb"};
#define NCMD 4
char shell[NCMD][3] = {"si", "lt", "fb", "xx"};
void mon_parse(char* s)
{
char *p;
int base, nreg, i;
p = strtok(s, delim); // Get command part of string
p = s; //strtok(s, delim); // Get command part of string
for (i=0; i<NCMD; i++)
if (strcmp(p, shell[i]) == 0) break;
if (strncmp(p, shell[i], 2) == 0) break;
switch(i)
{
case 0:
@ -50,11 +51,14 @@ void mon_parse(char* s)
break;
case 1:
printf("%s\n", p);
lcd_test();
break;
case 2:
case 3:
printf("%s\n", p);
break;
default:
printf("??\n");
break;
}
}
@ -77,7 +81,7 @@ void mon_read(uint32_t timeout)
case LF: // need to parse command string
putchar((char)c); // echo character
if (i==0) break; // already did a parse, only do it once
mon_cmd[i] = 0; // terminate command string
mon_cmd[i] = '\0'; // terminate command string
i=0; // reset index
mon_parse(mon_cmd); // process command
printf("Pico> "); // prompt

13
uSDR.c
Wyświetl plik

@ -55,12 +55,19 @@ int main()
si_init(); // VFO control unit
lcd_init(); // LCD output unit
dsp_init(); // Signal processing unit
mon_init();
lcd_ctrl(LCD_GOTO, 0, 0);
sprintf(display1, "A: 7074.0 kHz");
lcd_write(display1,13);
SI_SETFREQ(0, 2*7074000UL); // Set freq to 2*7074 kHz
SI_SETPHASE(0,2); // Set phase to 180deg
si_evaluate(); // Commit setting
lcd_test(); // Test LCD character set
lcd_ctrl(LCD_GOTO, 0, 0);
sprintf(display1, " 7074.0 kHz");
lcd_write(display1,11);
lcd_ctrl(LCD_GOTO, 1, 0);
lcd_ctrl(LCD_CURSOR, 1, 0);
while (1)
{