CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to CCS Technical Support

Sync ADC Reading with PWM

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
dmccric



Joined: 07 Dec 2009
Posts: 7
Location: Bradford, West Yorkshire

View user's profile Send private message

Sync ADC Reading with PWM
PostPosted: Thu Jun 10, 2010 3:54 am     Reply with quote

Hello,

I am using the PIC18F4431 and need to know how to sync the reading of the adc when the PWM pin is high. At the moment I am using the standard adc reading but this is inaccurate.

Cheers

Dave
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Thu Jun 10, 2010 12:06 pm     Reply with quote

You could poll the INT_TIMER2 interrupt flag in a loop. When it goes
high it means a PWM cycle has started. You could read the ADC at that
time. See this example code which tests the INT_TIMER2 flag:
http://www.ccsinfo.com/forum/viewtopic.php?t=41403&start=5

Or if you want to do it inside an interrupt routine, this code shows how
to use the Timer2 interrupt. The PWM cycle starts when the
#int_timer2 interrupt occurs. But, if your PIC is running at a low
frequency, such as 4 MHz, there can be a 25 to 30 usec delay between
the time the Timer2 interrupt occurs, and time that it enters into the
#int_timer2 interrupt routine. This is the time required by the CCS
interrupt handler to "save the state of the machine" and to route to
the #int_timer2 routine.
http://www.ccsinfo.com/forum/viewtopic.php?t=41473&start=1
bkamen



Joined: 07 Jan 2004
Posts: 1615
Location: Central Illinois, USA

View user's profile Send private message

PostPosted: Thu Jun 10, 2010 9:33 pm     Reply with quote

If you look closely at the ADCON3 register, you'll see you can trigger the A/D to take a measurement on several source inputs as the trigger. One of them being the PowerPWM.

Then you could have an IRQ for the A/D to just get the data when ready.

I did this in the past and it works nice.

You don't even need to set IRQ's for the PPWM unit.. just enable it and set the trigger for the A/D as needed.

Then it's all done in hardware with the only IRQ being the A/D when the result is ready.

-Ben
_________________
Dazed and confused? I don't think so. Just "plain lost" will do. :D
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group