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.

[SOLVED] PIC16F877A odd outputs?

Status
Not open for further replies.

Dale Gregg

Junior Member level 3
Junior Member level 3
Joined
Jul 23, 2013
Messages
29
Helped
2
Reputation
4
Reaction score
2
Trophy points
3
Location
Leeds, United Kingdom
Visit site
Activity points
263
Hi,

I was hoping someone might be able to help me. My problem is with a SPWM controller using a PIC. The PWM signal outputs from CCP1 (A0 on the logic analyser LA), that's working fine. The logic circuit, the two AND and NOT gates are also working as they should (A1 and A2 on LA, A2 been the inverse of A1).

Logic_ANA.PNG

RD0 is coded to change state every half cycle, thats after the last PWM duty cycle in the sequence, the counter for this is "a" and "div" is the number of duty cycles (39).

Logic_ANA_readout.PNG

A1/A2 should change state every half cycle (when the pulses on A0 get small) but instead A1 stays Hi for a while dips low for a much shorter time then comes back up, fairly regular but completely out of sync(they should be hi and low equal amounts of time). The next pics zoomed out,

Logic_ANA_readout2.PNG

This is the interrupt section of the code where the output toggles,

void interrupt() //Interrupt Function
{
/*
*/
if(TMR2IF_bit==1) //At PWM period end
{
if(a>=di) //when counter reaches end of string
{

if(RD0_bit==1) //Toggle H bridge switches
{
RD0_bit = 0;
}
else
{
RD0_bit = 1;
}
a=0; //reset counter
}
else
{
dctrans=a; //converts int to char
CCPR1L = sinedc[dctrans]; //Loads values from sine char string
//to DC
a++; //increment counter
TMR2IF_bit = 0; //TMR2IF reset
}
}
}


I can't find any fault in the code, I've used the debugger step by step and found nothing out of place. Could it be because the toggle code is in the interrupt?

Regards,

Dale
 

Just a guess, but have you declared the variables which are altered in the interrupt routine as 'volatile'? Also, use CODE tags when posting code.

Keith
 

Hi, thanks for your reply,

It was something much simpler. A redundant part of the code I'd forgotten to comment out was still using the bit,

Regards

Dale
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top