|
在這里發(fā)一個(gè)基于AVR單片機(jī)的混合信號(hào)示波器,有興趣的朋友可以DIY一個(gè)來(lái)玩玩
關(guān)鍵元件
MCU:ATXMEGA32A
顯示:0.96 OLE,128 x64像素
規(guī)格:
2路模擬輸入
最大采樣率2MSPS
模擬帶寬200Khz
綬沖區(qū)256字節(jié)
輸入電壓范圍-14V到+20V
pc程序界面:
0.png (20.97 KB, 下載次數(shù): 79)
下載附件
2018-5-19 16:41 上傳
電路原理圖如下:
0.png (169.79 KB, 下載次數(shù): 67)
下載附件
2018-5-19 16:40 上傳
1.jpg (158.72 KB, 下載次數(shù): 75)
下載附件
2018-5-19 16:40 上傳
2.jpg (109.29 KB, 下載次數(shù): 64)
下載附件
2018-5-19 16:40 上傳
3.jpg (106.2 KB, 下載次數(shù): 71)
下載附件
2018-5-19 16:40 上傳
4.jpg (102.98 KB, 下載次數(shù): 66)
下載附件
2018-5-19 16:40 上傳
單片機(jī)源程序如下:
- /*****************************************************************************
- Xprotolab - AVR XMEGA Oscilloscope and Development Kit
- Gabotronics C.A.
- March 2011
- ATXMEGA32A4
- Compiled with GCC, -Os optimizations
- email me at: gabriel@gabotronics.com
- *****************************************************************************/
- #include <avr/io.h>
- #include <util/delay.h>
- #include <avr/pgmspace.h>
- #include <avr/interrupt.h>
- #include <avr/sleep.h>
- #include <avr/wdt.h>
- #include <stddef.h>
- #include "main.h"
- #include "mso.h"
- #include "logic.h"
- #include "awg.h"
- uint8_t SP_ReadCalibrationByte(uint8_t location);
- void Restore(void);
- uint16_t readVCC(void);
- uint8_t AWGBuffer[256]; // AWG Output Buffer
- // Big temp buffer to store tempFFT, tempAWG and temp ch data
- // Last 256 bytes hold CHD.data
- uint8_t bigtemp[1280];
- // EEProm variables
- uint8_t EEMEM EESleepTime = 64; // Sleep timeout in minutes
- uint8_t EEMEM EEDACgain = 0; // DAC gain calibration
- uint8_t EEMEM EEDACoffset = 0; // DAC offset calibration
- static void Calibrate(void);
- static void SimpleADC(void);
- void ScreenSaver(uint8_t minutes);
- static void CalibrateDAC(void);
- int main(void) {
- uint8_t i,j,rx=0;
- // Power reduction: Stop unused peripherals
- PR.PRGEN = 0x18; // Stop: AES, EBI
- PR.PRPA = 0x04; // Stop: DAC
- PR.PRPB = 0x03; // Stop: ADC, AC
- PR.PRPC = 0x7C; // Stop: TWI, USART0, USART1, SPI, HIRES
- PR.PRPD = 0x7C; // Stop: TWI, USART0, USART1, SPI, HIRES
- PR.PRPE = 0x6C; // Stop: TWI, USART1, SPI, HIRES
- // PORTS CONFIGURATION
- // Initial value PORTA.DIR = 0x00; // CH2, CH1, 1V, K1, K2, K3, K4, REF
- PORTA.PIN4CTRL = 0x18; // Pull up on pin PA4
- PORTA.PIN3CTRL = 0x18; // Pull up on pin PA3
- PORTA.PIN2CTRL = 0x18; // Pull up on pin PA2
- PORTA.PIN1CTRL = 0x18; // Pull up on pin PA1
- PORTA.INTCTRL = 0x02; // PORTA will generate medium level interrupts
- PORTA.INT0MASK = 0x1E; // PA4, PA3, PA2, PA1 will be the interrupt 0 sources
- PORTB.DIR = 0x0B; // RES, AWG, D/C, R/W
- // Initial Value PORTB.OUT = 0x00; //
- // Initial Value PORTC.DIR = 0x00; // LOGIC
- PORTC.INT0MASK = 0x01; // PC0 (SDA) will be the interrupt 0 source
- PORTC.INT1MASK = 0x80; // PC7 (SCK) will be the interrupt 1 source
- PORTD.DIR = 0xFF; // LCD Data bus
- // Initial Value PORTD.OUT = 0x00;
- PORTE.DIR = 0x09; // TX, RX, EXT, E
- // Initial Value PORTE.OUT = 0x00; //
- PORTCFG.VPCTRLA = 0x41; // VP1 Map to PORTE, VP0 Map to PORTB
- PORTCFG.VPCTRLB = 0x32; // VP3 Map to PORTD, VP2 Map to PORTC
- key = 0;
- // Clock Settings
- i=1;
- OSC.XOSCCTRL = 0xCB; // 0.4-16 MHz XTAL - 16K CLK Start Up
- OSC.CTRL = 0x08; // Enable External Oscillator
- while(i && !testbit(OSC.STATUS,OSC_XOSCRDY_bp)) { // wait until crystal stable
- i++;
- _delay_us(100);
- }
- OSC.PLLCTRL = 0xC2; // XOSC is PLL Source - 2x Factor (32MHz)
- OSC.CTRL = 0x19; // Enable PLL & External Oscillator
- while(i && !testbit(OSC.STATUS,OSC_PLLRDY_bp)) { // wait until PLL stable
- i++;
- _delay_us(100);
- }
- // Swith to internal 32MHz if crystal fails
- if(i==0) { // Timed out, use internal oscillator
- OSC.XOSCCTRL = 0x00; // Disable external oscillators
- OSC.CTRL = 0x03; // Enable internal 32MHz
- while(!testbit(OSC.STATUS,OSC_RC32MRDY_bp)); // wait until 32MHz stable
- CCPWrite(&CLK.CTRL, CLK_SCLKSEL_RC32M_gc); // Use internal 32MHz
- OSC.CTRL = 0x02; // Disable internal 2MHz
- }
- else { // Crystal OK!
- CCPWrite(&CLK.CTRL, CLK_SCLKSEL_PLL_gc); // Switch to PLL clock
- OSC.CTRL = 0x18; // Disable internal 2MHz
- }
- // Initialize USART
- USARTE0.BAUDCTRLA = 0x17; // BSCALE = -6, BSEL = 1047
- USARTE0.BAUDCTRLB = 0xA4; // ==> 115211 bps (~115.2kbps)
- USARTE0.CTRLC = 0x03; // Async, No Parity, 1 stop bit, 8 data bits
- USARTE0.CTRLB = 0x18; // Enable RX and TX
- // Event System for ADC
- EVSYS.CH0MUX = 0xE0; // Event CH0 = TCE0 overflow used for ADC
- // ADC
- ADCA.CALL = SP_ReadCalibrationByte(offsetof(NVM_PROD_SIGNATURES_t, ADCACAL0) );
- ADCA.CALH = SP_ReadCalibrationByte(offsetof(NVM_PROD_SIGNATURES_t, ADCACAL1) );
- ADCA.PRESCALER = 0x06; // Prescaler
- ADCA.CTRLB = 0x18; // signed mode, free run, 12 bit
- ADCA.REFCTRL = 0x20; // REF= AREF (2V)
- ADCA.EVCTRL = 0x45; // Sweep channels 0,1
- ADCA.CH0.MUXCTRL = 0x2A; // Channel 0 input: ADC5 pin - ADC6 pin
- ADCA.CH0.CTRL = 0x03; // Differential input with gain
- ADCA.CH1.MUXCTRL = 0x2B; // Channel 1 input: ADC5 pin - ADC7 pin
- ADCA.CH1.CTRL = 0x03; // Differential input with gain
- ADCA.CH2.MUXCTRL = 0x02; // Channel 2 input: VCC/10
- ADCA.CTRLA = 0x01; // Enable ADC
- // Initial Value ADCA.CH2.CTRL = 0x00; // Internal input
- // Initial Value ADCA.CH3.MUXCTRL = 0x00; // Channel 3 input: temperature
- // Initial Value ADCA.CH3.CTRL = 0x00; // Internal input
- ADCA.CH1.INTCTRL = 0x03; // ADC is high level interrupt
- // Event system for DAC
- EVSYS.CH3MUX = 0xD0; // Event CH3 = TCD0 overflow used for DAC
- // Timer TCD0: 1MHz timer for DACA
- TCD0.CTRLA = 0x01; // Prescaler: clk/1
- TCD0.PER = 31; // 1MHz
- // DAC
- DACB.CTRLB = 0x01; // CH0 auto triggered by an event
- DACB.CTRLC = 0x11; // Use AREFA (2.0V), data is left adjusted
- DACB.EVCTRL = 0x03; // Event CH3 triggers the DAC Conversion
- DACB.TIMCTRL = 0x50; // Minimum 32 CLK between conversion (1uS)
- DACB.GAINCAL = eeprom_read_byte(&EEDACgain); // Load DACA gain calibration
- DACB.OFFSETCAL = eeprom_read_byte(&EEDACoffset); // Load DACA offset calibration
- DACB.CTRLA = 0x05; // Enable DACB and CH0
- InitDMA();
- // Arbitrary Waveform Generator
- LoadAWGvars(); // Load AWG settings
- BuildWave(); // Construct AWG waveform
- // Interrupt Configuration
- PMIC.CTRL = 0x07; // Enable High, Medium and Low level interrupts
- sei(); // Enable global interrupts
- // Initialize LCD
- GLCD_LcdInit();
- if(testbit(display, flip)) {
- LcdInstructionWrite(LCD_SET_SCAN_NOR); // direction
- LcdInstructionWrite(LCD_SET_SEG_REMAP1);
- }
- GLCD_DisplayPicture(LOGO);
- // tiny_printp(45,3,PSTR("XPROTOLAB"));
- tiny_printp(50/*39*/,7,VERSION);
- if(CLK.CTRL & CLK_SCLKSEL_RC32M_gc) lcd_putsp(PSTR(" XT FAIL"));
- show_display();
- for(i=0; i<100; i++) {
- if(testbit(USARTE0.STATUS,USART_RXCIF_bp)) {
- j=USARTE0.DATA; // dummy read
- rx++;
- }
- _delay_ms(30);
- }
- // Check if received data that should not have been received
- if(rx<=4) USARTE0.CTRLB = 0x18; // Enable RX and TX
- else {
- // Device is connected to a regular USB port on a PC, disable the USART
- USARTE0.CTRLB = 0x00; // Disable RX, TX
- PR.PRPE = 0x7C; // Stop: TWI, USART0, USART1, SPI, HIRES
- PORTE.DIR = 0x01; // TX as input
- }
- // TCD1 controls LCD refresh rate
- TCD1.CTRLA = 6; // Prescaler: clk/256
- TCD1.PER = 15624; // Maximum LCD refresh rate is 8Hz
- // TCC1 controls the auto trigger and auto key repeat
- TCC1.CTRLA = 7; // Prescaler: clk/256
- TCC1.PER = 31999; // Period is 1.024 seconds
- TCC1.INTCTRLA = 0x01; // Generate low level interrupt
- // RTC Clock Settings
- /* Set 1.024kHz from internal 32.768kHz RC oscillator */
- CLK.RTCCTRL = CLK_RTCSRC_RCOSC_gc | CLK_RTCEN_bm;
- i=eeprom_read_byte(&EESleepTime);
- ScreenSaver(i);
- if( testbit(PORTA.IN,1)) MSO(); // KD not pressed -> got to MSO
- setbit(Signals, redraw);
- key=0;
- for(;;) {
- while(!testbit(TCD1.INTFLAGS, TC1_OVFIF_bp)) { // wait for refresh timeout
- if(testbit(Signals, userinput))
- break; // cancel if user input
- }
- setbit(TCD1.INTFLAGS, TC1_OVFIF_bp);
- clr_display();
- lcd_goto(0,0); printhex(VPORT2.IN);
- tiny_printp(0,4,PSTR("XMEGA rev")); GLCD_Putchar('A'+MCU.REVID);
- //tiny_printp(32,5,PSTR("VIN"));
- tiny_printp(0,7,PSTR("OFFSET"));
- tiny_printp(98,7,PSTR("RESTORE"));
- tiny_printp(54,6,PSTR("SLEEP:"));
- lcd_goto(58,7);
- if(i) printN(i);
- else lcd_putsp(PSTR("OFF"));
- if(testbit(Signals, userinput)) {
- clrbit(Signals, userinput);
- switch(key) {
- case KA: Calibrate(); break;
- case KB: i+=16;
- ScreenSaver(i);
- break;
- case KC: Restore(); break;
- case KD: key=0; eeprom_write_byte(&EESleepTime, i);
- MSO();
- }
- }
- //lcd_goto(20,5); printN(readVCC());
- show_display();
- }
- return 0;
- }
- // Return sine fractional value
- int8_t Sin(uint8_t angle) {
- if(angle>=128) return - pgm_read_byte(&sint[angle-128]);
- return pgm_read_byte(&sint[angle]);
- }
- // Add unsigned with signed using saturation, return unsigned
- uint8_t addwsat(uint8_t a, int8_t b) {
- if(b>=0) {
- if(a>255-b) return 255;
- }
- else {
- if(a<(-b)) return 0;
- }
- return a+b;
- }
- // ADC conversion complete, for sampling rates >= 1mS/div (srate>=9)
- ISR(ADCA_CH1_vect) {
- static uint8_t i=0,n=0;
- static int16_t sum1=0,sum2=0;
- static int16_t *p1=bigtemp, *p2=bigtemp+512;
- int16_t d1,d2;
- d1=ADCA.CH0.RES; sum1 += d1;
- d2=ADCA.CH1.RES; sum2 += d2;
- n++;
- if(n==2 && srate==7) {
- if(CH1.ctrl.average) *p1++ = sum1>>1;
- else *p1++ = d1;
- if(CH2.ctrl.average) *p2++ = sum2>>1;
- else *p2++ = d2;
- }
- else if(n==4 && srate==8) {
- if(CH1.ctrl.average) *p1++ = sum1>>2;
- else *p1++ = d1;
- if(CH2.ctrl.average) *p2++ = sum2>>2;
- else *p2++ = d2;
- }
- else if(n==8) {
- if(CH1.ctrl.average) *p1++ = sum1>>3;
- else *p1++ = d1;
- if(CH2.ctrl.average) *p2++ = sum2>>3;
- else *p2++ = d2;
- }
- else return;
- CHD.data[i] = VPORT2.IN;
- i++;
- n=0;
- sum1=0; sum2=0;
- if(i==0) {
- setbit(MStatus,acquired); // Acquired all samples
- ADCA.CH1.INTCTRL = 0x00; // disable interrupt
- p1=bigtemp;
- p2=bigtemp+512;
- }
- }
- // Tactile Switches - This is configured as a low level interrupt
- ISR(PORTA_INT0_vect) {
- uint8_t i,in,j=0;
- // Debounce: need to read 10 consecutive equal numbers
- for(i=10; i>0; i--) {
- _delay_ms(1);
- in = PORTA.IN & 0x1E; // Read port
- if(j!=in) { j=in; i++; }
- }
- key=0;
- if(!testbit(in,1)) {
- key = KD; // Menu key
- }
- if(testbit(display, flip)) {
- if(!testbit(in,4)) key |= KC;
- if(!testbit(in,3)) key |= KB;
- if(!testbit(in,2)) key |= KA;
- }
- else {
- if(!testbit(in,4)) key |= KA;
- if(!testbit(in,3)) key |= KB;
- if(!testbit(in,2)) key |= KC;
- }
- if(key) {
- setbit(Signals, update); // Valid key
- setbit(Signals, userinput);
- }
- else keyrep=0;
- RTC.CNT=0; // Clear screen saver timer
- // TCC1 used for auto repeat key
- TCC1.CNT = 0; // Clear TCC1
- setbit(TCC1.INTFLAGS, TC1_OVFIF_bp); // Clear timeout interrupt
- }
- // From Application Note AVR1003
- void CCPWrite( volatile uint8_t * address, uint8_t value ) {
- uint8_t volatile saved_sreg = SREG;
- cli();
- #ifdef __ICCAVR__
- asm("movw r30, r16");
- #ifdef RAMPZ
- RAMPZ = 0;
- #endif
- asm("ldi r16, 0xD8 \n"
- "out 0x34, r16 \n"
- #if (__MEMORY_MODEL__ == 1)
- "st Z, r17 \n");
- #elif (__MEMORY_MODEL__ == 2)
- "st Z, r18 \n");
- #else /* (__MEMORY_MODEL__ == 3) || (__MEMORY_MODEL__ == 5) */
- "st Z, r19 \n");
- #endif /* __MEMORY_MODEL__ */
- #elif defined __GNUC__
- volatile uint8_t * tmpAddr = address;
- #ifdef RAMPZ
- RAMPZ = 0;
- #endif
- asm volatile(
- "movw r30, %0" "\n\t"
- "ldi r16, %2" "\n\t"
- "out %3, r16" "\n\t"
- "st Z, %1" "\n\t"
- :
- : "r" (tmpAddr), "r" (value), "M" (CCP_IOREG_gc), "i" (&CCP)
- : "r16", "r30", "r31"
- );
- #endif
- SREG = saved_sreg;
- }
- /*! \brief Function for GCC to read out calibration byte.
- *
- * \note For IAR support, include the adc_driver_asm.S90 file in your project.
- *
- * \param index The index to the calibration byte.
- *
- * \return Calibration byte.
- */
- uint8_t SP_ReadCalibrationByte( uint8_t location )
- {
- uint8_t result;
- /* Load the NVM Command register to read the calibration row. */
- NVM_CMD = NVM_CMD_READ_CALIB_ROW_gc;
- result = pgm_read_byte(location);
- /* Clean up NVM Command register. */
- NVM_CMD = NVM_CMD_NO_OPERATION_gc;
- return result;
- }
- // Calibrate offset, inputs must be connected to ground
- static void Calibrate(void) {
- uint8_t i,j;
- uint16_t average;
- key=0;
- clr_display();
- tiny_printp(48,0,PSTR("Connnect CH1, CH2"));
- tiny_printp(48,1,PSTR("to ground"));
- tiny_printp(108,7,PSTR("START"));
- /* // Show current calibration
- for(i=0; i<8; i++) {
- lcd_goto(0,i);
- printN((int8_t)eeprom_read_byte(&offsetsCH1[i])+128);
- printN((int8_t)eeprom_read_byte(&offsetsCH2[i])+128);
- }*/
- show_display();
- while(!key);
- if(key!=KC) {
- key=0;
- return;
- }
- key=0;
- clr_display();
- tiny_printp(84,0,PSTR("Calibrating"));
- // Cycle thru all the 8 gains
- for(i=0; i<8; i++) {
- lcd_goto(0,i);
- ADCA.CH0.CTRL = 0x03 | (i<<2); // Set gain
- ADCA.CH1.CTRL = 0x03 | (i<<2); // Set gain
- _delay_ms(50);
- SimpleADC();
- // Calculate offset for CH1
- average=0;
- j=0;
- do {
- average+= CH1.data[i];
- } while(++j);
- j = (uint8_t )(average>>8);
- if(j>=128) CH1.offset=-(j-128);
- else CH1.offset = (128-j);
- eeprom_write_byte(&offsetsCH1[i], CH1.offset);
- printN(CH1.offset+128);
- // Calculate offset for CH2
- average=0;
- j=0;
- do {
- average+= CH2.data[i];
- } while(++j);
- j = (uint8_t )(average>>8);
- if(j>=128) CH2.offset=-(j-128);
- else CH2.offset = (128-j);
- eeprom_write_byte(&offsetsCH2[i], CH2.offset);
- printN(CH2.offset+128);
- show_display();
- }
- _delay_ms(2000);
- }
- // Fill up channel data buffers
- void SimpleADC(void) {
- uint8_t *p1, *p2; // temp pointers to unsigned 8 bits
- int16_t *q1, *q2; // temp pointers to signed 16 bits
- uint8_t j;
- uint16_t data;
- // Acquire using DMA
- setbit(DMA.CH0.CTRLA, 7);
- setbit(DMA.CH1.CTRLA, 7);
- while(testbit(DMA.CH1.CTRLA,7)) ;
- // Convert 12bit result to 8bit
- p1=CH1.data; p2=CH2.data;
- q1=bigtemp; q2=bigtemp+512;
- j=0; do {
- data=*q1+2048; // convert to unsigned
- *p1 = (uint8_t)((data)>>4);
- data=*q2+2048; // convert to unsigned
- *p2 = (uint8_t)((data)>>4);
- p1++; p2++;
- q1++; q2++;
- } while (++j);
- }
- // Recieves a nibble, returns the corresponding ascii that represents the HEX value
- char NibbleToChar(uint8_t nibble) {
- if(nibble<10) return '0'+nibble; // '0' thru '9'
- return '7'+nibble; // 'A' thru 'F'
- }
- // Prints a HEX number
- void printhex(uint8_t n) {
- uint8_t temp;
- temp = n>>4;
- GLCD_Putchar(NibbleToChar(temp));
- temp = n&0x0F;
- GLCD_Putchar(NibbleToChar(temp));
- }
- // Converts an uint to int, then calculates the half
- uint8_t half(uint8_t number) {
- int8_t temp;
- temp=(int8_t)(number-128);
- temp=temp/2;
- return (uint8_t)(temp+128);
- }
- /*
- // Calibrate DAC gain and offset, connect AWG to CH1
- // Adjust with rotary encoders
- static void CalibrateDAC(void) {
- uint8_t i, step=0, data, average;
- uint8_t test, bestoffset, bestgain, bestmeasure1;
- uint16_t sum, bestmeasure2;
- clr_display();
- ADCA.CH0.CTRL = 0x03 | (6<<2); // Set gain 6
- CH1.offset=(signed char)eeprom_read_byte(&offsetsCH1[6]);
- AWGAmp=127; // Amplitude range: [0,127]
- AWGtype=1; // Waveform type
- AWGduty=256; // Duty cycle range: [0,512]
- AWGOffset=0; // 0V offset
- desiredF = 100000; // 1kHz
- BuildWave();
- while(step<7) {
- while(!testbit(TCD1.INTFLAGS, TC1_OVFIF_bp)); // wait for refresh timeout
- setbit(TCD1.INTFLAGS, TC1_OVFIF_bp);
- // Acquire data
- // Display waveform
- i=0; sum=0;
- do {
- data=addwsat(CH1.data[i],CH1.offset);
- sum+=data;
- set_pixel(i>>1, data>>2); // CH1
- } while(++i);
- average=(uint8_t)(sum>>8);
- switch(step) {
- case 0: // Connect AWG to CH1
- tiny_printp(0,0,PSTR("AWG Calibration Connect AWG CH1 Press 5 to start"));
- step++;
- break;
- case 1:
- if(key) {
- if(key==KC) step++;
- else step=7; // Did not press 5 -> exit
- }
- break;
- case 2: // Output 0V from AWG
- AWGAmp=1; // Amplitude range: [0,127]
- AWGtype=1; // Waveform type
- BuildWave();
- tiny_printp(0,3,PSTR("Adjusting offset"));
- // ADS931 power, output enable, CH gains
- // PORTE.OUT = 0;
- CH1.offset=(signed char)eeprom_read_byte(&offsetsCH1[0]);
- step++;
- bestoffset = 0;
- test = 0;
- bestmeasure1=0;
- DACB.OFFSETCAL = 0;
- break;
- case 3: // Adjust Offset
- if(abs((int16_t)average-128)<abs((int16_t)bestmeasure1-128)) { // Current value is better
- bestoffset = test;
- bestmeasure1=average;
- lcd_goto(0,4);
- if(bestoffset>=0x40) printN(0x40-bestoffset);
- else printN(bestoffset);
- }
- lcd_line(0,bestmeasure1>>1,127,bestmeasure1>>1);
- test++;
- DACB.OFFSETCAL = test;
- if(test>=128) {
- step++;
- DACB.OFFSETCAL = bestoffset; // Load DACA offset calibration
- }
- break;
- case 4: // Output -1.75V from AWG
- AWGAmp=0; // Full Amplitude
- AWGtype=1; // Waveform type
- AWGOffset=112; // Offset = -1.75
- BuildWave();
- tiny_printp(0,5,PSTR("Adjusting gain"));
- // PORTE.OUT = 4; // 0.5V / div
- CH1.offset=(signed char)eeprom_read_byte(&offsetsCH1[4]);
- step++;
- bestgain = 0;
- test=0;
- bestmeasure2=0;
- DACB.GAINCAL = 0;
- break;
- case 5: // Adjust gain
- // (1.75/0.5)*32+128)*256 = 61440
- if(abs((int32_t)sum-61696)<abs((int32_t)bestmeasure2-61696)) { // Current value is better
- bestgain = test;
- bestmeasure2=sum;
- lcd_goto(0,6);
- if(bestgain>=0x40) printN(0x40-bestgain);
- else printN(bestgain);
- }
- test++;
- DACB.GAINCAL = test;
- if(test>=128) {
- step++;
- DACB.GAINCAL = bestgain;
- }
- break;
- case 6: // Calibration complete
- // Save calibration results
- AWGAmp=0;
- eeprom_write_byte(&EEDACoffset, bestoffset); // Save offset calibration
- eeprom_write_byte(&EEDACgain, bestgain); // Save gain calibration
- tiny_printp(0,15,PSTR("Cal complete"));
- step++;
- break;
- }
- }
- // Restore Waveform
- LoadAWGvars(); // Load AWG settings
- BuildWave(); // Construct AWG waveform
- }*/
- void Restore(void) {
- key=0;
- clr_display();
- tiny_printp(0,0,PSTR("PRESS K1 TO RESTORE DEFAULTS"));
- show_display();
- while(!key);
- if(key!=KA) {
- key=0;
- return;
- }
- key=0;
- srate = 6; // Sampling rate, start with 512uS/s
- tdelay = 0; // Trigger delay
- tlevel = 128; // Trigger level
- tpre = 128; // Number of Pre Trigger samples
- tsource = 1; // Trigger source, start with CH1
- CH2.option = 0x01; // CH2 on, 5V/div
- CH2.gain = 1; // CH2 gain
- CH2.position = -32; // CH2 vertical position
- CH1.option = 0x01; // CH1 on, 5V/div
- CH1.gain = 1; // CH1 gain
- CH1.position = -96; // CH1 vertical position
- CHD.option = 0x04; // CHD off, thick line when low
- CHD.param = 0x00; // Decode parameters
- CHD.decode = 0x00; // Decode
- CHD.mask = 0xFF; // Mask logic inputs
- CHD.position = 0; // CHD vertical position
- Mcursor = 0x00; // Cursors off
- MStatus = 0x01; // Set free trigger
- Mset = 0x1C; // Set scope mode, show settings, line
- MFFT = 0x21; // Use hamming window, no logarithm
- display = 0x01; // Standard grid
- SaveEE();
- AWG.type = 1; // Type
- AWG.amp = -64; // Amplitude
- AWG.offset = 0; // Offset
- AWG.duty = 256; // Duty cycle high byte
- AWG.desiredF = 100000; // desired F x 100
- SaveAWGvars();
- tiny_printp(0,2,OKtext);
- show_display();
- _delay_ms(1000);
- }
- // Configures the Screen Saver time out
- void ScreenSaver(uint8_t minutes) {
- RTC.PER = (uint16_t)(minutes)*60;
- RTC.CNT = 0;
- if(minutes) {
- RTC.INTCTRL = 0x01; // Generate low level interrupt
- RTC.CTRL = 0x07; // Divisor 1024 (1 second per count)
- }
- else {
- RTC.INTCTRL = 0;
- RTC.CTRL = 0;
- }
- }
- // RTC clock, this function is called when the sleep timeout has been reached
- ISR(RTC_OVF_vect) {
- GLCD_LcdOff();
- SaveEE(); // Save MSO settings
- SaveAWGvars(); // Save AWG settings
- SLEEP.CTRL = SLEEP_SMODE_PDOWN_gc | SLEEP_SEN_bm;
- ……………………
- …………限于本文篇幅 余下代碼請(qǐng)從51黑下載附件…………
復(fù)制代碼
0.png (45.04 KB, 下載次數(shù): 71)
下載附件
2018-5-19 16:41 上傳
所有資料51hei提供下載:
原理圖.rar
(193.79 KB, 下載次數(shù): 18)
2018-5-19 09:23 上傳
點(diǎn)擊文件名下載附件
原理圖 下載積分: 黑幣 -5
圖片.rar
(474.94 KB, 下載次數(shù): 12)
2018-5-19 09:23 上傳
點(diǎn)擊文件名下載附件
圖片 下載積分: 黑幣 -5
驅(qū)動(dòng)及源碼.rar
(905.83 KB, 下載次數(shù): 14)
2018-5-19 09:23 上傳
點(diǎn)擊文件名下載附件
驅(qū)動(dòng)及源碼 下載積分: 黑幣 -5
|
評(píng)分
-
查看全部評(píng)分
|