Continue to Site

Welcome to our site!

Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

  • Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

Strange Problem Encountered Using MicroChip MPLAB IDE C Compiler

Status
Not open for further replies.
I just looked at the chip your using, check the function of bit 6&7 of CCP1CON. In fact, I think you can set the chip up so that CCP1 output is inverted - see page 147 of the data sheet.

Mike.
 
Oh, you get the correct result, but not the wanted result :)
You want the waveform to be inverted, but not the duty cycle to be complemented.
You cannot use this: PORTB = ~CCP1 because the result on PORTB is parallel. The easiest way is to use a hardware inverter at the output of CCP1.

Or, is the program running anything else? If not then you can update the duty cycle of CCP1 in the timer 2 ISR. In the main, poll RC2 (CCP1) and invert this pin to any output pin. Or anyone has better solution?

I'm using the chip to do other things so I think external circuitry is better. Haha
 
I just looked at the chip your using, check the function of bit 6&7 of CCP1CON. In fact, I think you can set the chip up so that CCP1 output is inverted - see page 147 of the data sheet.

Mike.

Hi Pommie,

Haha.. U are waiting for me to describe what i wanted to achieved? Haha... By the way, I seem page 147 of the data sheet. I will set the bits and see whether I can achieve the inverting part. Update again. :)

Another thing, can PIC do deadtime timing delay? :D
 
I just looked at the chip your using, check the function of bit 6&7 of CCP1CON. In fact, I think you can set the chip up so that CCP1 output is inverted - see page 147 of the data sheet.

Mike.

Hohoho... Thanks Pommie for guiding me to the datasheet.

I can now do the inverting of the signal already.

I only make the changes on CCP1CON bits 0&1.

CCP1CON = 0b00001111; // Active Low
CCP2CON = 0b00001100; // Active High

Where my PWM become

CCP1 = 0011 1100 &
CCP2 = 1100 0011

As mentions earlier, CCP1CON bits 6&7 don't seem to have effect on my PWM signal as I tried to put it both to '1' and '0'. The output remain the same.
 
Hi All,

I have one more issue that I'm figuring out but I don't know whether i'm write or wrong. Please Advise.

The issue is as follows:

The code that I posted in this forum was doing a forever while loop. I understand that this approach was called "polling". There should be 1 more approach by using the Interrupt which I'm very lost at it.

I would like to have a timer that can count (say 1uS), than after every 1uS, it will call the interrupt to execute some task. Please advise me if the following code is wrong.

Code:
#include <P18F4520.h>
#include <timers.h>

#pragma interrupt interrupt_1

void interrupt_1 (void);

void main(void)
{	
	OpenTimer0( TIMER_INT_OFF & T0_8BIT & T0_SOURCE_INT & T0_PS_1_256 );
	if (INTCONbits.TMR0IF=1)
		interrupt_1();		
}

void interrupt_1(void)
{
	// Interrupt Code - For example like reading analog input
}
 
Oopz.. Seem like no1 can comment about how to trigger the interrupt by using a timer ?

Wondering is my approach is correct or wrong...

I have missed out something on the previous part of the code. The following is the new code that I have add in.

Code:
#include <P18F4520.h>
#include <timers.h>

#pragma interrupt interrupt_1

void interrupt_1 (void);

void main(void)
{	
	OpenTimer0( TIMER_INT_OFF & T0_8BIT & T0_SOURCE_INT & T0_PS_1_256 );
	if (INTCONbits.TMR0IF=1)
		interrupt_1();		
}

void interrupt_1(void)
{
	INTCONbits.TMR0IF = 0;
	// Interrupt Code - For example like reading analog input
}
 
If you have a look at this thread, about a dozen posts down I posted some code showing how to setup the interrupt vector and routine. From this you should be able to work out how to do your interrupt.

BTW, a 1μS interrupt is very fast. Are you sure you don't mean 1mS?

Mike.
 
If you have a look at this thread, about a dozen posts down I posted some code showing how to setup the interrupt vector and routine. From this you should be able to work out how to do your interrupt.

BTW, a 1μS interrupt is very fast. Are you sure you don't mean 1mS?

Mike.

Thanks Pommie... I have set up my interrupt and it working now already. The thing that i missed out in my interrupt is the setting of interrupt vector right. :)...
 
Status
Not open for further replies.

New Articles From Microcontroller Tips

Back
Top