Just edit in the interruptHi engshahrul,
The Example Servo program was useful,But there it was discussed with single servomotor only Please give me a solution to control multi servomotors simultaneously with different position angle,I'm Waiting for your valuable reply,Thank You
if(TMR0IF==1){
TMR0IF=0;
counter++;
if(counter==position1) SERVO1=0;
if(counter==position2) SERVO2=0;
if(counter==position3) SERVO3=0;
if(counter==position4) SERVO4=0;
if(counter==390){
counter=0;
SERVO1=1;
SERVO1=2;
SERVO1=3;
SERVO1=4;}
}
You check the PIC16F887 datasheet and you will know the function address ADCON0, ADCON1, ANSEL, ANSELHHi,
Can You Please explain the folloe=wing Block in the servo example code,
int read_a2d(unsigned char channel)
{
ADCON0=0b00000001; //Turn on A/D module
ADCON1=0b10000000; //Right Justify
if(channel<=7) ANSEL=ANSEL|(0b00000001<<channel);
else ANSELH=ANSELH|(0b00000001<<(channel-8));
__delay_ms(2);
GO=1; //initiate conversion on the selected channel
while(GO==1) continue; //wait until conversion done
return(256*ADRESH+ADRESL);
That range to get signal for servo about 0.5ms - 2.5msAnd Also this line,
position=(int)(0.9775*(max-min)*read_a2d(0)/1000+min);
How the Position is calculated here.
Because in my project Initially I want to check only the simultanious servo running thatsy.
Thank You in Advance.
#include<pic.h>
#include<htc.h>
__CONFIG(FOSC_HS & //External Crystal at High Speed
WDTE_OFF & //Disable Watchdog Timer
PWRTE_ON & //Enable Power Up Timer
BOREN_OFF & //Disable Brown Out Reset
/*MCLRE_ON &*/ //MCLR function is enabled
LVP_OFF); //Disable Low Voltage Programming
#define SERVO1 RB1
#define SERVO2 RB2
#define SERVO3 RB3
#define SERVO4 RB4
#define _XTAL_FREQ 16000000
#define min 10
#define max 50
void pic_init(void);
int read_a2d(unsigned char channel);
int counter,position1=28,position3=12,position4=24;
int position2=36,x;
static void interrupt isr(void)
{
if(TMR0IF==1)
{
TMR0IF=0;
counter++;
if(counter==position1)
SERVO1=0;
if(counter==position2)
SERVO2=0;
if(counter==position3)
SERVO3=0;
if(counter==position4)
SERVO4=0;
if(counter==390)
{
counter=0;
SERVO1=1;
SERVO2=1;
SERVO3=1;
SERVO4=1;
}
}
}
main()
{
pic_init(); //initialize PIC
for(;;)
{
position1=36; //36->+90deg,12->-90deg,24->Neutral
}
}
void pic_init(void)
{
TRISB=0b00000000;
TRISD=0b00000000;
OPTION_REG=0b00001000; //Internal instruction clock
PORTB=0b00000000;
INTCON=0b10100000; //Enable Global, TMR0 Interrupt
PIE1=0b00000000; //Disable TMR1, TMR2 Interrupt
PIE2=0b00000000;
}
See this servo using Timer Interrupt or using Servo Controller.Hi Friends,Any one please help me I want to control my 11 servomotors with slow motion using the timer intruupt.Im using PIC 16f877A with 4Mhz clock and hitec c compilr.Its very urget.Thanks in advance.
We use cookies and similar technologies for the following purposes:
Do you accept cookies and these technologies?
We use cookies and similar technologies for the following purposes:
Do you accept cookies and these technologies?