Compare commits

..

10 commits

Author SHA1 Message Date
stephan
bf69d871f4 chaos avr: redefine 2nd parameter of hv_osc_init() as dc
git-svn-id: svn+ssh://asterix.ieap.uni-kiel.de/home/subversion/stephan/solo/eda/arm/avr@8894 bc5caf13-1734-44f8-af43-603852e9ee25
2024-03-08 17:24:26 +00:00
stephan
119f776fc3 chaos avr: symmetric hvosc gap
git-svn-id: svn+ssh://asterix.ieap.uni-kiel.de/home/subversion/stephan/solo/eda/arm/avr@8893 bc5caf13-1734-44f8-af43-603852e9ee25
2024-03-08 16:57:03 +00:00
stephan
09face2e57 chaos avr: LED pin numbers
git-svn-id: svn+ssh://asterix.ieap.uni-kiel.de/home/subversion/stephan/solo/eda/arm/avr@8891 bc5caf13-1734-44f8-af43-603852e9ee25
2024-03-08 16:51:44 +00:00
stephan
85b304d7db chaos avr: fixes
git-svn-id: svn+ssh://asterix.ieap.uni-kiel.de/home/subversion/stephan/solo/eda/arm/avr@8890 bc5caf13-1734-44f8-af43-603852e9ee25
2024-03-06 16:46:53 +00:00
stephan
77452de170 avr chaos: conf_init() execution order
git-svn-id: svn+ssh://asterix.ieap.uni-kiel.de/home/subversion/stephan/solo/eda/arm/avr@8880 bc5caf13-1734-44f8-af43-603852e9ee25
2024-02-28 14:06:42 +00:00
stephan
6d56b99f89 avr chaos: hvled
git-svn-id: svn+ssh://asterix.ieap.uni-kiel.de/home/subversion/stephan/solo/eda/arm/avr@8879 bc5caf13-1734-44f8-af43-603852e9ee25
2024-02-28 13:52:52 +00:00
stephan
50ab323173 arv/chaos: move ADC_SDO to PD1
git-svn-id: svn+ssh://asterix.ieap.uni-kiel.de/home/subversion/stephan/solo/eda/arm/avr@8878 bc5caf13-1734-44f8-af43-603852e9ee25
2024-02-28 13:08:32 +00:00
stephan
ec13f94d99 avr/chaos: upcase()
git-svn-id: svn+ssh://asterix.ieap.uni-kiel.de/home/subversion/stephan/solo/eda/arm/avr@8839 bc5caf13-1734-44f8-af43-603852e9ee25
2024-01-28 12:43:50 +00:00
stephan
67981e803f avr/chaos: hvosc_gap
git-svn-id: svn+ssh://asterix.ieap.uni-kiel.de/home/subversion/stephan/solo/eda/arm/avr@8837 bc5caf13-1734-44f8-af43-603852e9ee25
2024-01-26 21:52:29 +00:00
stephan
20c6f1a801 avr/chaos: poke, hvosc DDR
git-svn-id: svn+ssh://asterix.ieap.uni-kiel.de/home/subversion/stephan/solo/eda/arm/avr@8836 bc5caf13-1734-44f8-af43-603852e9ee25
2024-01-26 15:30:03 +00:00
6 changed files with 115 additions and 57 deletions

View file

@ -59,8 +59,8 @@ lfuse_sologse=0xA0
lfuse_chaos=0xef
chaos_CFLAGS = -I.
chaos.o: ads8688.h ltc1655.h spi_slave.h tick.h hvosc.h
chaos.s: ads8688.h ltc1655.h spi_slave.h tick.h hvosc.h
chaos.o: ads8688.h ltc1655.h spi_slave.h tick.h hvosc.h hvled.h
chaos.s: ads8688.h ltc1655.h spi_slave.h tick.h hvosc.h hvled.h
%.lfuse:
$(AVRDUDE) -p $(pMCU-$(MCU)) -P $(AVRDUDE_PORT) -c $(AVRDUDE_PROGRAMMER) \

View file

