creating PWM using PIC

Status
Not open for further replies.
im not too good at programming , because that i ask on this forum

hi allbits
i dont understand what you are saying
i just need the asm/C file
 
Last edited:
hi allbits
i dont understand what you are saying
i just need the asm/C file

Just giving the asm file may not work, because I got no clue about your motor, and the delays will be definitely different.
 

I think I was pretty clear in my post. Going from -90° to +90° and back again is going 180° in each direction. Going (nearly) 270° in each direction requires a total movement of 270°, not 540°. Did you really not understand such a simple concept?

Mike.
 
Last edited:
Do you want a simple circuit that tests a servo? See Talking Electronics: "50 - 555 Circuits" for more details
**broken link removed**

**broken link removed**
 
Last edited:
Here you go, BoostC source code for a 16F886.
Code:
#include <system.h>

#pragma DATA _CONFIG, _DEBUG_ON & _MCLRE_ON
                    & _CP_OFF & _PWRTE_OFF
                    & _WDT_OFF & _INTOSCIO
                    & _LVP_OFF
#pragma CLOCK_FREQ 8000000

#define Servo portb.0
#define ServoTris trisb.0

void WaitInt();
unsigned int Position;
unsigned char PK2_reserved@0x70;
unsigned int ccp1 @CCPR1L;

void main(void){
    while(!osccon.HTS);
    osccon=0x71;                //8 meg
    ansel=0;
    anselh=0;
    adcon1=0x0f;
    ServoTris=0;                //make servo pin output
    Servo=0;                    //Servo output off
    ccp1con=0b00001011;         //Special event trigger
    t1con=0b10010001;           //Timer 1 on with Pre=2
    Position=1500;              //set servo to mid position
    pie1.CCP1IE=1;
    intcon.GIE=1;
    intcon.PEIE=1;
    while(1){
        while(Position<2000){
            WaitInt();
            Position+=10;
        }
        while(Position>1000){
            WaitInt();
            Position-=10;
        }

    }
}

void WaitInt(){
    while(Servo);       //wait for low
    while(!Servo);      //wait for high
}

void interrupt(void){
    if(Servo){
        Servo=0;
        ccp1=20000-Position;
    }else{
        Servo=1;
        ccp1=Position;
    }
    pir1.CCP1IF=0;
}
The above uses the internal oscillator and outputs the pulse on B0. It takes 2 seconds to go from one extreme to the other.

Mike.
 
Last edited:
hi thanks pommie
i want to try it but i loss my 16F886 while experimenting with my other pic
uh , i cant remember it
gotta need to find it !
 
Status
Not open for further replies.
Cookies are required to use this site. You must accept them to continue using the site. Learn more…