+ Post New Thread
Page 1 of 2 1 2 LastLast
Results 1 to 20 of 24
  1. #1
    Banned
    Points: 333, Level: 3

    Join Date
    Jul 2014
    Posts
    62
    Helped
    0 / 0
    Points
    333
    Level
    3

    A Little Help with Coding AT90USB

    I want to send real-time data(ADC) to my PC with AT90USB646. I've used Codevision Wizard but it failed some times.anyOne can help me with the coding? and I used LabView to get results and that was terrible if you can suggest a better softwer ill appreciate it,

    regards

  2. #2
    Full Member level 5
    Points: 1,653, Level: 9
    udayan92's Avatar
    Join Date
    Mar 2014
    Location
    India
    Posts
    284
    Helped
    38 / 38
    Points
    1,653
    Level
    9

    Re: A Little Help with Coding AT90USB

    Did you use LabView for simulating the connection between PC and AT90USB646?
    Hint :Data communication between microcontroller and PC is possible.You need to have either a USB or a Ethernet cable with
    RJ-45 type connector on both the sides,for transmitting and receiving data.


    1 members found this post helpful.

  3. #3
    Banned
    Points: 333, Level: 3

    Join Date
    Jul 2014
    Posts
    62
    Helped
    0 / 0
    Points
    333
    Level
    3

    Re: A Little Help with Coding AT90USB

    Quote Originally Posted by udayan92 View Post
    Did you use LabView for simulating the connection between PC and AT90USB646?
    Hint :Data communication between microcontroller and PC is possible.You need to have either a USB or a Ethernet cable with
    RJ-45 type connector on both the sides,for transmitting and receiving data.
    can you help me with the code?how should I do it? I want real time data with no errors



  4. #4
    Banned
    Points: 333, Level: 3

    Join Date
    Jul 2014
    Posts
    62
    Helped
    0 / 0
    Points
    333
    Level
    3

    help with coding to send data to USB PC port

    I used this code but I need a little help to improve it. Help me if you can please I really need it :(

    Code:
    /*******************************************************
    This program was created by the
    CodeWizardAVR V3.12 Advanced
    Automatic Program Generator
    © Copyright 1998-2014 Pavel Haiduc, HP InfoTech s.r.l.
    http://www.hpinfotech.com
    
    Project : ESG
    Version : 1
    Date    : 11/19/2014
    Author  : Farad
    Company : 
    Comments: 
    
    
    Chip type               : AT90USB646
    Program type            : Application
    AVR Core Clock frequency: 16.000000 MHz
    Memory model            : Small
    External RAM size       : 0
    Data Stack size         : 1024
    *******************************************************/
    
    #include <90usb646.h>
    
    #include 
    
    // USB Device functions
    #include 
    
    // USB CDC Virtual Serial Port functions
    #include 
    
    // USB initialization
    #include "usb_init.h"
    
    // Declare your global variables here
    
    // Standard Input/Output functions
    #include 
    
    // Voltage Reference: AREF pin
    #define ADC_VREF_TYPE ((0<
    



    •   AltAdvertisment

        
       

  5. #5
    Member level 1
    Points: 294, Level: 3

    Join Date
    Nov 2014
    Posts
    37
    Helped
    4 / 4
    Points
    294
    Level
    3

    Re: help with coding to send data to USB PC port

    please, would you like to precise what's used for and what's not working.

    mention any reference if you can.



  6. #6
    Banned
    Points: 333, Level: 3

    Join Date
    Jul 2014
    Posts
    62
    Helped
    0 / 0
    Points
    333
    Level
    3

    Advice in ADC AT90USB series

    Hi
    if I want to get real-time data which mode should i choose? with interupt?

    shoudl I write
    Code:
    read_adc=x; putchar(x);
    codevision



    •   AltAdvertisment

        
       

  7. #7
    Super Moderator
    Points: 251,535, Level: 100
    Awards:
    1st Helpful Member

    Join Date
    Jan 2008
    Location
    Bochum, Germany
    Posts
    43,802
    Helped
    13318 / 13318
    Points
    251,535
    Level
    100

    Re: A Little Help with Coding AT90USB

    Code:
    read_adc=x; putchar(x);
    Meaned this?
    Code:
    x=read_adc();putchar(x);
    AVR ADC outputs 10-Bit data, so the code isn't particularly useful. And you want to write the data to USB rather than UART, where is the data sent by putchar()?

    If you send binary data over USB through virtual COM port protocol, you usually want some kind of data framing or print it to ASCII format. O.K., single channel 8-bit ADC data can send without framing if this is sufficient for your application.

    In post #4, you copied an USB virtual COM port device template, but the most interesting block stayed empty
    Code:
    // Place your code here
    There's no user code yet. I'm pretty sure that Atmel has a lot of working USB code examples that can give you an idea which code should be placed.


    1 members found this post helpful.

    •   AltAdvertisment

        
       

  8. #8
    Banned
    Points: 333, Level: 3

    Join Date
    Jul 2014
    Posts
    62
    Helped
    0 / 0
    Points
    333
    Level
    3

    Re: A Little Help with Coding AT90USB

    Quote Originally Posted by FvM View Post
    Code:
    read_adc=x; putchar(x);
    Meaned this?
    Code:
    x=read_adc();putchar(x);
    AVR ADC outputs 10-Bit data, so the code isn't particularly useful. And you want to write the data to USB rather than UART, where is the data sent by putchar()?

    If you send binary data over USB through virtual COM port protocol, you usually want some kind of data framing or print it to ASCII format. O.K., single channel 8-bit ADC data can send without framing if this is sufficient for your application.

    In post #4, you copied an USB virtual COM port device template, but the most interesting block stayed empty
    Code:
    // Place your code here
    There's no user code yet. I'm pretty sure that Atmel has a lot of working USB code examples that can give you an idea which code should be placed.
    I used AT90USb646 ADC USART and USB activate but still sometimes there is a gap in ECK signal and then the micro will send them all to together

    - - - Updated - - -

    thank you so much.im hoping for a solotuion for
    Code:
    // Place your code here
    part.

    regards.



  9. #9
    Banned
    Points: 12,436, Level: 26

    Join Date
    Apr 2013
    Posts
    2,528
    Helped
    538 / 538
    Points
    12,436
    Level
    26

    Re: A Little Help with Coding AT90USB

    http://www.hpinfotech.ro/cvavr_examples.html

    You have to use the below function in while(1) loop to send data out of USB.

    usb_serial_putchar(c);

    Code C - [expand]
    1
    2
    3
    4
    5
    6
    
    void usb_send_string(char *str) {
        
        while(*str) {
            usb_serial_putchar(*str++);
        }
    }

    Convert your adc value to string using sprintf() and then use strcat() to concatanate \r\n to the string and pass this string to the above function like shown below.


    usb_send_string(strADCVal);


    1 members found this post helpful.

  10. #10
    Banned
    Points: 333, Level: 3

    Join Date
    Jul 2014
    Posts
    62
    Helped
    0 / 0
    Points
    333
    Level
    3

    Re: A Little Help with Coding AT90USB

    I need int data(digital) real time no error char doesnt work well



  11. #11
    Banned
    Points: 12,436, Level: 26

    Join Date
    Apr 2013
    Posts
    2,528
    Helped
    538 / 538
    Points
    12,436
    Level
    26

    Re: A Little Help with Coding AT90USB

    You want to send out data as integer ? Then if your adc value is integer type that is 16 bits and adc value is 10 bits then you have to send it as two bytes.

    Code C - [expand]
    1
    2
    3
    4
    5
    
    void usb_send_integer(unsigned int dat) {
          
            usb_serial_putchar(dat & 0xFF);
        usb_serial_putchar((dat & 0xFF00) >> 8);    
    }


    1 members found this post helpful.

  12. #12
    Super Moderator
    Points: 251,535, Level: 100
    Awards:
    1st Helpful Member

    Join Date
    Jan 2008
    Location
    Bochum, Germany
    Posts
    43,802
    Helped
    13318 / 13318
    Points
    251,535
    Level
    100

    Re: A Little Help with Coding AT90USB

    Virtual COM port is a stream of characters, so starting with two data bytes, you run into the "framing necessary" problem, otherwise there'a certain risk of losing lock with the word boundary, confusing high and low byte.

    But it's quite easy to use unique fill bits when splitting the 10 bit data.


    1 members found this post helpful.

  13. #13
    Banned
    Points: 333, Level: 3

    Join Date
    Jul 2014
    Posts
    62
    Helped
    0 / 0
    Points
    333
    Level
    3

    Re: A Little Help with Coding AT90USB

    Quote Originally Posted by FvM View Post
    Virtual COM port is a stream of characters, so starting with two data bytes, you run into the "framing necessary" problem, otherwise there'a certain risk of losing lock with the word boundary, confusing high and low byte.

    But it's quite easy to use unique fill bits when splitting the 10 bit data.
    so I need to use characters value...what about interrupt? should I use that?and what is baud rate for USB 2?



  14. #14
    Banned
    Points: 12,436, Level: 26

    Join Date
    Apr 2013
    Posts
    2,528
    Helped
    538 / 538
    Points
    12,436
    Level
    26

    Re: A Little Help with Coding AT90USB

    I don't now what transfer rate codevisionAVR USB CDC library uses. You refer to CodeVisionAVR Manual and also email your questions to CodeVisionAVR support team.

    Just try the given code and see if that works. You can worry about the transfer rate later.

    Why do you want to use interrupt ? Interrupts are usually used to receive data. You are only sending data.


    1 members found this post helpful.

  15. #15
    Banned
    Points: 333, Level: 3

    Join Date
    Jul 2014
    Posts
    62
    Helped
    0 / 0
    Points
    333
    Level
    3

    Re: A Little Help with Coding AT90USB

    Quote Originally Posted by milan.rajik View Post
    I don't now what transfer rate codevisionAVR USB CDC library uses. You refer to CodeVisionAVR Manual and also email your questions to CodeVisionAVR support team.

    Just try the given code and see if that works. You can worry about the transfer rate later.

    Why do you want to use interrupt ? Interrupts are usually used to receive data. You are only sending data.

    thank youuuu very much.I didnt know that.so I just need to activate ADC USART an USB then add the code
    Code:
    void usb_send_integer(unsigned int dat) {
          
            usb_serial_putchar(dat & 0xFF);
        usb_serial_putchar((dat & 0xFF00) >> 8);    
    }
    void usb_send_string(char *str) {
        
        while(*str) {
            usb_serial_putchar(*str++);
        }
    }
    dat=read_adc();
    putchar(dat);
    ]

    ?



  16. #16
    Banned
    Points: 12,436, Level: 26

    Join Date
    Apr 2013
    Posts
    2,528
    Helped
    538 / 538
    Points
    12,436
    Level
    26

    Re: A Little Help with Coding AT90USB

    Your dat is an unsigned integer which is 16 bits and contains 10 bit adc result. putchar() accepts char as argument. You can't pass dat to putchar. Use my usb_sent_integer() function to send two bytes of data. First low bute is send and then high byte.


    1 members found this post helpful.

  17. #17
    Banned
    Points: 333, Level: 3

    Join Date
    Jul 2014
    Posts
    62
    Helped
    0 / 0
    Points
    333
    Level
    3

    Re: A Little Help with Coding AT90USB

    Quote Originally Posted by milan.rajik View Post
    Your dat is an unsigned integer which is 16 bits and contains 10 bit adc result. putchar() accepts char as argument. You can't pass dat to putchar. Use my usb_sent_integer() function to send two bytes of data. First low bute is send and then high byte.
    so that is
    Code:
    void usb_send_integer(unsigned int dat) {
          dat=read_adc()
            usb_serial_putchar(dat & 0xFF);
        usb_serial_putchar((dat & 0xFF00) >> 8);    
    }
    void usb_send_string(char *str) {
        
        while(*str) {
            usb_serial_putchar(*str++);
        }
    }
    dat=read_adc();
    - - - Updated - - -

    or read_adc()=%c



  18. #18
    Banned
    Points: 12,436, Level: 26

    Join Date
    Apr 2013
    Posts
    2,528
    Helped
    538 / 538
    Points
    12,436
    Level
    26

    Re: A Little Help with Coding AT90USB

    You only need this function.

    Code C - [expand]
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    
    void usb_send_integer(unsigned int dat) {
          dat=read_adc()
            usb_serial_putchar(dat & 0xFF);
        usb_serial_putchar((dat & 0xFF00) >> 8);    
    }
     
    unsigned int dat = 0;
     
    dat = adc_read();
     
    usb_send_integer(dat);


    1 members found this post helpful.

    •   AltAdvertisment

        
       

  19. #19
    Banned
    Points: 333, Level: 3

    Join Date
    Jul 2014
    Posts
    62
    Helped
    0 / 0
    Points
    333
    Level
    3

    Re: A Little Help with Coding AT90USB

    or
    Code:
    dat=adc_data[]
    - - - Updated - - -

    Quote Originally Posted by milan.rajik View Post
    You only need this function.

    Code C - [expand]
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    
    void usb_send_integer(unsigned int dat) {
          dat=read_adc()
            usb_serial_putchar(dat & 0xFF);
        usb_serial_putchar((dat & 0xFF00) >> 8);    
    }
     
    unsigned int dat = 0;
     
    dat = adc_read();
     
    usb_send_integer(dat);
    I need 10 bit data can I use
    Code:
     usb_serial_putchar((dat & 0xFF00) >> 10);

    that helped so much thank you



  20. #20
    Banned
    Points: 12,436, Level: 26

    Join Date
    Apr 2013
    Posts
    2,528
    Helped
    538 / 538
    Points
    12,436
    Level
    26

    Re: A Little Help with Coding AT90USB

    You need both bytes and so you need both of these.

    Code C - [expand]
    1
    2
    
    usb_serial_putchar(dat & 0xFF);
    usb_serial_putchar((dat & 0xFF00) >> 8);

    The first is to extract and send low byte and the second is to extract and send high byte. The low byte contains 8 lower bits of dat and high byte contains the lower 2 bits of the high byte (dat)


    1 members found this post helpful.

--[[ ]]--