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

PIC 12F629 RC-electronic speed controller

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



Joined: 31 Jan 2009
Posts: 59

View user's profile Send private message

PIC 12F629 RC-electronic speed controller
PostPosted: Thu Aug 06, 2009 9:16 am     Reply with quote

I have a ppm signal from a RC receiver.
1 ms up full bw.
1.5 ms up neutral.
2 ms up full fw.
20 ms down.

My code is:
Code:

#include "C:\Documents and Settings\Noyz2k\My Documents\rc car\acc.h"
int i,b,c;
unsigned int t;

#define preload 65458
#define red pin_A2

//*********************************************************
//Global variables
//*********************************************************

int red_duty;
int Intcount;

//*********************************************************
//100Hz pwm (interrupt at 25.8kHz
//*********************************************************

#INT_TIMER1
void timer_irq()
{
    set_timer1(preload);
   
   if (Intcount < 255)
    {
      if (Intcount == red_duty)
       {
         output_low(red);
       }
    }
   
   else if(Intcount == 255)
    {
      Intcount = 0;
      if (red_duty==0) output_low(red); else
      output_high(red);
    }   
    Intcount++;
}


//**********************************************************
// Main Program
//**********************************************************
void main()
{
    setup_timer_0(RTCC_INTERNAL|RTCC_DIV_8);
    setup_timer_1(T1_INTERNAL | T1_DIV_BY_1);
    enable_interrupts(INT_TIMER1);
    enable_interrupts(GLOBAL);
   //red_duty = 126;
   Intcount = 0;
//printf("start");
while (TRUE)
   {
      c=0;
   if (input(PIN_A1)) while (input(PIN_A1));
   while(!input(PIN_A1));
   set_timer0(0);
   while ((input(PIN_A1))) { if (c==0) {if (get_timer0()==126) {set_timer0(0);c++;}};};
   t=c*126+get_timer0()-128 -c*2;
   //printf("%u\r\n",t);
   if (t>63) {b=t-63;
              // blue_duty=0;
               output_low(PIN_A4);
               if (b>=63) red_duty=255; else {red_duty=4*b;}
               }
   if (t<63) {b=63-t;
              // blue_duty=0;
              output_high(PIN_A4);
               if (b>=63) red_duty=255; else {red_duty=4*b;}
               }
  if ((t>=62)&&(t<=64)) red_duty=0;
   //63 middle
   // 126 max
   // 0 min
   
   }
}

The thing is that without that pwm, it works just fine : t=0 full bkw, t = 63 neutral, t=126 full fw.
When I use the sf pwm using interrupt t isn't the same because of the breaks, if I try to use rs232 to print the values again I get ascii unreadable code.
My question is how do I get to know the new val?
Guest








PostPosted: Thu Aug 06, 2009 12:19 pm     Reply with quote

Hi,

Maybe it's just me, but I find your 'C' writing style to be almost totally unreadable Shocked ! Sure, it's probably compilable, but it's really tough to follow the flow. I just gave up, and I suspect I won't be alone....

Doug
noyz



Joined: 31 Jan 2009
Posts: 59

View user's profile Send private message

PostPosted: Thu Aug 06, 2009 7:22 pm     Reply with quote

The thing is that I get in t a value from 0 to 126 1ms to 2ms signal.
The t is counted for a full time minus a 1ms that is always there.
I don't know how to explain exactly.
The pwm part I took it from the internet and seem to work fine by setting red_duty=val;
and there is a translation from 0 to 63 into 255 down to 0 for backw and 63 to 126 into 0 to 255 for fw.
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