@ -2,11 +2,11 @@
#define ADC_SDI 4
#define ADC_SCK 5
#define ADC_CE 7
#define ADC_SDO 2
#define ADC_SDO 1
#define ADC_PO PORTD
#define ADC_PI PORTB
#define PORTB_IO 0x05
#define PORTD_IO 0x0b
#define ADC_PI PORTD
#define ADC_PO_IO _SFR_IO_ADDR(ADC_PO)
#define ADC_PI_IO _SFR_IO_ADDR(ADC_PI)
static inline void ads8688_init()
{
DDRD |= 0xb0;
@ -26,7 +26,7 @@ static inline void ads8688_write(unsigned char c, unsigned char i)
"nop" "\n\t"
"cbi %[p], %[ck]" "\n"
:
:[p] "n" (PORTD_IO),
:[p] "n" (ADC_PO_IO),
[d] "n" (ADC_SDI),
[ck] "n" (ADC_SCK),
[c] "r" (c),
@ -34,12 +34,6 @@ static inline void ads8688_write(unsigned char c, unsigned char i)
}
static inline void ads8688_read(unsigned char *r, unsigned char *rr, unsigned char i)
{
#if 0
ADC_PO |= (1<<ADC_SCK);
if (ADC_PI & (1<<ADC_SDO)) *r |= 1<<i;
if (!(ADC_PI & (1<<ADC_SDO))) *r &=~(1<<i);
ADC_PO &=~ (1<<ADC_SCK);
#else
// qq is a dummy requested here to avoid load/store between bytes.
__asm__("sbi %[pk], %[ck]" "\n\t"
@ -55,14 +49,13 @@ static inline void ads8688_read(unsigned char *r, unsigned char *rr, unsigned ch
"nop" "\n"
:[q] "+d" (*r), // ORI needs r16..r31
[qq] "+d" (*rr)
:[pk] "n" (PORTD_IO),
[pd] "n" (PORTB_IO),
:[pk] "n" (ADC_PO_IO),
[pd] "n" (ADC_PI_IO),
[d] "n" (ADC_SDO),
[ck] "n" (ADC_SCK),
[i] "n" (1<<i),
[ii] "n" (0xff&~(1<<i))
);
#endif
}
static inline void ads8688_frame(const unsigned char *c, unsigned char *r)
@ -92,7 +85,7 @@ static inline void ads8688_frame(const unsigned char *c, unsigned char *r)
__asm__("nop" "\n\t"
"cbi %[p], %[d]" "\n"
:
:[p] "n" (PORTD_IO),
:[p] "n" (ADC_PO_IO),
[d] "n" (ADC_SDI)
);

View file

@ -2,6 +2,8 @@
// ATmega32M1
#define upcase(c) (!((c)&0x20))
const char *revision =
"$Id$";
@ -18,6 +20,7 @@ void ads8688_cmd(const unsigned char *c, unsigned char *r);
void ltc1655_cmd(const unsigned char *c);
void ads8688_config();
#include "hvled.h"
#include "tick.h"
#include "hvosc.h"
@ -46,7 +49,7 @@ static inline unsigned int avradc_data()
{
unsigned int r = ADCL;
r |= ADCH << 8;
r |= ADMUX << 13;
r |= ADMUX << 11;
return r;
}
@ -105,7 +108,8 @@ struct {
unsigned char portc_on;
unsigned char portc_off;
unsigned char hvosc_freq;
unsigned char padding[1];
unsigned char hvosc_dc;
unsigned char padding[2];
} conf = {
.wdt_timeout = 10, // 2 min
.wdt_tick_period = TICK_NS(100000L), // 100µs
@ -113,7 +117,8 @@ struct {
.avradc = 0x7f, // off
.adcconf = 0x8500,// RST
.ddrc = 2, // OC1B HVOSC
.hvosc_freq = 88, // 125 kHz
.hvosc_freq = 51,
.hvosc_dc = 9,
};
enum {
@ -127,6 +132,7 @@ enum {
FLAG2_PORTC = 1,
FLAG2_PC_HV = 2,
FLAG2_HVOSC = 4,
FLAG2_HVLED = 8,
};
void conf_init()
@ -134,19 +140,23 @@ void conf_init()
tick_init(conf.tick_period);
if (conf.flags & FLAG_WDT)
wdt_init(conf.wdt_mode);
if (conf.flags2 & FLAG2_HVOSC) {
conf.ddrc |= 2;
hvosc_init(conf.hvosc_freq, conf.hvosc_dc);
}
if (conf.flags & FLAG_ADCCONF)
ads8688_config();
if (conf.flags & FLAG_DACADC)
conf.dac = dacadc_read();
if (conf.flags & FLAG_RAMP)
dac_ramp(conf.dac_nominal);
if (conf.flags & FLAG_ADC)
avradc_enable(conf.avradc);
if (conf.flags & FLAG_DAC)
avrdac_set(conf.avrdac);
if (conf.flags & FLAG_ADCCONF)
ads8688_config();
if (conf.flags & FLAG_DACADC)
conf.dac = dacadc_read();
if (conf.flags2 & FLAG2_HVOSC) {
conf.ddrc |= 2;
hvosc_init(conf.hvosc_freq);
if (conf.flags2 & FLAG2_HVLED) {
conf.ddrc |= LED_MASK;
led_init();
}
if (conf.flags2 & FLAG2_PORTC) {
PORTC = conf.portc;
@ -154,6 +164,16 @@ void conf_init()
}
}
static inline void led_hv()
{
if (conf.flags2 & FLAG2_HVLED) {
if (conf.dac == conf.dac_off)
led_toggle(LED_GREEN);
else
led_toggle(LED_RED);
}
}
unsigned long adc_sum[8];
unsigned int adc_noise[8];
unsigned char adc_n[8];
@ -181,6 +201,7 @@ int main()
spi_slave_Rx(cmd, 3);
resp[0] = cmd[0];
sreg = disable_irq();
led_hv();
if (conf.wdt_mode == WDT_MODE_LIVE)
wdt_kick();
switch (cmd[0]) {
@ -214,7 +235,7 @@ int main()
if (conf.flags2 & FLAG2_PC_HV)
PORTC = conf.portc_on;
if (conf.flags2 & FLAG2_HVOSC)
hvosc_init(conf.hvosc_freq);
hvosc_init(conf.hvosc_freq, conf.hvosc_dc);
int2frame(conf.dac, resp+1);
if (conf.wdt_mode >= WDT_MODE_HV)
wdt_kick();
@ -223,10 +244,14 @@ int main()
dac_ramp(conf.dac_nominal);
continue;
case 'Q':
conf.hvosc_freq = frame2int(cmd+1);
case 'q':
int2frame(conf.hvosc_freq, resp+1);
hvosc_init(conf.hvosc_freq);
resp[1] = conf.hvosc_freq;
resp[2] = conf.hvosc_dc;
if (upcase(cmd[0])) {
conf.hvosc_freq = cmd[1];
conf.hvosc_dc = cmd[2];
}
hvosc_init(conf.hvosc_freq, conf.hvosc_dc);
break;
case 'I':
int2frame(tick_freq(), resp+1);
@ -241,20 +266,17 @@ int main()
ads8688_cmd(cmd+1, resp+1);
break;
case 'T':
resp[1] = adc_status;
resp[2] = adc_error;
enable_irq(sreg);
spi_slave_Tx(resp, 3);
if (cmd[1])
adc_read(cmd[1], cmd[2]);
continue;
case 't':
resp[1] = adc_status;
resp[2] = adc_error;
enable_irq(sreg);
spi_slave_Tx(resp, 3);
if (cmd[1])
if (cmd[1]) {
if (upcase(cmd[0]))
adc_read(cmd[1], cmd[2]);
else
adc_dac = dacadc_read();
}
continue;
case 'R':
c = cmd[1] & 7;
@ -318,8 +340,12 @@ int main()
resp[2] = conf.padding[0];
break;
}
if (cmd[2]==1)
if (cmd[2]==1) {
enable_irq(sreg);
spi_slave_Tx(resp, 3);
conf_init();
continue;
}
break;
case 'B':
c = cmd[1] & 0x7f;
@ -349,7 +375,9 @@ int main()
PORTC = conf.portc = cmd[2];
break;
case 'O':
case 'o':
resp[2] = DDRC;
if (upcase(cmd[1]))
DDRC = conf.ddrc = cmd[2];
break;
case 'A':
@ -374,9 +402,12 @@ int main()
break;
}
break;
case 'Y':
case 'Y': // peek
case 'y': // poke
resp[1] = cmd[1];
resp[2] = *(unsigned char *)(cmd[1]+0);
if (!upcase(cmd[0]))
*(unsigned char *)(cmd[1]+0) = cmd[2];
break;
}
enable_irq(sreg);
@ -497,7 +528,7 @@ ISR(WDT_vect)
if (conf.flags2 & FLAG2_PC_HV)
PORTC = conf.portc_off;
if (conf.flags2 & FLAG2_HVOSC)
hvosc_init(0);
hvosc_init(0, 0);
}
tick_init(conf.tick_period);
if (conf.wdt_save_addr && !wdt_saved) {

33
chaos/hvled.h Normal file
View file

@ -0,0 +1,33 @@
#include "avr/io.h"
#define LED1 2
#define LED2 3
#define LED_PORT PORTC
#define LED_GREEN (1<<LED1)
#define LED_RED (1<<LED2)
#define LED_MASK (LED_GREEN | LED_RED)
static inline void led_init()
{
DDRC |= LED_MASK;
}
static uint8_t led_status()
{
return LED_PORT & LED_MASK;
}
static inline void led_off()
{
LED_PORT &=~ LED_MASK;
}
static inline void led_on(uint8_t color)
{
LED_PORT &= ~(LED_MASK & ~color);
LED_PORT |= color;
}
static inline void led_toggle(uint8_t color)
{
if (led_status() == color)
LED_PORT &=~ color;
else
led_on(color);
}

View file

@ -1,19 +1,20 @@
#include "avr/io.h"
static inline void hvosc_init(unsigned char freq)
static inline void hvosc_init(unsigned char freq, unsigned char dc)
{
if (!freq) {
if (!dc || freq <= dc) {
TCCR1A = 0;
return;
}
PRR &=~ (1<<PRTIM1);
__asm__("NOP");
DDRC |= (1<<PC1);
DDRD |= (1<<PD2);
TCCR1A = (2<<COM1A0) | (3<<COM1B0) | (2<<WGM10);
TCCR1B = (1<<CS10) | (3<<WGM12);
TCCR1B = (1<<CS10) | (2<<WGM12);
ICR1H = 0;
ICR1L = freq;
OCR1AH = 0;
OCR1AL = freq>>1;
OCR1AL = dc;
OCR1BH = 0;
OCR1BL = freq>>1;
OCR1BL = freq-dc;
}

View file

@ -2,8 +2,8 @@
#define DAC_SDI 4
#define DAC_SCK 5
#define DAC_CE 6
#define DAC_PO PORTD
#define PORTD_IO 0x0b
#define DAC_PORT PORTD
#define DAC_PORT_IO _SFR_IO_ADDR(DAC_PORT)
static inline void ltc1655_init()
{
@ -24,7 +24,7 @@ static inline void ltc1655_bit(unsigned char c, unsigned char i)
"nop" "\n\t"
"sbi %[p], %[k]" "\n"
::
[p] "n" (PORTD_IO),
[p] "n" (DAC_PORT_IO),
[d] "n" (DAC_SDI),
[k] "n" (DAC_SCK),
[c] "r" (c),
@ -33,8 +33,8 @@ static inline void ltc1655_bit(unsigned char c, unsigned char i)
static inline void ltc1655_frame(const unsigned char *c)
{
DAC_PO &=~ (1<<DAC_SCK);
DAC_PO &=~ (1<<DAC_CE);
DAC_PORT &=~ (1<<DAC_SCK);
DAC_PORT &=~ (1<<DAC_CE);
ltc1655_bit(c[1],7);
ltc1655_bit(c[1],6);
ltc1655_bit(c[1],5);
@ -58,6 +58,6 @@ static inline void ltc1655_frame(const unsigned char *c)
"nop" "\n\t"
"nop" "\n"
);
DAC_PO &=~ (1<<DAC_SCK);
DAC_PO |= (1<<DAC_CE);
DAC_PORT &=~ (1<<DAC_SCK);
DAC_PORT |= (1<<DAC_CE);
}