CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to CCS Technical Support

Problem with HID and Analog

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
Markdem



Joined: 24 Jun 2005
Posts: 206

View user's profile Send private message Send e-mail

Problem with HID and Analog
PostPosted: Sat Jun 06, 2009 4:26 am     Reply with quote

HI All, I am trying to make a simple flight yoke. I have the following code

Code:

#include <18F4550.h>
#fuses HSPLL,NOWDT,NOPROTECT,NOLVP,NODEBUG,USBDIV,PLL5,CPUDIV1,VREGEN
#use delay(clock=48000000)
   
#DEFINE USB_HID_DEVICE  TRUE

//the following defines needed for the CCS USB PIC driver to enable the TX endpoint 1
// and allocate buffer space on the peripheral
#define USB_EP1_TX_ENABLE  USB_ENABLE_INTERRUPT   //turn on EP1 for IN bulk/interrupt transfers
#define USB_EP1_TX_SIZE    8  //allocate 8 bytes in the hardware for transmission

//the following defines needed for the CCS USB PIC driver to enable the RX endpoint 1
// and allocate buffer space on the peripheral
#define USB_EP1_RX_ENABLE  USB_ENABLE_INTERRUPT   //turn on EP1 for OUT bulk/interrupt transfers
#define USB_EP1_RX_SIZE    8  //allocate 8 bytes in the hardware for reception

#define USB_CON_SENSE_PIN    PIN_E1
#DEFINE LED               PIN_E2

#define ADC_DELAY         20

#include <pic18_usb.h>
#include "usb_desc_yoke.h"
#include <usb.c>

int out_data[50];
int in_data[2];

signed int Rudder;               //out_data[0]
signed int X;                  //out_data[1]
signed int Y;                  //out_data[2]
int Hat_Buttons;               //out_data[3]
int Buttons;                  //out_data[4]

int i;

void main()
   {
      setup_adc_ports(AN0_TO_AN2);
      setup_adc(ADC_CLOCK_DIV_64);

         usb_init_cs();
   
      set_adc_channel(0);
      delay_us(ADC_DELAY);

        while (TRUE)
         {
              usb_task();


            out_data[0] = read_adc();

              if (usb_enumerated())
               {
                  out_data[0]=-111;
                  out_data[1]=-100;
                  out_data[2]=100;
                  out_data[3]=0b01101110;
                  out_data[4]=0b00111011;

                     usb_put_packet(1, out_data, 5, USB_DTS_TOGGLE);
                  }

            delay_ms(500);
            output_high(LED);
            delay_ms(500);
            output_low(LED);
         }
   }




Now, when I comment out the read_adc() line, everything works 100%. With the read_adc() line included, the PIC will stop running (the LED stops blinking) after 30-60 seconds. This will happen both when the USB plug is in and out. I just don't get it. I am not even using the adc reading to send to the PC.

I know that the PIC can be very fussy about the voltage on the VUSB pin. Could it be that somehow, when I read the adc value, the voltage on that pin is going below what the PIC needs? I don't have a scope, so I can't check this.

Thanks

Mark
Rocket



Joined: 29 Aug 2005
Posts: 27

View user's profile Send private message

PostPosted: Wed Jun 10, 2009 6:49 am     Reply with quote

Hi Markdem, there is a project which probably has what you want.
http://alessioandrea.altervista.org/rcjoyng2.html
The source is available.
If you get it translated to CCS, please forward me a copy.

Kind Regards.
_________________
J.I.L.
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group