diff --git a/.gitignore b/.gitignore index 572b022..2806ac8 100644 --- a/.gitignore +++ b/.gitignore @@ -19,3 +19,6 @@ /sw/InductorTester/obj/Debug /sw/InductorTester/*.suo /fw/f4discovery/bin/*.map +/sw/InductorTester/bin +/sw/InductorTester/TestResults +/sw/InductorTester/obj diff --git a/fw/f4discovery/Makefile b/fw/f4discovery/Makefile index 8065c2e..2e97643 100644 --- a/fw/f4discovery/Makefile +++ b/fw/f4discovery/Makefile @@ -105,12 +105,12 @@ clean: %.flash: %.elf @$(PRINTF) " GDB $< (flash)\n" - $(Q)$(GDB) --batch -ex 'target extended-remote COM3' \ + $(Q)$(GDB) --batch -ex 'target extended-remote COM4' \ -x $(OPENCM3_DIR)scripts/black_magic_probe_flash.scr $< %.gdb: %.elf @$(PRINTF) " GDB $< (gdb)\n" - $(Q)$(GDB) -ex 'target extended-remote COM3' \ + $(Q)$(GDB) -ex 'target extended-remote COM4' \ -x $(OPENCM3_DIR)scripts/black_magic_probe_flash.scr $< ############################################################################### diff --git a/fw/f4discovery/include/dac.h b/fw/f4discovery/include/dac.h new file mode 100644 index 0000000..a93cca2 --- /dev/null +++ b/fw/f4discovery/include/dac.h @@ -0,0 +1,8 @@ +#ifndef DAC_H_INCLUDED +#define DAC_H_INCLUDED +#include +#include +#include +void dac_init(void); +void set_napeti(uint16_t napeti); +#endif // DAC_H_INCLUDED diff --git a/fw/f4discovery/include/protokol.h b/fw/f4discovery/include/protokol.h new file mode 100644 index 0000000..03b79dd --- /dev/null +++ b/fw/f4discovery/include/protokol.h @@ -0,0 +1,24 @@ +#ifndef PROTOKOL_H_INCLUDED +#define PROTOKOL_H_INCLUDED + + +#include +#include + +#include "pwm.h" +#include "dac.h" + +struct Param_Mer +{ + uint8_t set_param; + uint8_t start_mer; + uint16_t Napeti; + uint16_t Cas_Nas; + uint32_t default_pwm[4]; +}; + +void protokol(char *buf); +void set_mer(void); +void init_protokol(void); + +#endif // PROTOKOL_H_INCLUDED diff --git a/fw/f4discovery/include/usb_vilem.h b/fw/f4discovery/include/usb_vilem.h new file mode 100644 index 0000000..ccbed3e --- /dev/null +++ b/fw/f4discovery/include/usb_vilem.h @@ -0,0 +1,207 @@ +#ifndef usb_vilem_154763 +#define usb_vilem_154763 + +#include + +#include + +#include + +#include + +#include + +#include + +static const struct usb_device_descriptor dev = { + .bLength = USB_DT_DEVICE_SIZE, + .bDescriptorType = USB_DT_DEVICE, + .bcdUSB = 0x0200, + .bDeviceClass = USB_CLASS_CDC, + .bDeviceSubClass = 0, + .bDeviceProtocol = 0, + .bMaxPacketSize0 = 64, + .idVendor = 0x0483, + .idProduct = 0x5740, + .bcdDevice = 0x0200, + .iManufacturer = 1, + .iProduct = 2, + .iSerialNumber = 3, + .bNumConfigurations = 1, + +}; + + + + +// * This notification endpoint isn't implemented. According to CDC spec it's +// * optional, but its absence causes a NULL pointer dereference in the +// * Linux cdc_acm driver. +// + +static const struct usb_endpoint_descriptor comm_endp[] = {{ + .bLength = USB_DT_ENDPOINT_SIZE, + .bDescriptorType = USB_DT_ENDPOINT, + .bEndpointAddress = 0x83, + .bmAttributes = USB_ENDPOINT_ATTR_INTERRUPT, + .wMaxPacketSize = 16, + .bInterval = 255, +}}; + + +static const struct usb_endpoint_descriptor data_endp[] = +{ + { + .bLength = USB_DT_ENDPOINT_SIZE, + .bDescriptorType = USB_DT_ENDPOINT, + .bEndpointAddress = 0x01, + .bmAttributes = USB_ENDPOINT_ATTR_BULK, + .wMaxPacketSize = 64, + .bInterval = 1, + }, + + { + .bLength = USB_DT_ENDPOINT_SIZE, + .bDescriptorType = USB_DT_ENDPOINT, + .bEndpointAddress = 0x82, + .bmAttributes = USB_ENDPOINT_ATTR_BULK, + .wMaxPacketSize = 64, + .bInterval = 1, + } +}; + + + +static const struct +{ + struct usb_cdc_header_descriptor header; + struct usb_cdc_call_management_descriptor call_mgmt; + struct usb_cdc_acm_descriptor acm; + struct usb_cdc_union_descriptor cdc_union; +} +__attribute__((packed)) cdcacm_functional_descriptors = +{ + + .header = + { + .bFunctionLength = sizeof(struct usb_cdc_header_descriptor), + .bDescriptorType = CS_INTERFACE, + .bDescriptorSubtype = USB_CDC_TYPE_HEADER, + .bcdCDC = 0x0110, + }, + + .call_mgmt = + { + .bFunctionLength = + sizeof(struct usb_cdc_call_management_descriptor), + .bDescriptorType = CS_INTERFACE, + .bDescriptorSubtype = USB_CDC_TYPE_CALL_MANAGEMENT, + .bmCapabilities = 0, + .bDataInterface = 1, + }, + + .acm = + { + .bFunctionLength = sizeof(struct usb_cdc_acm_descriptor), + .bDescriptorType = CS_INTERFACE, + .bDescriptorSubtype = USB_CDC_TYPE_ACM, + .bmCapabilities = 0, + }, + + .cdc_union = + { + .bFunctionLength = sizeof(struct usb_cdc_union_descriptor), + .bDescriptorType = CS_INTERFACE, + .bDescriptorSubtype = USB_CDC_TYPE_UNION, + .bControlInterface = 0, + .bSubordinateInterface0 = 1, + } + +}; + + + +static const struct usb_interface_descriptor comm_iface[] = +{ + { + .bLength = USB_DT_INTERFACE_SIZE, + .bDescriptorType = USB_DT_INTERFACE, + .bInterfaceNumber = 0, + .bAlternateSetting = 0, + .bNumEndpoints = 1, + .bInterfaceClass = USB_CLASS_CDC, + .bInterfaceSubClass = USB_CDC_SUBCLASS_ACM, + .bInterfaceProtocol = USB_CDC_PROTOCOL_AT, + .iInterface = 0, + + .endpoint = comm_endp, + + .extra = &cdcacm_functional_descriptors, + .extralen = sizeof(cdcacm_functional_descriptors) +}}; + + + +static const struct usb_interface_descriptor data_iface[] = +{{ + .bLength = USB_DT_INTERFACE_SIZE, + .bDescriptorType = USB_DT_INTERFACE, + .bInterfaceNumber = 1, + .bAlternateSetting = 0, + .bNumEndpoints = 2, + .bInterfaceClass = USB_CLASS_DATA, + .bInterfaceSubClass = 0, + .bInterfaceProtocol = 0, + .iInterface = 0, + + .endpoint = data_endp, +}}; + + +static const struct usb_interface ifaces[] = +{ + { + .num_altsetting = 1, + .altsetting = comm_iface, + }, + + { + .num_altsetting = 1, + .altsetting = data_iface, + } +}; + + +static const struct usb_config_descriptor config = +{ + .bLength = USB_DT_CONFIGURATION_SIZE, + .bDescriptorType = USB_DT_CONFIGURATION, + .wTotalLength = 0, + .bNumInterfaces = 2, + .bConfigurationValue = 1, + .iConfiguration = 0, + .bmAttributes = 0x80, + .bMaxPower = 0x32, + + .interface = ifaces, +}; + + +static const char *usb_strings[] = +{ + "VUT - BROB projekt", + "Inductor-tester", + "DEMO", +}; + + +// Buffer to be used for control requests. + +static int cdcacm_control_request(usbd_device *usbd_dev, struct usb_setup_data *req, uint8_t **buf, uint16_t *len, void (**complete)(usbd_device *usbd_dev, struct usb_setup_data *req)); + +static void cdcacm_data_rx_cb(usbd_device *usbd_dev, uint8_t ep); + +static void cdcacm_set_config(usbd_device *usbd_dev, uint16_t wValue); + + +#endif diff --git a/fw/f4discovery/project.cbp b/fw/f4discovery/project.cbp index 16c508c..85b16e3 100644 --- a/fw/f4discovery/project.cbp +++ b/fw/f4discovery/project.cbp @@ -47,11 +47,18 @@ + + + + + @@ -873,6 +880,10 @@ + + @@ -885,27 +896,33 @@ + + + + - - - - + + + + - + diff --git a/fw/f4discovery/project.layout b/fw/f4discovery/project.layout index 75f49a0..1d24d6a 100644 --- a/fw/f4discovery/project.layout +++ b/fw/f4discovery/project.layout @@ -1,14 +1,150 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - + + + + + + + + + + + @@ -16,69 +152,95 @@ - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + + + + + + + + + + + + - + - + - + - + - + - + - + - + - + - + + + + + + + + + + + + + + + + @@ -86,19 +248,19 @@ - + - + - + - + - + - + diff --git a/fw/f4discovery/src/dac.c b/fw/f4discovery/src/dac.c new file mode 100644 index 0000000..ec0222d --- /dev/null +++ b/fw/f4discovery/src/dac.c @@ -0,0 +1,28 @@ + +#include "dac.h" +void dac_init(void) +{ + rcc_clock_setup_hse_3v3(&hse_8mhz_3v3[CLOCK_3V3_120MHZ]); //nastaveni globalnich hodin + rcc_periph_clock_enable(RCC_GPIOA); //pusteni hodin pro port A + rcc_periph_clock_enable(RCC_DAC); //pusteni hodin pro DAC + + gpio_mode_setup(GPIOA, GPIO_MODE_ANALOG, GPIO_PUPD_NONE, GPIO4); //pin4 portu A nako analogovy bez pullu/pulldown + dac_disable(CHANNEL_1); //zakazani kanalu 1 DAC + dac_disable_waveform_generation(CHANNEL_1); //bastaveni generovani signalu na kanalu 1 DAC + dac_enable(CHANNEL_1); //Povoleni DAC na kanalu 1 + dac_set_trigger_source(DAC_CR_TSEL1_SW); //Triger kanalu 1 nastaven na softwarovy +} + +void set_napeti(uint16_t napeti) +{ + napeti*=(0xFFF/(15)); + dac_load_data_buffer_single(napeti, RIGHT12, CHANNEL_1);//do kanalu 1 DAC nahrat hodnotu (j) + dac_software_trigger(CHANNEL_1); //pustit hodnotu ven +} + +/* takhle se pak nastavi hodnota do DAC + + dac_load_data_buffer_single(j, RIGHT12, CHANNEL_1);//do kanalu 1 DAC nahrat hodnotu (j) + dac_software_trigger(CHANNEL_1); //pustit hodnotu ven + +*/ diff --git a/fw/f4discovery/src/main.c b/fw/f4discovery/src/main.c index 90f14e8..4421ad4 100644 --- a/fw/f4discovery/src/main.c +++ b/fw/f4discovery/src/main.c @@ -3,6 +3,9 @@ #include #include #include +#include +#include +#include #include #include #include @@ -12,32 +15,82 @@ #include "serial.h" #include "pwm.h" #include "current.h" +#include "usb_vilem.h" +#include "usb_vilem.c" +#include "dac.h" +#include "protokol.h" + +struct Param_Mer Parametry; //struktura do tkere se ulozi parametry mereni +uint8_t usbd_control_buffer[64]; //bufer pro usb +uint16_t nas_koef=1; //nasobici koeficient pro pripadne delsi mereni static uint8_t rbuf[1024]; static uint8_t tbuf[1024]; FILE *us2; +usbd_device *usbd_dev; +volatile bool run = false; void usa_rxb(uint8_t ch); void adc_finish(uint16_t values[]); +void inicializace(void); -volatile bool run = false; +void inicializace() +{ + rcc_clock_setup_hse_3v3(&hse_8mhz_3v3[CLOCK_3V3_120MHZ]); //nastaveni obecnych hodin +//usb + rcc_periph_clock_enable(RCC_GPIOD); //povoleni hodin pro port D kvuli bliknu ti led pri poslani 'p' - pak ostranit + + rcc_peripheral_enable_clock(&RCC_AHB1ENR, RCC_AHB1ENR_IOPAEN); //povoleni hodin pro usb + rcc_peripheral_enable_clock(&RCC_AHB2ENR, RCC_AHB2ENR_OTGFSEN); //povoleni hodin pro usb + + gpio_mode_setup(GPIOA, GPIO_MODE_AF, GPIO_PUPD_NONE, GPIO9 | GPIO11 | GPIO12); //u portu A + gpio_set_af(GPIOA, GPIO_AF10, GPIO9 | GPIO11 | GPIO12); //na pinech 9, 11, 12 posru A alternativni fce USB + usbd_dev = usbd_init(&otgfs_usb_driver, &dev, &config, usb_strings, 3, usbd_control_buffer, sizeof(usbd_control_buffer)); //vytvoreni noveho USB + usbd_register_set_config_callback(usbd_dev, cdcacm_set_config); //nastaveni "funkci" ktere jsou volany na obsluhu +//usb end + + us2 = fopenserial(1, 115200, tbuf,1024,rbuf,1024); // novy soubor pro uart + + leds_init(); //inicializace let + pwm_init(); //inicializace pwm + current_init(); //inicializace AD prevodniku + dac_init(); //inicializace DAC + init_protokol(); //inicializace protokolu +} void adc_finish(uint16_t values[]) { if (!run) return; - fwrite(&pwm[3],1,2,us2); + uint32_t pom=pwm[3]/nas_koef; + + char zn[8]; + zn[0]=pom; + zn[1]=pom/256; + zn[2]=values[0]; + zn[3]=values[0]/256; + zn[4]=values[1]; + zn[5]=values[1]/256; + zn[6]=values[3]; + zn[7]=values[3]/256; + + /*fwrite(&pwm[3],1,2,us2); //bylo zruseno, rpotoze debuger si stezoval, ze arm se pokusil pristoupit nekam do pameti akm nemel fwrite(&values[0],1,2,us2); fwrite(&values[1],1,2,us2); - fwrite(&values[2],1,2,us2); - - // increment TIM5/OC4 - pwm[3] = (pwm[3] + 1) & 0xFFF; + fwrite(&values[2],1,2,us2);*/ - if (pwm[3] == 0) - run = false; + usbd_ep_write_packet(usbd_dev, 0x82, &zn, 8); + // increment TIM5/OC4 + pwm[3] = (pwm[3] + nas_koef) & (0xFFF*nas_koef); + + if (pwm[3] == 0) //zmereny vsechny hodnoty? + { + run = false; //zastav mereni + if(Parametry.set_param==1) //pokud prisel pokyn zmenit nastaveny parametry + set_mer(); //zmen je + } timer_set_oc_value(TIM5, TIM_OC4, pwm[3]); } @@ -45,31 +98,44 @@ void usa_rxb(uint8_t ch) { (void)ch; pwm[3] = 1; - timer_set_oc_value(TIM5, TIM_OC4, pwm[3]); + timer_set_oc_value(TIM5, TIM_OC4, pwm[0]); run = true; } int main(void) { - rcc_clock_setup_hse_3v3(&hse_8mhz_3v3[CLOCK_3V3_168MHZ]); - - us2 = fopenserial(1, 115200, tbuf,1024,rbuf,1024); - - leds_init(); - pwm_init(); - current_init(); - - while (1) { - - for (int i = 0; i < 1000000000; i++) /* Wait a bit. */ - __asm__("nop"); - - LED_TGL(LED0); - - pwm[3] = 1; - timer_set_oc_value(TIM5, TIM_OC4, pwm[3]); - run = true; + inicializace(); + + while (1) + { + //for (int i = 0; i < 100000000; i++) /* Wait a bit. */ + { + //__asm__("nop"); + usbd_poll(usbd_dev); //obsluha USB + } + + if(run==true) + { + LED_ON(LED0); + } + else + { + LED_OFF(LED0); + } + + /* gpio_mode_setup(GPIOA, GPIO_MODE_INPUT, GPIO_PUPD_NONE, GPIO0); + if ((GPIOA_IDR & (1 << 0)) != 0) + { + + pwm[3]=1; + run=true; + }*/ //pouze pokus dkyz byl tento fw testovan se starsim programem + + //pwm[3] = 1; + //timer_set_oc_value(TIM5, TIM_OC4, pwm[3]); + //run = true; } return 0; } + diff --git a/fw/f4discovery/src/protokol.c b/fw/f4discovery/src/protokol.c new file mode 100644 index 0000000..248bce2 --- /dev/null +++ b/fw/f4discovery/src/protokol.c @@ -0,0 +1,70 @@ +#include "protokol.h" + +extern volatile bool run; +extern struct Param_Mer Parametry; +extern int16_t nas_koef; + +//naplni strukturu daty z retezce +void protokol(char *buf) //buf = 0 pro pepsat nastaveni, 1 pro spustit a 2 pro prepsat a spustit +{ + if(buf[0]==0) + { + Parametry.Cas_Nas=buf[3]*256+buf[4]; //uloz cas mereni + Parametry.Napeti=buf[1]*256+buf[2]; //uloz merici napeti + Parametry.set_param=1; //nastav ze se maji zmenit parametry po domereni + Parametry.start_mer=0; // mereni se nema hend spustit + } + else if(buf[0]==1) + { + pwm[3] = 1; //vyresetuj mereni + timer_set_oc_value(TIM5, TIM_OC4, pwm[3]); // nahraj do timeru 1 + run=true; //spust mereni + } + else if(buf[0]==2) + { + Parametry.Cas_Nas=buf[3]*256+buf[4]; //uloz do struktury cas + Parametry.Napeti=buf[1]*256+buf[2]; //uloz do struktury merici napeti + Parametry.set_param=1; //uloz priznak ze se maji zmenit parametry + Parametry.start_mer=1; //uloz priznak ze se hned ma spustit nove mereni + set_mer(); //zavolej fci, ktera prenese data ze struktury do patricnych periferii a promenych + } + else + { + run=false; //zastav mereni + } + +} + +void set_mer(void) //prenese parametry ze struktury do promenych, a podle hodnoty ve strukture spusti enbo enspusti mereni +{ + set_napeti(Parametry.Napeti); //zavolej fci ktera nastavi vystupni anpeti + nas_koef=Parametry.Cas_Nas; //uloz merici cas + pwm[0]=Parametry.Cas_Nas*Parametry.default_pwm[0]; //do pole s parametry citacu uloz hodnoty + pwm[1]=Parametry.Cas_Nas*Parametry.default_pwm[1]; + pwm[2]=Parametry.Cas_Nas*Parametry.default_pwm[2]; + pwm_init(); // volanim teto fce nahraju hodnoty do citacu + Parametry.set_param=0; //zakazani dalsiho volani teto funkce kdyz se nezmenily parametry mereni + if(Parametry.start_mer==1) + { + Parametry.start_mer=0; //zablokovani dalsiho spusteni mereno + pwm[3] = 1; //reset citace od kereho se odviji spusteni ADC + timer_set_oc_value(TIM5, TIM_OC4, pwm[3]); + run=true;//spusteni mereni + + } + + +} + +void init_protokol(void) //nastavi implicitni hodnoty struktury +{ + Parametry.set_param=0; //vynulovani struktury na nastaveni parametru mereni + Parametry.Napeti=0; + Parametry.Cas_Nas=1; + Parametry.start_mer=0; + Parametry.default_pwm[0]=pwm[0]; + Parametry.default_pwm[1]=pwm[1]; + Parametry.default_pwm[2]=pwm[2]; + Parametry.default_pwm[3]=pwm[3]; + +} diff --git a/fw/f4discovery/src/pwm.c b/fw/f4discovery/src/pwm.c index 56581a2..c77cd0e 100644 --- a/fw/f4discovery/src/pwm.c +++ b/fw/f4discovery/src/pwm.c @@ -6,6 +6,7 @@ #include "pwm.h" uint32_t pwm[4] = { 0x4FF, 0x2FF, 0x7FF, 1}; +extern uint16_t nas_koef; void pwm_init(void) { @@ -18,10 +19,10 @@ void pwm_init(void) gpio_set_output_options(GPIOA, GPIO_OTYPE_PP, GPIO_OSPEED_50MHZ, GPIO0 | GPIO1 | GPIO2 | GPIO3); - timer_reset(TIM5); + timer_reset(TIM5); //hlavni citac timer_set_mode(TIM5, TIM_CR1_CKD_CK_INT, TIM_CR1_CMS_EDGE, TIM_CR1_DIR_UP); timer_set_prescaler(TIM5, 1); // 20.5kHz - timer_set_period(TIM5, 0xFFF); + timer_set_period(TIM5, 0xFFF*nas_koef); //cita do fff nastaveni periody citani timer_set_counter(TIM5, 0); timer_set_repetition_counter(TIM5, 0); timer_continuous_mode(TIM5); @@ -48,7 +49,7 @@ void pwm_init(void) /* -- OC3 and OC2N configuration -- */ - timer_disable_oc_output(TIM5, TIM_OC3); + timer_disable_oc_output(TIM5, TIM_OC3); // synchronizace na osciloskop timer_enable_oc_preload(TIM5, TIM_OC3); timer_set_oc_mode(TIM5, TIM_OC3, TIM_OCM_PWM1); timer_set_oc_polarity_high(TIM5, TIM_OC3); @@ -58,7 +59,7 @@ void pwm_init(void) /* -- OC4 and OC2N configuration -- */ - timer_disable_oc_output(TIM5, TIM_OC4); + timer_disable_oc_output(TIM5, TIM_OC4); // venku nikam nepripojovat timer_enable_oc_preload(TIM5, TIM_OC4); timer_set_oc_mode(TIM5, TIM_OC4, TIM_OCM_PWM1); timer_set_oc_polarity_high(TIM5, TIM_OC4); diff --git a/fw/f4discovery/src/usb_vilem.c b/fw/f4discovery/src/usb_vilem.c new file mode 100644 index 0000000..5170be3 --- /dev/null +++ b/fw/f4discovery/src/usb_vilem.c @@ -0,0 +1,76 @@ +#include +#include +#include +#include +#include +#include +#include "usb_vilem.h" +#include "protokol.h" + +static int cdcacm_control_request(usbd_device *usbd_dev, struct usb_setup_data *req, uint8_t **buf, + uint16_t *len, void (**complete)(usbd_device *usbd_dev, struct usb_setup_data *req)) +{ + (void)complete; + (void)buf; + (void)usbd_dev; + + + switch (req->bRequest) + { + case USB_CDC_REQ_SET_CONTROL_LINE_STATE: + { + // + //* This Linux cdc_acm driver requires this to be implemented + // * even though it's optional in the CDC spec, and we don't + // * advertise it in the ACM functional descriptor. + // + return 1; + } + case USB_CDC_REQ_SET_LINE_CODING: + if (*len < sizeof(struct usb_cdc_line_coding)) + return 0; + return 1; + default: + return 1; + } + + return 0; +} + + +static void cdcacm_data_rx_cb(usbd_device *usbd_dev, uint8_t ep) +{ + + (void)ep; + char buf[64]; + int len = usbd_ep_read_packet(usbd_dev, 0x01, buf, 64); + + + + /* if (len) + { + while (usbd_ep_write_packet(usbd_dev, 0x82, buf, len) == 0); + }*/ + + if(len) + protokol(buf); + gpio_toggle(GPIOC, GPIO5); +} + + +void cdcacm_set_config(usbd_device *usbd_dev, uint16_t wValue)//puvodne static +{ + (void)wValue; + + usbd_ep_setup(usbd_dev, 0x01, USB_ENDPOINT_ATTR_BULK, 64, cdcacm_data_rx_cb); + usbd_ep_setup(usbd_dev, 0x82, USB_ENDPOINT_ATTR_BULK, 64, NULL); + usbd_ep_setup(usbd_dev, 0x83, USB_ENDPOINT_ATTR_INTERRUPT, 16, NULL); + + usbd_register_control_callback( + usbd_dev, + USB_REQ_TYPE_CLASS | USB_REQ_TYPE_INTERFACE, + USB_REQ_TYPE_TYPE | USB_REQ_TYPE_RECIPIENT, + cdcacm_control_request); +} + + diff --git a/sw/InductorTester/App.config b/sw/InductorTester/App.config index 8e15646..58262a1 100644 --- a/sw/InductorTester/App.config +++ b/sw/InductorTester/App.config @@ -1,6 +1,6 @@ - + - + - \ No newline at end of file + diff --git a/sw/InductorTester/Forms/frmMain.Designer.cs b/sw/InductorTester/Forms/frmMain.Designer.cs index cae044a..c1d3352 100644 --- a/sw/InductorTester/Forms/frmMain.Designer.cs +++ b/sw/InductorTester/Forms/frmMain.Designer.cs @@ -50,12 +50,23 @@ private void InitializeComponent() this.label3 = new System.Windows.Forms.Label(); this.label2 = new System.Windows.Forms.Label(); this.label1 = new System.Windows.Forms.Label(); - this.label6 = new System.Windows.Forms.Label(); - this.bCursorL = new System.Windows.Forms.Label(); - this.bCursorL2 = new System.Windows.Forms.Label(); + this.button2 = new System.Windows.Forms.Button(); + this.ComboPortBox = new System.Windows.Forms.ComboBox(); + this.label7 = new System.Windows.Forms.Label(); + this.groupBox2 = new System.Windows.Forms.GroupBox(); + this.LabelKolenoI = new System.Windows.Forms.Label(); + this.LabelKolenoL = new System.Windows.Forms.Label(); + this.label9 = new System.Windows.Forms.Label(); + this.label8 = new System.Windows.Forms.Label(); + this.TextBoxMesRepeat = new System.Windows.Forms.TextBox(); + this.TextBoxMesPoints = new System.Windows.Forms.TextBox(); + this.label10 = new System.Windows.Forms.Label(); + this.label11 = new System.Windows.Forms.Label(); + this.button3 = new System.Windows.Forms.Button(); ((System.ComponentModel.ISupportInitialize)(this.chart1)).BeginInit(); ((System.ComponentModel.ISupportInitialize)(this.numericUpDown1)).BeginInit(); this.groupBox1.SuspendLayout(); + this.groupBox2.SuspendLayout(); this.SuspendLayout(); // // port @@ -64,7 +75,7 @@ private void InitializeComponent() this.port.PortName = "COM9"; this.port.ReadBufferSize = 16384; this.port.ReadTimeout = 1000; - this.port.ReceivedBytesThreshold = 8; + this.port.ReceivedBytesThreshold = 9; this.port.DataReceived += new System.IO.Ports.SerialDataReceivedEventHandler(this.port_DataReceived); // // chart1 @@ -117,17 +128,16 @@ private void InitializeComponent() // button1 // this.button1.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left))); - this.button1.Location = new System.Drawing.Point(96, 491); + this.button1.Location = new System.Drawing.Point(157, 488); this.button1.Name = "button1"; - this.button1.Size = new System.Drawing.Size(75, 23); + this.button1.Size = new System.Drawing.Size(90, 23); this.button1.TabIndex = 1; - this.button1.Text = "button1"; + this.button1.Text = "Draw Current"; this.button1.UseVisualStyleBackColor = true; this.button1.Click += new System.EventHandler(this.button1_Click); // // timer1 // - this.timer1.Enabled = true; this.timer1.Interval = 500; this.timer1.Tick += new System.EventHandler(this.button1_Click); // @@ -153,9 +163,6 @@ private void InitializeComponent() // groupBox1 // this.groupBox1.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right))); - this.groupBox1.Controls.Add(this.bCursorL2); - this.groupBox1.Controls.Add(this.bCursorL); - this.groupBox1.Controls.Add(this.label6); this.groupBox1.Controls.Add(this.bCursorVoltage); this.groupBox1.Controls.Add(this.bCursorI2); this.groupBox1.Controls.Add(this.bCursorI1); @@ -179,7 +186,7 @@ private void InitializeComponent() this.bCursorVoltage.Name = "bCursorVoltage"; this.bCursorVoltage.Size = new System.Drawing.Size(50, 13); this.bCursorVoltage.TabIndex = 9; - this.bCursorVoltage.Text = "36.12 V"; + this.bCursorVoltage.Text = "36.12 H"; this.bCursorVoltage.TextAlign = System.Drawing.ContentAlignment.MiddleLeft; // // bCursorI2 @@ -197,7 +204,7 @@ private void InitializeComponent() this.bCursorI1.Name = "bCursorI1"; this.bCursorI1.Size = new System.Drawing.Size(50, 13); this.bCursorI1.TabIndex = 7; - this.bCursorI1.Text = "3.62 A"; + this.bCursorI1.Text = "3.62 V"; this.bCursorI1.TextAlign = System.Drawing.ContentAlignment.MiddleLeft; // // bCursorTime @@ -225,17 +232,17 @@ private void InitializeComponent() this.label5.Name = "label5"; this.label5.Size = new System.Drawing.Size(50, 13); this.label5.TabIndex = 4; - this.label5.Text = "Vcc"; + this.label5.Text = "L"; this.label5.TextAlign = System.Drawing.ContentAlignment.MiddleRight; // // label4 // this.label4.Font = new System.Drawing.Font("Microsoft Sans Serif", 8.25F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(238))); - this.label4.Location = new System.Drawing.Point(6, 66); + this.label4.Location = new System.Drawing.Point(4, 66); this.label4.Name = "label4"; this.label4.Size = new System.Drawing.Size(50, 13); this.label4.TabIndex = 3; - this.label4.Text = "I2"; + this.label4.Text = "I"; this.label4.TextAlign = System.Drawing.ContentAlignment.MiddleRight; // // label3 @@ -245,7 +252,7 @@ private void InitializeComponent() this.label3.Name = "label3"; this.label3.Size = new System.Drawing.Size(50, 13); this.label3.TabIndex = 2; - this.label3.Text = "I1"; + this.label3.Text = "U"; this.label3.TextAlign = System.Drawing.ContentAlignment.MiddleRight; // // label2 @@ -268,39 +275,145 @@ private void InitializeComponent() this.label1.Text = "Sample"; this.label1.TextAlign = System.Drawing.ContentAlignment.MiddleRight; // - // label6 - // - this.label6.Font = new System.Drawing.Font("Microsoft Sans Serif", 8.25F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(238))); - this.label6.Location = new System.Drawing.Point(6, 92); - this.label6.Name = "label6"; - this.label6.Size = new System.Drawing.Size(50, 13); - this.label6.TabIndex = 5; - this.label6.Text = "L"; - this.label6.TextAlign = System.Drawing.ContentAlignment.MiddleRight; - // - // bCursorL - // - this.bCursorL.Location = new System.Drawing.Point(62, 92); - this.bCursorL.Name = "bCursorL"; - this.bCursorL.Size = new System.Drawing.Size(50, 13); - this.bCursorL.TabIndex = 10; - this.bCursorL.Text = "500 uH"; - this.bCursorL.TextAlign = System.Drawing.ContentAlignment.MiddleLeft; - // - // bCursorL2 - // - this.bCursorL2.Location = new System.Drawing.Point(62, 105); - this.bCursorL2.Name = "bCursorL2"; - this.bCursorL2.Size = new System.Drawing.Size(50, 13); - this.bCursorL2.TabIndex = 11; - this.bCursorL2.Text = "500 uH"; - this.bCursorL2.TextAlign = System.Drawing.ContentAlignment.MiddleLeft; + // button2 + // + this.button2.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left))); + this.button2.Location = new System.Drawing.Point(265, 488); + this.button2.Name = "button2"; + this.button2.Size = new System.Drawing.Size(112, 23); + this.button2.TabIndex = 4; + this.button2.Text = "Draw Inductance"; + this.button2.UseVisualStyleBackColor = true; + this.button2.Click += new System.EventHandler(this.button2_Click); + // + // ComboPortBox + // + this.ComboPortBox.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right))); + this.ComboPortBox.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList; + this.ComboPortBox.FormattingEnabled = true; + this.ComboPortBox.Location = new System.Drawing.Point(735, 482); + this.ComboPortBox.Name = "ComboPortBox"; + this.ComboPortBox.Size = new System.Drawing.Size(121, 21); + this.ComboPortBox.TabIndex = 6; + this.ComboPortBox.TextChanged += new System.EventHandler(this.PortSelected); + // + // label7 + // + this.label7.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right))); + this.label7.AutoSize = true; + this.label7.Location = new System.Drawing.Point(730, 461); + this.label7.Name = "label7"; + this.label7.Size = new System.Drawing.Size(135, 13); + this.label7.TabIndex = 7; + this.label7.Text = "Select Port (Default COM9)"; + // + // groupBox2 + // + this.groupBox2.Controls.Add(this.LabelKolenoI); + this.groupBox2.Controls.Add(this.LabelKolenoL); + this.groupBox2.Controls.Add(this.label9); + this.groupBox2.Controls.Add(this.label8); + this.groupBox2.Location = new System.Drawing.Point(724, 381); + this.groupBox2.Name = "groupBox2"; + this.groupBox2.Size = new System.Drawing.Size(132, 65); + this.groupBox2.TabIndex = 8; + this.groupBox2.TabStop = false; + this.groupBox2.Text = "Koleno L char"; + // + // LabelKolenoI + // + this.LabelKolenoI.AutoSize = true; + this.LabelKolenoI.Location = new System.Drawing.Point(80, 42); + this.LabelKolenoI.Name = "LabelKolenoI"; + this.LabelKolenoI.Size = new System.Drawing.Size(31, 13); + this.LabelKolenoI.TabIndex = 12; + this.LabelKolenoI.Text = "0 mA"; + // + // LabelKolenoL + // + this.LabelKolenoL.AutoSize = true; + this.LabelKolenoL.Location = new System.Drawing.Point(80, 20); + this.LabelKolenoL.Name = "LabelKolenoL"; + this.LabelKolenoL.Size = new System.Drawing.Size(30, 13); + this.LabelKolenoL.TabIndex = 11; + this.LabelKolenoL.Text = "0 uH"; + // + // label9 + // + this.label9.AutoSize = true; + this.label9.Location = new System.Drawing.Point(8, 42); + this.label9.Name = "label9"; + this.label9.Size = new System.Drawing.Size(10, 13); + this.label9.TabIndex = 10; + this.label9.Text = "I"; + // + // label8 + // + this.label8.AutoSize = true; + this.label8.Location = new System.Drawing.Point(8, 20); + this.label8.Name = "label8"; + this.label8.Size = new System.Drawing.Size(13, 13); + this.label8.TabIndex = 9; + this.label8.Text = "L"; + // + // TextBoxMesRepeat + // + this.TextBoxMesRepeat.Location = new System.Drawing.Point(736, 355); + this.TextBoxMesRepeat.Name = "TextBoxMesRepeat"; + this.TextBoxMesRepeat.Size = new System.Drawing.Size(109, 20); + this.TextBoxMesRepeat.TabIndex = 9; + this.TextBoxMesRepeat.TextChanged += new System.EventHandler(this.NumberOfMesChanged); + // + // TextBoxMesPoints + // + this.TextBoxMesPoints.Location = new System.Drawing.Point(736, 310); + this.TextBoxMesPoints.Name = "TextBoxMesPoints"; + this.TextBoxMesPoints.Size = new System.Drawing.Size(109, 20); + this.TextBoxMesPoints.TabIndex = 10; + this.TextBoxMesPoints.TextChanged += new System.EventHandler(this.NumberOfSamplesChanged); + // + // label10 + // + this.label10.AutoSize = true; + this.label10.Location = new System.Drawing.Point(739, 294); + this.label10.Name = "label10"; + this.label10.Size = new System.Drawing.Size(108, 13); + this.label10.TabIndex = 11; + this.label10.Text = "Samples per measure"; + // + // label11 + // + this.label11.AutoSize = true; + this.label11.Location = new System.Drawing.Point(739, 339); + this.label11.Name = "label11"; + this.label11.Size = new System.Drawing.Size(99, 13); + this.label11.TabIndex = 12; + this.label11.Text = "Number of measure"; + // + // button3 + // + this.button3.Location = new System.Drawing.Point(736, 259); + this.button3.Name = "button3"; + this.button3.Size = new System.Drawing.Size(109, 23); + this.button3.TabIndex = 13; + this.button3.Text = "Reset Measure"; + this.button3.UseVisualStyleBackColor = true; + this.button3.Click += new System.EventHandler(this.Button3_Click); // // Form1 // this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F); this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; this.ClientSize = new System.Drawing.Size(868, 515); + this.Controls.Add(this.button3); + this.Controls.Add(this.label11); + this.Controls.Add(this.label10); + this.Controls.Add(this.TextBoxMesPoints); + this.Controls.Add(this.TextBoxMesRepeat); + this.Controls.Add(this.groupBox2); + this.Controls.Add(this.label7); + this.Controls.Add(this.ComboPortBox); + this.Controls.Add(this.button2); this.Controls.Add(this.groupBox1); this.Controls.Add(this.numericUpDown1); this.Controls.Add(this.button1); @@ -311,7 +424,10 @@ private void InitializeComponent() ((System.ComponentModel.ISupportInitialize)(this.chart1)).EndInit(); ((System.ComponentModel.ISupportInitialize)(this.numericUpDown1)).EndInit(); this.groupBox1.ResumeLayout(false); + this.groupBox2.ResumeLayout(false); + this.groupBox2.PerformLayout(); this.ResumeLayout(false); + this.PerformLayout(); } @@ -333,9 +449,19 @@ private void InitializeComponent() private System.Windows.Forms.Label label3; private System.Windows.Forms.Label label2; private System.Windows.Forms.Label label1; - private System.Windows.Forms.Label bCursorL; - private System.Windows.Forms.Label label6; - private System.Windows.Forms.Label bCursorL2; + private System.Windows.Forms.Button button2; + private System.Windows.Forms.ComboBox ComboPortBox; + private System.Windows.Forms.Label label7; + private System.Windows.Forms.GroupBox groupBox2; + private System.Windows.Forms.Label LabelKolenoI; + private System.Windows.Forms.Label LabelKolenoL; + private System.Windows.Forms.Label label9; + private System.Windows.Forms.Label label8; + private System.Windows.Forms.TextBox TextBoxMesRepeat; + private System.Windows.Forms.TextBox TextBoxMesPoints; + private System.Windows.Forms.Label label10; + private System.Windows.Forms.Label label11; + private System.Windows.Forms.Button button3; } } diff --git a/sw/InductorTester/Forms/frmMain.cs b/sw/InductorTester/Forms/frmMain.cs index f3124d2..881b57b 100644 --- a/sw/InductorTester/Forms/frmMain.cs +++ b/sw/InductorTester/Forms/frmMain.cs @@ -8,6 +8,13 @@ using System.Text; using System.Threading.Tasks; using System.Windows.Forms; +using System.IO; +//osa Y se musí změnit podle hodnot aby se tam vlezly +//Je potřeba metoda která vypočte závislost indukce na proudu +// zvetsit u portu pocet bytu nez se ma spustit read na 9 (navic 1 byte na cteni zesileni proudu) +// pridat do data recieved buffer na 1 byte, ktery bude brat ten byte od zesileni +// napred znormalizovat a pak jeste podelit zesilenim proudu +// meri se id, napeti, proud 1, proud 2, funguje na stridacku jen jeden proud, druhy tam ma nejaky srance namespace tester { @@ -15,7 +22,7 @@ public partial class Form1 : Form { public Form1() { - InitializeComponent(); + InitializeComponent(); // inicializuje prvky ve formu } private void chart1_Click(object sender, EventArgs e) @@ -24,24 +31,35 @@ private void chart1_Click(object sender, EventArgs e) } UInt16 oldid = 0; - double[] adc1 = new double[0x1000]; - double[] adc2 = new double[0x1000]; - double[] adc3 = new double[0x1000]; + UInt16 knee = 0; + uint points_per_mes = 1000; + uint number_of_mes = 3; + uint id_of_mes = 0; + bool curr_graph = true; - double adc1_offset = 47932; // nula - double adc2_offset = 47595; - double adc3_offset = -255; + double[] adc1 = new double[0x1000]; //pole pro hodnoty napeti (volty) + double[] adc2 = new double[0x1000]; //pole pro hodnoty proudu ve forme napeti (volty) + double[] adc3 = new double[0x1000]; //pole pro vypoctene hodnoty proudu (ampery) + double[] adc4 = new double[0x1000]; //pole pro vypoctene hodnoty indukcnosti (henry) + double[] adc5 = new double[0x1000]; //pole pro hodnoty zesileni proudu - double adc1_gain = -3805 * 2; // 1A - double adc2_gain = 3616 * 2; - double adc3_gain = 2320; + double adc1_offset = 237; //pro napeti + double adc2_offset = 100; //pro prvni proud + double adc3_offset = 100; //pro druhy proud + double adc5_offset = 0; //pro zesileni - double time_scale = 0.0238; + double adc1_gain = 1000; //napeti + double adc2_gain = 1000; //prvni proud + double adc3_gain = 1000; //druhy proud + double adc5_gain = 1; //zesileni + double time_scale = 0.0238; //rozliseni casove zakladny + double resistance = 0.33; //odpor pro vypocet proudu private UInt16 ReadU16(System.IO.Stream stm) { + // přečte 2 byty ze streamu a vrátí je jako unsigned int16 byte[] buffer = new byte[2]; stm.Read(buffer, 0, 2); return (UInt16)(buffer[0] + buffer[1] * 256); @@ -49,11 +67,14 @@ private UInt16 ReadU16(System.IO.Stream stm) private void port_DataReceived(object sender, System.IO.Ports.SerialDataReceivedEventArgs e) { - while (port.BytesToRead > 8) + byte[] buffer = new byte[1]; //buffer pro zesileni + double pomocnik = 0; + + while (port.BytesToRead > 9) { UInt16 id = ReadU16(port.BaseStream); - if ((oldid + 1 != id) && (id != 1) && (oldid != 0xFFF)) + if ((oldid + 1 != id) && (id != 1) && (oldid != 0xFFF)) //asi zjistuje jestli se neztratily zadny data { Trace.WriteLine("LOST"); oldid = 0; @@ -62,41 +83,149 @@ private void port_DataReceived(object sender, System.IO.Ports.SerialDataReceived oldid = id; - adc1[id] = (ReadU16(port.BaseStream) - adc1_offset) / adc1_gain; - adc2[id] = (ReadU16(port.BaseStream) - adc2_offset) / adc2_gain; - adc3[id] = (ReadU16(port.BaseStream) - adc3_offset) / adc3_gain; + if (id * number_of_mes + id_of_mes <= 0xFFF) + { + port.BaseStream.Read(buffer, 0, 1); + adc5[id * number_of_mes + id_of_mes] = ((UInt16)buffer[0] - adc5_offset) / adc5_gain; //zesileni + + adc1[id * number_of_mes + id_of_mes] = (ReadU16(port.BaseStream) - adc1_offset) / adc1_gain; //napeti + + adc2[id * number_of_mes + id_of_mes] = (ReadU16(port.BaseStream) - adc2_offset) / adc2_gain / adc5[id * number_of_mes + id_of_mes]; //prvni proud + pomocnik = (ReadU16(port.BaseStream) - adc3_offset) / adc3_gain / adc5[id * number_of_mes + id_of_mes]; //druhy proud + if (adc2[id * number_of_mes + id_of_mes] < pomocnik) //porovnani proudu + adc2[id * number_of_mes + id_of_mes] = pomocnik; + } + else + port.DiscardInBuffer(); + } + + if (id_of_mes == (number_of_mes - 1)) //spusti se az kdyz je dokonceno cele mereni + { + for (int i = 0; i < 0xFFF; i++) + { + adc3[i] = adc2[i] / resistance; //vypocita proud + if (i > 1) + adc4[i - 2] = adc1[i - 1] * (adc3[i] - adc3[i - 2]) / (2 * time_scale); //vypocita indukcnost + } + + for (int i = 0; i < 0xFFF; i++) + { + chart1.Series[1].Points.AddXY(adc3[i], 0); //nastavi body Y na 0 a X na hodnoty podle hodnot proudu + } + + id_of_mes = 0; + } + else + id_of_mes++; + } + + private void Form1_Load(object sender, EventArgs e) //tohle se zavola pri vytvoreni formu + { + chart1.Series[0].Points.Clear(); //vymaze body v grafu + chart1.Series[1].Points.Clear(); + + string[] ports = System.IO.Ports.SerialPort.GetPortNames(); + int n = 0; + foreach (string single_port in ports) + { + ComboPortBox.Items.Add(single_port); + n++; + } + + TextBoxMesPoints.Text = points_per_mes.ToString(); + TextBoxMesRepeat.Text = number_of_mes.ToString(); + + if (ports != null && ports.Length != 0) + { + this.ComboPortBox.SelectedItem = ports[0]; + //port.Open(); } } - private void Form1_Load(object sender, EventArgs e) + private void button1_Click(object sender, EventArgs e) //vykresli graf proudu v zavislosti na case { + double min = adc3[0]; + double max = adc3[0]; + + curr_graph = true; + chart1.Series[0].Points.Clear(); chart1.Series[1].Points.Clear(); - chart1.Series[2].Points.Clear(); for (int i = 0; i < 0xFFF; i++) { - chart1.Series[0].Points.AddXY(i * time_scale, 0); - chart1.Series[1].Points.AddXY(i * time_scale, 0); - chart1.Series[2].Points.AddXY(i * time_scale, 0); + chart1.Series[0].Points.AddXY(i * time_scale, adc3[i]); //vykresli ho + if (adc3[i] < min) + min = adc3[i]; + if (adc3[i] > max) + max = adc3[i]; } - port.Open(); + if (max > min) + { + chart1.ChartAreas[0].AxisY.Interval = (System.Math.Ceiling(max) - System.Math.Floor(min)) / 20; + chart1.ChartAreas[0].AxisY.Minimum = System.Math.Floor(min); + chart1.ChartAreas[0].AxisY.Maximum = System.Math.Ceiling(max); + chart1.ChartAreas[0].AxisX.Maximum = System.Math.Ceiling(adc3.Count(i => i != 0) * time_scale); + chart1.ChartAreas[0].AxisX.Interval = chart1.ChartAreas[0].AxisX.Maximum / 20; + chart1.Refresh(); + } } - private void button1_Click(object sender, EventArgs e) + private void button2_Click(object sender, EventArgs e) //vykresli graf indukcnosti v zavislosti na proudu { - for (int i = 0; i < 0xFFF; i++) + double min = adc4[0]; //promenne pro urceni minimalni a maximalni hodnoty na Y ose grafu + double max = adc4[0]; + double max_proud = adc3[0]; + + double last_angle = 0; + double max_dif = 0; + + curr_graph = false; + + chart1.Series[0].Points.Clear(); + chart1.Series[1].Points.Clear(); + + for (int i = 0; i < 0xFFD; i++) + { + chart1.Series[1].Points.AddXY(adc3[i+1], adc4[i]); //vykresluje jednotlive body charakteristiky + + if (adc4[i] < min) //porovnava min a max hodnoty s hodnotami ve vektoru indukcnosti a bere mensi/vetsi hodnotu + min = adc4[i]; + if (adc4[i] > max) + max = adc4[i]; + + if (i == 0) //spocte prvni uhel + last_angle = Math.Atan((adc4[i + 1] - adc4[i]) / (adc3[i + 2] - adc3[i + 1])); + else //spocte druhy uhel, rozdil prvniho a druheho porovna s maximalnim rozdilem + { //koleno charakteristiky je tam kde je maximalni rozdil mezi uhly spojnic bodu + double this_angle = Math.Atan((adc4[i + 1] - adc4[i]) / (adc3[i + 2] - adc3[i + 1])); + if ((this_angle - last_angle) > max_dif) + { + max_dif = this_angle - last_angle; + knee = (UInt16)i; //ulozi pozici kolena charakteristiky + } + } + + if (adc3[i+1] > max_proud) + max_proud = adc3[i+1]; + } + + if (max > min) { - chart1.Series[0].Points[i].SetValueY(adc1[i]); - chart1.Series[1].Points[i].SetValueY(adc2[i]); - chart1.Series[2].Points[i].SetValueY(adc3[i]); + chart1.ChartAreas[0].AxisY.Interval = (System.Math.Ceiling(max) - System.Math.Floor(min)) / 20; //nastavi interval mezi znackami na ose Y + chart1.ChartAreas[0].AxisY.Minimum = System.Math.Floor(min); //nastavi minimum a maximum osy Y + chart1.ChartAreas[0].AxisY.Maximum = System.Math.Ceiling(max); + chart1.ChartAreas[0].AxisX.Maximum = System.Math.Ceiling(max_proud); //nastavi delku osy X + chart1.ChartAreas[0].AxisX.Interval = chart1.ChartAreas[0].AxisX.Maximum / 20; //nastavi interval mezi znackami na ose X + chart1.Refresh(); } - chart1.ChartAreas[0].RecalculateAxesScale(); - chart1.Refresh(); + LabelKolenoI.Text = string.Format("{0:F2} mA", adc3[knee+1] * 1000); + LabelKolenoL.Text = string.Format("{0:F0} uH", adc4[knee] * 1000 * 1000); } + private void numericUpDown1_ValueChanged(object sender, EventArgs e) { chart1.ChartAreas[0].CursorY.Position = (float)numericUpDown1.Value; @@ -108,17 +237,36 @@ private void chart1_MouseMove(object sender, MouseEventArgs e) chart1.ChartAreas[0].CursorX.SetCursorPixelPosition(mousePoint, true); - double curpos = chart1.ChartAreas[0].CursorX.Position; - int curofs = (int)(curpos / time_scale); - double i1 = adc1[curofs & 0xFFF]; - double i2 = adc2[curofs & 0xFFF]; - double vcc = adc3[curofs & 0xFFF]; + double curpos = 0; + int curofs = 0; + double volt = 0; + double curr = 0; + double induct = 0; + + if (curr_graph == true) + { + curpos = chart1.ChartAreas[0].CursorX.Position; + curofs = (int)(curpos / time_scale); + volt = adc1[curofs & 0xFFF]; + curr = adc3[curofs & 0xFFF]; + if (curofs > 0) + induct = adc4[(curofs - 1) & 0xFFF]; + } + else + { + curr = chart1.ChartAreas[0].CursorX.Position; + curofs = (int)Array.IndexOf(adc3, curr); + volt = adc1[curofs & 0xFFF]; + if (curofs > 0) + induct = adc4[(curofs - 1) & 0xFFF]; + curpos = curofs * time_scale; + } bCursorTime.Text = string.Format("{0:F2} us", curpos / 100); bCursorSample.Text = string.Format("0x{0:X3}", curofs); - bCursorI1.Text = string.Format("{0:F3} A", i1); - bCursorI2.Text = string.Format("{0:F3} A", i2); - bCursorVoltage.Text = string.Format("{0:F2} V", vcc); + bCursorI1.Text = string.Format("{0:F3} V", volt); + bCursorI2.Text = string.Format("{0:F3} A", curr); + bCursorVoltage.Text = string.Format("{0:F2} H", induct); int dt = 50; double sx = 0, sy1 = 0, sxy1 = 0, sy2 = 0, sxy2 = 0, sx2 = 0, s1 = 0, svcc = 0; @@ -137,12 +285,41 @@ private void chart1_MouseMove(object sender, MouseEventArgs e) s1 += 1; svcc += adc3[i]; } + } - double L1 = (svcc/s1) * (s1 * sxy1 - sx * sy1) / (s1 * sx2 - sx * sx); - double L2 = (svcc/s1) * (s1 * sxy2 - sx * sy2) / (s1 * sx2 - sx * sx); + private void PortSelected(object sender, EventArgs e) + { + port.Close(); + string selected = this.ComboPortBox.GetItemText(this.ComboPortBox.SelectedItem); + port.PortName = selected; + // port.Open(); + } - bCursorL.Text = string.Format("{0:F0} uH", L1 * 1000); - bCursorL2.Text = string.Format("{0:F0} uH", L2 * 1000); + private void NumberOfMesChanged(object sender, EventArgs e) + { + if (points_per_mes * Convert.ToUInt16(TextBoxMesRepeat.Text) > 0xFFE) + { + number_of_mes = (uint)Math.Floor(0xFFF / (double)points_per_mes); + TextBoxMesRepeat.Text = number_of_mes.ToString(); + } + else + number_of_mes = Convert.ToUInt16(TextBoxMesRepeat.Text); + } + + private void NumberOfSamplesChanged(object sender, EventArgs e) + { + if (number_of_mes * Convert.ToUInt32(TextBoxMesPoints.Text) > 0xFFE) + { + points_per_mes = (uint)Math.Floor(0xFFF / (double)number_of_mes); + TextBoxMesPoints.Text = points_per_mes.ToString(); + } + else + points_per_mes = Convert.ToUInt32(TextBoxMesPoints.Text); + } + + private void Button3_Click(object sender, EventArgs e) + { + id_of_mes = 0; } } } diff --git a/sw/InductorTester/InductorTester.csproj b/sw/InductorTester/InductorTester.csproj index f5e0578..1460db5 100644 --- a/sw/InductorTester/InductorTester.csproj +++ b/sw/InductorTester/InductorTester.csproj @@ -9,8 +9,9 @@ Properties InductorTester InductorTester - v4.5 + v4.0 512 + AnyCPU diff --git a/sw/InductorTester/Properties/Resources.Designer.cs b/sw/InductorTester/Properties/Resources.Designer.cs index 8d3de19..7772f34 100644 --- a/sw/InductorTester/Properties/Resources.Designer.cs +++ b/sw/InductorTester/Properties/Resources.Designer.cs @@ -1,7 +1,7 @@ //------------------------------------------------------------------------------ // // This code was generated by a tool. -// Runtime Version:4.0.30319.17929 +// Runtime Version:4.0.30319.1 // // Changes to this file may cause incorrect behavior and will be lost if // the code is regenerated. diff --git a/sw/InductorTester/Properties/Settings.Designer.cs b/sw/InductorTester/Properties/Settings.Designer.cs index 34077a9..9a60e49 100644 --- a/sw/InductorTester/Properties/Settings.Designer.cs +++ b/sw/InductorTester/Properties/Settings.Designer.cs @@ -1,7 +1,7 @@ //------------------------------------------------------------------------------ // // This code was generated by a tool. -// Runtime Version:4.0.30319.17929 +// Runtime Version:4.0.30319.1 // // Changes to this file may cause incorrect behavior and will be lost if // the code is regenerated. @@ -12,7 +12,7 @@ namespace InductorTester.Properties { [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()] - [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.VisualStudio.Editors.SettingsDesigner.SettingsSingleFileGenerator", "11.0.0.0")] + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.VisualStudio.Editors.SettingsDesigner.SettingsSingleFileGenerator", "10.0.0.0")] internal sealed partial class Settings : global::System.Configuration.ApplicationSettingsBase { private static Settings defaultInstance = ((Settings)(global::System.Configuration.ApplicationSettingsBase.Synchronized(new Settings())));