Variable PWM PIC18F2431


Closed Thread
Results 1 to 8 of 8
  1. #1
    Join Date
    May 2009
    Posts
    5

    Default Variable PWM PIC18F2431

    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.
    Attached Files Attached Files

  2. #2
    Join Date
    Feb 2005
    Location
    Kolkata-India
    Posts
    563


    Did you find this post helpful? Yes | No

    Default Probably not a problem

    Hi,

    As far as I understand you are trying to reconstruct the input waveform through the PWM output. Probably your code is working fine but you are not being able to visualize it due to triggering issues on the oscilloscope. Try using a R-C low pass filter at the output. If you are using a DSO change the acquisition to average sample. Better even select the trigger to be a different channel with the input analogue and adjust timebase according to the input.

    This would be just a step as a proof of concept.
    Regards

    Sougata

  3. #3
    Join Date
    May 2009
    Posts
    5


    Did you find this post helpful? Yes | No

    Default

    Thank you for your answer sougata Today I have changed to a digital scope, but I dont undestand why the pwm output some times stay freeze, or start doing the work and go to 0 volts the pwm output, other times stay in 5 volts, what can be doing it ?

    I have modified my code using pwm and a/d interrup... each time that PTMR match PTPER, the PWM module go to interrup, in PWM interrupt I start A/D conversion and load the result to Duty cycle register, after I turn off PWM interrupt, I attach here the code, I hope u can check it please and tell me some suggestion, thank you.

    Regards.
    Tom.
    Attached Files Attached Files

  4. #4
    Join Date
    Feb 2005
    Location
    Kolkata-India
    Posts
    563


    Did you find this post helpful? Yes | No

    Default Have you tried the R-C Filter ?

    Hi,

    In your DSO you should find a menu called acquire. In that menu there should be different options like :

    1. Sample
    2. Average
    3. Peak-Detect
    ....
    ......

    or so.

    Select the average mode --> if it supports number of samples to be programmed, select it to 128 or higher now watch the waveform with a timebase between 1ms and 5ms.

    Your PWM runs at a high frequency and is continuously changing. If your scope is running in automatic trigger mode, it is repeating the trigger as per the timebase. If you try "Autoset" on the scope, it will perhaps try to lock onto the PWM frequency. But what you are interested is the PWMed envelope.

    Using a simple RC may help.

    If I find some time I would try to duplicate your setup here. But I still doubt Your scope is not set up properly to visualize the modulation
    Regards

    Sougata

  5. #5
    Join Date
    May 2009
    Posts
    5


    Did you find this post helpful? Yes | No

    Default

    Thank you Sougata, I will test today it, later I will put here the results.

    Regards.
    Tom.

  6. #6
    Join Date
    Oct 2004
    Location
    Hangover, Germany
    Posts
    289


    Did you find this post helpful? Yes | No

    Wink

    I can't see any 100nF-Cs round your PIC - is he resetting ? You can use a portpin to see it!
    Maybe it will better the AD-Converter by filtering his AVDD via 56 Ohm and 100nF against ground, but this is not the reason for your problem.

    The INTHIGH-routine starts the AD-conversion on every Interrupt, because the bit-check is faulty (or not complete).

    For PIC18-uCs: Writing to a port (PORTA) is better done by writing to the LAT-register instead of a PORT-register.
    PBP 2.50C, MCS+ 3.0.0.5, MPLAB 8, MPASM 5.14, ASIX Presto, PoScope, mE mikroBasic V7.2, PICKIT2

  7. #7
    Join Date
    May 2009
    Posts
    5


    Did you find this post helpful? Yes | No

    Default

    Hi guys, 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.
    Attached Files Attached Files
    Last edited by trr1985; - 11th June 2009 at 21:22.

  8. #8
    Join Date
    May 2009
    Posts
    5


    Did you find this post helpful? Yes | No

    Default

    Im back from university, I get new results, The A/D module is working fine I tested it loading the ADC result to a port C and A from pic, I used a led bar (10 leds) to check it, when I tested in PWM it work fine load the correctly value to duty cycle register, if I load 2.5 Volts in analog input, I get 50% from duty cycle in PWM output signal, my trouble now is that my signal is flickering a lot, some times stay some value for some seconds and after load other value, I think that FIFO buffer from ADC is doing wrong some thing, I changed my code today, Im using PWM interrup each time that PTMR match PTPER start the Hight priority interrupt routine service, in this interrupt service Im reading and loading the ADC result to duty cycle registers, I have attached my new code here, I have disallowed ADC interrupt.

    I hope someone can help me, thanks.

    Regards.
    Attached Files Attached Files

Similar Threads

  1. EEPROM Variables (EE_Vars.pbp)
    By Darrel Taylor in forum Code Examples
    Replies: 79
    Last Post: - 26th October 2012, 00:06
  2. Help with sound command in 2 programs
    By hyperboarder in forum mel PIC BASIC Pro
    Replies: 4
    Last Post: - 5th July 2007, 20:36
  3. Variable PWM on 2 Channels using software.
    By Tissy in forum mel PIC BASIC Pro
    Replies: 3
    Last Post: - 23rd September 2006, 01:34
  4. pwm to pin using variable
    By wsmrite in forum mel PIC BASIC Pro
    Replies: 3
    Last Post: - 7th April 2006, 17:08
  5. Tidying Up PWM Routine
    By Tissy in forum mel PIC BASIC Pro
    Replies: 4
    Last Post: - 21st February 2005, 00:26

Members who have read this thread : 1

You do not have permission to view the list of names.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts