Help Variable PWM using A/D PIC18F2431

Thread Starter

trr85

Joined May 30, 2009
4
Hi guys Im EE student Im doing a project where I need 2 PWM signals: 1 fixed PWM and 1 variable PWM using A/D module.
Im using POWER CONTROL PWM MODULE.

I did fixed PWM and it worked perfect, I tested with some PWM frequencys and some duty cycles, here I dont have troubles.

Variable PWM my analog input is a rectified sinusoidal wave at 60 Hz, Im using AN0, Im working in this project since April and I have troubles here, my output isnt working in the correct way. I was using 8 MHz cristal with HSPLL enabled so Fosc = 32 MHz, I had FPWM = 100 KHz at 8 bits PWM resolution, I was loading the 8 MSB to Duty Cycle register... but I cant get the correctly output, so the last Wednesday I get a 10 MHz cristal now I have Fosc = 40 MHz, and 10 PWM resolution bits at FPWM = 39 KHz.. I loaded the 10 A/D result bits to the 10 PWM duty cycle bits and I still having troubles, the PWM output is working bad, some times the output go to 5 Volts (100% duty cycle) or go to 0 Volts (0 % duty cycle) or stay freeze in a low duty cycle, some times didnt stop.

About my A/D configuration, Im using single shot, Im trigering A/D convertion by software, A/D interrupt disable, my TAD is Fosc/32, and my TACQT = 2TAD, I have followed the A/D configuration steps from datasheet.
Im using PWM free-running mode.
To read the A/D result Im using a PWM interrupt each time that interrupt is active Im reading the A/D result and loading to Duty Cycle registers.

I hope somebody can help me please I need finish it, this project is my thesis from university, its a led ballast, the variable PWM signal will be used for a CD-CD converter Boost to made a PFC, the fixed PWM will be used for a CD-CD converter Buck, Im in darkness in variable PWM since April I dont know what can be the trouble I read my code, read datasheet, Im going to be crazy =P

I show You my hardware connection and my variable PWM output in a video.
I have attached my code.

http://img33.imageshack.us/img33/6127/hardwarepwm.jpg
>>> Hardware connection

http://img5.imageshack.us/img5/4380/pwmanaloginput.jpg
>>> Analog input

http://www.fileden.com/getfile.php?f...able%20PWM.wmv
>>> Variable PWM output video

Note: please copy and paste the url-links to your web browser.

Thank You for Your time.
Regards.
Tom.
 

Attachments

mik3

Joined Feb 4, 2008
4,843
Do you want to read the value on AN0 and adjust the duty cycle according to it?

In your code add some functions which limit the PWM duty cycle between 0% and 100%. If the duty cycle value is not between 0% and 100% the PWM output will behave strangely.
 

Thread Starter

trr85

Joined May 30, 2009
4
Yes I want to read the analog input by ADC, load the ADC result to duty cycle value to have the PWM according the input,
Im using 10 bits from ADC result, I load in 10 bits resolution PWM duty cycle register, 2^10 = 1024, 1024 - 1 = 1023, 1023 = 0h3FF, so PWM duty cycle values are 0h0 - 0h3FF = 0% - 100%, in theory I dont need limit the PWM duty cycle because Im loading 10 bits from ADC result to 10 bits from PWM duty cycle, or Im wrong ?
 

mik3

Joined Feb 4, 2008
4,843
Limit the values to make sure they are fine. Also, the value which determines the PWM duty cycle depends on the clock frequency. I know how to calculate it when programming in C but not in assembly.
 

Thread Starter

trr85

Joined May 30, 2009
4
I have modified my code, I removed PWM interrupt, and now Im using ADC interrup, in Continuous Loop mode each time that ADC do a conversion Interrupt is generated when the 2nd and 4th words are written to the buffer, in the interrupt service routine I load the ADC result to Duty Cycle register, I did some test using a pot, now my ADC is working correctly, 0.5 V = 10% Duty Cycle in PWM, so 5 Volts = 100 % Duty Cycle PWM, Im loading the 10 ADC result bits to 10 resolution bits from PCPWM (duty cycle registers), Im using Digital Scope, when I get the PWM output the signal stay some seconds, after I luse the PWM signal, after some second the signal come back, after the signal down, after back, etc...
Im getting the correctly variable PWM output but the signal isnt constant, and its not good to use in a DC-DC converter, I need dont luse my PWM output.
I think the ADC interrupt is the trouble because I luse the PWM output, I hope u can help me guys thank for ur help and time.
I have uploaded my new code.

Regards.
Tom.
 

Attachments

Thread Starter

trr85

Joined May 30, 2009
4
Hi Alberto, Im using cristal 10 MHz but using HSPLL so my Fosc = 40 MHz, now I did get a new result in my PWM signal, the signal show now with a flickering, some times stay in some value flickering and after some time load the new value, maybe its a trouble with FIFO buffer from ADC, if somebody had use this 18F2431 A/D module I hope can tell me a suggestion, thank you people.

Regards.
Tom.
 
Top