dor8
Junior Member level 1
I use PWM port that connection to DIGITAL input and from digital input (with interrupt-B5) I take another digital output controller (C0), it's because I need to switch fourth transistors and this technique should work for me.
(Attached picture of the connection)
in duty Cycle I see that I flip between the PWM and digital port (it's like I want to), but I do not know why frequency is not the same- 50KHZ.
in attached Picture we see that in Yellow I get the frequency I want (50KHZ ) and in blue I gut a completely different frequency (4 KHZ) - I want them to be the same frequency, how can I do it?
Also attached to the code
(Attached picture of the connection)
in duty Cycle I see that I flip between the PWM and digital port (it's like I want to), but I do not know why frequency is not the same- 50KHZ.
in attached Picture we see that in Yellow I get the frequency I want (50KHZ ) and in blue I gut a completely different frequency (4 KHZ) - I want them to be the same frequency, how can I do it?
Also attached to the code
Code:
/* Main.c file generated by New Project wizard
*[B] Processor: PIC16F886[/B]
[B]* Compiler: HI-TECH C for PIC10/12/16[/B]
*/
#include <htc.h>
void interrupt IOC_ISR(void)
{
if (RB5==1)
{
RC0=0; //duyt cycle of 0.65
}
else
{
RC0=1;
}
RBIF=0;
}
void main()
{
TRISC = 0 ; // set PORTC as output
TRISB=0b11111111;
PORTC = 0 ; // clear PORTC
ANSEL=0;
ANSELH=0;
OSCCON = 0b01100101; //int oscilator- 4Mhz
PR2 = 0b00000100 ; // 50KHZ freq
T2CON = 0b00000101 ; //50KHZ freq
CCPR1L = 0b00000001 ; //duyt cycle of 0.35
CCP1CON = 0b00111100 ; //duyt cycle of 0.35
GIE= 1;
RBIE=1; // eneble port b
RBIF=0;
IOCB=0b00110000; // INTERRUPT ON CHANGE REGISTER
while (1){
RB5=CCPR1;
}
}