SEARCH
TOOLBOX
LANGUAGES
Register    Login    Forum    Search    FAQ

Board index » Electronics Projects » PIC18F USB development




Post new topic Reply to topic  [ 4 posts ] 
Author Message
 Post subject: How to stop a loop via USB
 Post Posted: Wed Apr 25, 2012 2:56 pm 
Offline

Joined: Wed Apr 25, 2012 2:47 pm
Posts: 2
Hi,
I am using hid simple custom demo that provided by microchip, for my device. In one of cases (case 0x82:) in the ProcessIO function, I am starting a loop that take a long time to be completed. And in some cases I want to break this loop by a commond from PC. how can I do this? the code is below and I want to break it anywhere in this case:
Code:
   case 0x82:   
               {               
            
            
               dackontrol1 = 1;
               dackontrol2 = 1;
               dacch2=0x0000;
               databuffersayisi = 0x00;
               xindex=0x0000;
               yindex=0x0000;
               dacnum2= 0x0000;
               dacnum1=0x0000;
               //spi yaz
               /*verial();            // dds value can be ready to scan;
               deger=ilkdeger;
               converter();   
               spiyaz(); */
               // adc oncesi veriyi yaz
               //ilk durum icin indexler
               ToSendDataBuffer[10]= xindex;
               ToSendDataBuffer[11]= yindex;
            
                adc2reg=32;
               adimsayma=0;
               verisayma=0;
               xdac=0x00;
               ydac=0x00;
               ysayac=0x00;
               while(ydac<0xfff& ReceivedDataBuffer[5]==0x0F)//tarama
               {
                     //bir dac okuması+adımsayacı bir artır
                     
                  
                  
                     while(xdac<0xfff& ReceivedDataBuffer[5]==0x0F)
                     {
                        if(xdac==0)
                        {
                        adc2();
                        adc2reg=adc2reg+2;
                        
                        }
                        adimsayma=adimsayma+1;// bu ifin içine alınmalı
                        xdac++;
                        dac1(xdac);
                        gecikme(ReceivedDataBuffer[25]);
                        if(adimsayma==16)
                        {                           
                        
                           adc2();
                           adc2reg=adc2reg+2;
                           verisayma=verisayma+1;
                           if(verisayma==16)
                           {
                              USBInHandle = HIDTxPacket(HID_EP,(BYTE*)&ToSendDataBuffer[0],64); //verigonder
                        
                              verisayma=0;
                           adc2reg=32;
                           }
                           adimsayma=0;
                           
                        }
                     }   
                  
                     while(xdac>0x00& ReceivedDataBuffer[5]==0x0F)
                     {
                        if(xdac==4095)
                        {
                        adc2();
                        adc2reg=adc2reg+2;
                        
                        }
                     adimsayma=adimsayma+1;//bu ifin içine alınmalı
                     xdac=xdac-1;
                     dac1(xdac);
                     gecikme(ReceivedDataBuffer[25]);
                     if(adimsayma==16)
                     {
                        adc2();
                        adc2reg=adc2reg+2;
                        verisayma=verisayma+1;
                        if(verisayma==16)
                        {
                           USBInHandle = HIDTxPacket(HID_EP,(BYTE*)&ToSendDataBuffer[0],64); //verigonder
                           
                           verisayma=0;
                           adc2reg=32;
                        }
                        adimsayma=0;
                        
                     }
                     }
                     while(ysayac<16)//ysayac<17 bunu ysayac<16 olarak değiştirdim
                     {
                     ydac=ydac+1;
                     ysayac=ysayac+1;
                     dac2(ydac);
                     
                     gecikme(ReceivedDataBuffer[25]);
                     }
                     ysayac=0x00;
                     }
                     while(ydac>0x00)
               {
               ydac=ydac-1;
               dac2(ydac);
               gecikme(ReceivedDataBuffer[25]);
               }
            }
            break;


Top 
 Profile  
 
 Post subject: Re: How to stop a loop via USB
 Post Posted: Thu Apr 26, 2012 12:26 am 
Offline

Joined: Thu Sep 22, 2011 2:35 am
Posts: 78
Location: Carlisle England
I would put a timeout at the PIC end.


Top 
 Profile  
 
 Post subject: Re: How to stop a loop via USB
 Post Posted: Thu Apr 26, 2012 4:11 am 
Offline

Joined: Thu Apr 01, 2010 6:23 am
Posts: 893
You could place your code into an interrupt and use a command from the host to activate the interrupt and stop the interrupt. You can't hold the device in a loop without polling the USB functions as the host will disconnect the device after a very short time.


Top 
 Profile  
 
 Post subject: Re: How to stop a loop via USB
 Post Posted: Thu Apr 26, 2012 9:11 am 
Offline

Joined: Wed Apr 25, 2012 2:47 pm
Posts: 2
hi Simon and nigelwright7557 thank you for your replies. I am a pyhsicist and I am not too much experienced in c18 programing. I need this codes for my experiment. I can not do this job with your hints. Do you have any sample codes or can't you show me more detailed way?


Top 
 Profile  
 
Display posts from previous:  Sort by  
 
Post new topic Reply to topic  [ 4 posts ] 

Board index » Electronics Projects » PIC18F USB development


Who is online

Users browsing this forum: No registered users and 2 guests

 
 

 
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 post attachments in this forum

Search for:
Jump to:  
cron
Translated by Maël Soucaze © 2009 phpBB.fr