PICcoder.co.uk Forum  


::post new topic::
<< Start < Prev 1 2 Next > End >>
A bit confused
Date: 2006/04/02 03:46 By: streddy Status: User  
Karma: 0  
Posts: 7
graphgraph
Hello,
I am new to using USB microcontrollers . I have just gone through the 'Basic USB' article and have found it to be quite helpful in my project.

However I am a bit confused about the difference between the PIC code and the Application code. My project involves taking the information from the PIC18F4550 A/D converter and passing it to the PC via USB for storage in any type of file.

Do I need to write my code using MPLAB/C18 or C#Sharp or both?

Thanks
reply | quote

Re:A bit confused
Date: 2006/04/02 10:48 By: dariog Status: User  
Karma: 6  
Posts: 107
graphgraph
Hi, you'll need both,
PIC code goes on the PIC and performs the needed tasks to get A/D results, store them , and send them to the PC.
On the PC, you'll receive that data, in the format you specified on the PIC, via USB: and you'll need a VisualBasic, or C/C++/C# software to handle them (it's not as easy as opening a Serial Port).

Start out with an easy example!
reply | quote

Re:A bit confused
Date: 2006/04/02 21:56 By: streddy Status: User  
Karma: 0  
Posts: 7
graphgraph
Thanks for the response,

At this time I have set up code to get the data from the ADC into PORTB which is an I/O port that can be "software programmed for internal pull-ups" (according to the 4550 datasheet).

By editing the code provided in the this USB example article would I be able to read the contents of PORTB? For example, similar to the way that the Add button reads the sum of the two inputs on MCU - would I be able to set up a button that reads the contents of PORTB?

Is it not that simple?
Thank you,
reply | quote

Re:A bit confused
Date: 2006/04/03 12:47 By: dariog Status: User  
Karma: 6  
Posts: 107
graphgraph
sure, you can.
I haven't seen where exaclty , in the project, the PIC reads PORTB.
But you just have to setup ADC (which, incidentally, are usually on ports A and E), perform the conversion (OpenADC/SetChanADC/ConvertADC) and feed the result to the routine which talks to the USB.

You may create a packet which contains more than just one converted A/D value
reply | quote

Re:A bit confused
Date: 2006/04/04 17:37 By: streddy Status: User  
Karma: 0  
Posts: 7
graphgraph
My partner on this project developed this code for putting the results of the ADC in PORTA and PORTB (used a post from forum.microchip.com website). How does it look? From here the contents of PORTA and PORTB will be uploaded:

Code:

 void main(void)  {  while(1) { TRISA0xFF//tri-state buffer for Port A, all input  PORTA0x00//initialize 8 pins to low  TRISB0x00//tri-state buffer for Port B, all output  PORTB0x00//initialize 8 pins to low  //Setting up the A/D converter  OpenADC(ADC_FOSC_32 ADC_LEFT_JUST ADC_8ANA_0REFADC_CH0 ADC_INT_OFF);  SetChanADC(ADC_CH0);  ConvertADC(); //start conversion  while(BusyADC()); //wait for completion  PORTA ADRESH; PORTB ADRESL  CloseADC();  }  }

reply | quote

Re:A bit confused
Date: 2006/04/04 18:20 By: Mat Status: Admin  
Karma: 7  
Posts: 211
graphgraph
Looks almost there, but i have a few suggestions.

Why are you putting the output onto PORT A and B, you could just store it internally in the PIC and upload it?

Also you set PORTA to input and are trying to write the result to it? This shouldnt allow the pic to display the result on the port, if your intention was to display it externally.

Mat
reply | quote

Re:A bit confused
Date: 2006/04/04 21:25 By: streddy Status: User  
Karma: 0  
Posts: 7
graphgraph
Thanks for the suggestions.

When you say to store it internally in the PIC and upload it do you mean in the USB buffer RAM space? If so how is that done?

As for your second suggestion, it was a mistake on our part to set the output on PORTA after defining it as an input.

Please excuse my trivial questions...just trying to understand,
Thanks
reply | quote

Re:A bit confused
Date: 2006/04/04 21:34 By: Mat Status: Admin  
Karma: 7  
Posts: 211
graphgraph
Just define a variable and save it to that. Look throught he code and you will see lots of examples of how to create variables.

Mat
reply | quote

Re:A bit confused
Date: 2006/04/04 21:40 By: dariog Status: User  
Karma: 6  
Posts: 107
graphgraph
agreed on it all.
store it/them in the buffers used by HidTXBuffer (or eqv)
reply | quote

Re:A bit confused
Date: 2006/04/05 01:04 By: streddy Status: User  
Karma: 0  
Posts: 7
graphgraph
Something like this?:
Code:

 #include <p18f4550.h>  #include <stdio.h>  #include <stdlib.h>  #include <adc.h>  #include <delays.h>  byte LO_BYTE; byte HI_BYTE; void main(void) {     InitializeSystem();     while(1)     { TRISA0xFF//tri-state buffer for Port A, all input  PORTA0x00//initialize 8 pins to low  //Setting up the A/D converter  OpenADC(ADC_FOSC_32 ADC_LEFT_JUSTADC_CH0 ADC_INT_OFF);  SetChanADC(ADC_CH0);  ConvertADC(); //start conversion  while(BusyADC()); //wait for completion  HI_BYTE ADRESH; LO_BYTE ADRESL; CloseADC();      }//end while }//end main

reply | quote

Re:A bit confused
Date: 2006/04/05 09:24 By: Mat Status: Admin  
Karma: 7  
Posts: 211
graphgraph
Looks better I'd probably make a few changes,,,

Code:

   #include <p18f4550.h>  #include <stdio.h>  #include <stdlib.h>  #include <adc.h>  #include <delays.h>  byte LO_BYTE; byte HI_BYTE; void main(void) {     InitializeSystem(); //Setting up the A/D converter  OpenADC(ADC_FOSC_32 ADC_LEFT_JUSTADC_CH0 ADC_INT_OFF);  SetChanADC(ADC_CH0);  TRISA0xFF//tri-state buffer for Port A, all input  PORTA0x00//initialize 8 pins to low      while(1)     { ConvertADC(); //start conversion  while(BusyADC()); //wait for completion  HI_BYTE ADRESH; LO_BYTE ADRESL;     }//end while }



put the closeadc() on the loop exit if you ever need it. There is no point in resetting up the tris and ADC each loop as they will be set from the previous one, so I moved it outside the while. Mat
reply | quote

<< Start < Prev 1 2 Next > End >>
::post new topic::