Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

[PIC] How I can generate pulses ?

Status
Not open for further replies.

Stas Mamaischi

Newbie level 6
Joined
Apr 24, 2014
Messages
11
Helped
0
Reputation
0
Reaction score
0
Trophy points
1
Activity points
60
I am a beginner in programming and microcontrollers but I would like to generate pulses with pic 16f886 to 310-630 rpm in the period 0.2 second. Can help me ? . Thank you forward.
 

In the PIC16f886 microcontroller datasheet there will be a section that covers PWM (the CCP) section. It will tell you have to setup the control registers, set your PWM frequency (what you call RPM), and your duty cycle. It has all the formulas and everything in there. Basically it is just setting some registers and setting your timer scalar correctly.
 

i calculate : rpm in frequency : 310/60=~5 hz ; 630/60=10.5=~11hz
t=0.2 sec => freq=5
Code:
#define _XTAL_FREQ   5000000  


// Main function
void main(void)
{
		TRISC2  = 0;            // Make CCP1 pin as output
	CCP1CON = 0x0C;         // Configure CCP1 module in PWM mode

	PR2   = 0xFF;           
	T2CON = 0x01;           // 

	SetPWMDutyCycle(0);     

	T2CON |= 0x04;          
}


void PWMDuty(unsigned int DutyCycle)  
{
	CCPR1L   = DutyCycle>>2;        	 
	CCP1CON &= 0xCF;                	
	CCP1CON |= (0x30&(DutyCycle<<4));   
}	

	PWMDuty(512);   //50% duty cycle

	while(1)
	{
		
	}
}

Think correctly?
But time=0,2 second , how to make? with function if and some variable count in while?
 

In the PIC16f886 microcontroller datasheet there will be a section that covers PWM (the CCP) section. It will tell you have to setup the control registers, set your PWM frequency (what you call RPM), and your duty cycle. It has all the formulas and everything in there. Basically it is just setting some registers and setting your timer scalar correctly.


Code:
#define _XTAL_FREQ   5000000  


// Main function
void main(void)
{
		TRISC2  = 0;            // Make CCP1 pin as output
	CCP1CON = 0x0C;         // Configure CCP1 module in PWM mode

	PR2   = 0xFF;           
	T2CON = 0x01;           // 

	SetPWMDutyCycle(0);     

	T2CON |= 0x04;          
}


void PWMDuty(unsigned int DutyCycle)  
{
	CCPR1L   = DutyCycle>>2;        	 
	CCP1CON &= 0xCF;                	
	CCP1CON |= (0x30&(DutyCycle<<4));   
}	

	PWMDuty(512);   //50% duty cycle

	while(1)
	{
		
	}
}
 

Status
Not open for further replies.

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top