ADC to PWM

Tip / Sign in to post questions, reply, level up, and achieve exciting badges. Know more

cross mob
lock attach
Attachments are accessible only for community members.
DaBr_1233126
Level 4
Level 4
10 likes given 5 likes given First like received

Hello All!

   

 

   

I have a need to generate a PWM signal with an adjustable duty cycle controlled via a 10K POT.   Having a bunch of 8 pin CY8C4014SXI-420 chips laying around I decided to try using them for this project.  Just enough room for Analog Input and PWM Output.

   

I am attaching my project which 'should' work.  Of course it doesn't....

   

I am using the CSD_ADC component and feeding it's output to the compare of the PWM component.  I started from an example I think i found in the component docs.  I have increased a couple of the delays to try getting it to work, but still a no go.

   

When debugging, I basically get only 1 value from the ADC (0x19FE) with it connected as shown.  I get basically a 0x01 when the pin is disconnected from the resister.  With my multimeter, I am reading about 1.2V at the pin when connected, no matter the POT setting.  (Sweep arm of pot is verified working and voltage is changing when disconnected from PSoC...)

   

I have tried 3 different chips, so I don't think the issue is hardware.

   

Anyone have ideas?

   

Dan

0 Likes
22 Replies
lock attach
Attachments are accessible only for community members.
rola_264706
Level 8
Level 8
50 likes received 25 likes received 10 likes received

Here is an example that checks for 3 levels using the PSOC 5lp.  It should give you some ideals.

0 Likes
DaBr_1233126
Level 4
Level 4
10 likes given 5 likes given First like received

So are you saying that the CSD_ADC component doesn't work?  This is being used to control brightness of an LED panel.  (120 White LEDs used to view an X-Ray)  I really need it to be adjustable thru the whole range...

0 Likes
Anonymous
Not applicable

Unfortunately, not able to open your attached project due to "incorrect format" errors upon execution;

   

That said, if you are getting only one value from the ADC: Either you are not running the ADC multiple times, you are not sampling correctly, or there is a hardware issue for your voltage not changing. Here is an attachd datasheet for the CSD ADC that might be useful to double-check: http://www.cypress.com/file/185806/download

0 Likes
Anonymous
Not applicable

According to the CSD ADC Sheet: Place a 1 M-ohm resistor in series between your ADC pin and the voltage you want to measure; The CSD-ADC will pull its input pin to 1.2 volts for calculating the voltage at the external end of the 1M-ohm based on the given 1 M-ohm series resistance and 1.2 volt node for the ADC.

0 Likes
DaBr_1233126
Level 4
Level 4
10 likes given 5 likes given First like received

So I checked my '1M' resister and it wasn't....  I replaced it and it is mostly working now.

   

There is ALOT of jitter on this thing.  Watching the PWM on an oscope I see the it going all over.  I will try adding some averaging next and see if it fixes it some.  It is really bad on low values...

   

BTW - My circuit and code all came from your reference datasheet.

0 Likes
lock attach
Attachments are accessible only for community members.
DaBr_1233126
Level 4
Level 4
10 likes given 5 likes given First like received

So in debugging, I am seeing a very consistant output from the ADC.  Put my view of the PWM shows it jumping around alot.  At low PWM duty cycles it is ALOT of jumping around.  Came someone check my setup here and tell me how to improve it?

   

I have similar code running on a CyBLE module that isn't doing this at all.

0 Likes
Anonymous
Not applicable

Under the ADC component, there is a setting to change: Sample time, sample averaging, and resolution. All three of those settings should help with getting better results. Plus, averaging the results in software doesn't seem to be working for your case 🙂

   

Let me if modifying the adc component settings works out for you (.cysch file)

0 Likes
DaBr_1233126
Level 4
Level 4
10 likes given 5 likes given First like received

I am not sure that the ADC is now the issue.  While debugging, I am watching a test variable, and it is staying fairly constant.  It is the PWM that is maybe acting up.   Also, the CSD_ADC component does not have any setting for sample time and sample averaging.  It is very basic!

   

I am very disappointed in this part (CY8C4014SXI-420) really.  I have used several other parts and not had the issues that this one does.  I wish cypress made parts with a newer core in them but the same low pin count.  I might have to change to the CY8C4245PVI-482 to get this project done.  I use those in several test fixtures for other projects and have never had an issue with them.  I worry about using them in this project due to the amount of stuff that gets pulled into the fan that will be blowing on this from outside the device.  SOIC8 pins are a lot further apart so less chance of shorting pins, and also much easier assembly.  Once my design is completed I will probably only make a hundred of these.

0 Likes
Anonymous
Not applicable

Fyi: The peripherals run even while the debugger has the CPU halted, so there might be hardware things happening when you try to debug 🙂

   

For example: Trying to use low power modes while debugging will cause the debugger to crash or for the device to fail to enter low power mode.

   

I've been using the CYBLE-022001-00 module, and it is working great so far (some odd code architecture, but still smooth-running). I have not tried the other devices you mention however.

0 Likes

Yes, that is a great module!  I use it and and the CYBLE-014008-00 Module in several of my designs.  I am hoping that the PSoC 6 BLE ends up as a module also.  It has some very interesting potential!!!

0 Likes
DaBr_1233126
Level 4
Level 4
10 likes given 5 likes given First like received

Also, are you having problems with BOTH attachments?  I have downloaded them both and they work fine for me.  (I downloaded them to a different laptop to make sure wasn't something on this one....)

0 Likes
Anonymous
Not applicable

Yeah, I think I was having trouble with both formats. My guess is the IDE you are using has some tweaks in it or something 😕

   

Here's the error I'm seeing:

   
    

Unable to open the project "C:\Product\PSoC Creator\Example Projects\Debugging\Design02.cydsn\Design02.cyprj": The data was not formatted correctly: The version value 'CyDesigner.Common.ProjMgmt.Model.CyPrjMgmtFolderSerialize' for type '3' is an unknown version.. This could mean that the data was corrupted or that it was created by an unsupported software version.

   
   

Obviously, I can still read the sources file main.c 🙂 

0 Likes

Are you using PSoC Creater 4.1?

0 Likes
Anonymous
Not applicable

I'm currently using PSoC 4.0, maybe the version update is not backwards compatible? I'll have to try it with 4.1 and see if that works

0 Likes
Anonymous
Not applicable

Switching to creator 4.1 works 🙂

0 Likes
Anonymous
Not applicable

The code line //Conversion_Active_DR &= ~Conversion_Active_MASK; is commented out in the MyISR code. Could that be affecting the result?

   

Looking at the averaging, it seems like the average will trend towards 0, I would try dividing the value before adding it to the average instead of adding all of the results together and then dividing. That way, you won't need to worry about overflow; Both methods should work since your sample-count is a compile-time constant.

   

...

   


        avgV += tempV / NUMAVGS;
        }
        
        /* Load the ADC value into the PWM Compare*/
        Voltage_mV = avgV;
        PWM_WriteCompare(Voltage_mV);    // Use ADC Voltage to adjust PWM Duty Cycle

   

...

0 Likes
DaBr_1233126
Level 4
Level 4
10 likes given 5 likes given First like received

Thanks for still looking into this with me!

   

As for the ConversionActive bit, I disabled the ISR and that bit of code from the example due to needing the pins.  I do wish this chip had the register component!  Would have used that instead!

   

As for moving the division, I am not seeing any difference while using that method.  I also did some tests where I left all the code alone but instead of reloading the compare with the computed value, I used a constant of 300.  Let it run with the oScope connected and sat and watched the output.  It is looking like the ADC Conversion might be interfering with the PWM output.

0 Likes
Anonymous
Not applicable

Huh; That's odd for the ADC to be interfering with the PWM output; I would expect it might be interrupt(s) related priorities then? You could try setting the ADC to lower priority and hopefully the flickering on the PWM output will disappear...

0 Likes
odissey1
Level 9
Level 9
First comment on KBA 1000 replies posted 750 replies posted
        Morantz, In my view, having a pot +ADC as an input control for PWM is not the right choice for this application. Maybe it's time to reconsider. As I understand, the plan was to have illuminated panel made for X-RAY screening with ~100 LEDs, each one adjustable by a pot. For this task, UART / I2C control is simpler, and can allow for automation of the brightness leveling. Just send address and duty cycle, no analog control at all. Alternatively, rotary encoder can be used instead of Pot, which produce digital value for PWM directly.   
0 Likes

Odissey1,

   

What I am doing is making a replacement controller board for someone else's existing product.   In their product, they use a 10K Potentiometer to control the brightness of the LED panel.  (120 LEDs in a 6x20 matrix.)  There is an option to plug in a foot pedal to control brightness.

   

One flaw in the origional design is they are driving a 2 current sources, each for 10 strips of 6 LEDs, and pushing them to max current.  When one LED dies, that starts a cascade effect and takes out most of the LEDs on the panel.  I have fixed this issue by driving each string of 6 LEDs with their own Current source that will accept a PWM signal for brightness control.

   

So, now I just need a clean PWM output to drive the panel.  Part of what you said about I2C control has me thinking of using an external ADC connected to the PSoC as that might help solve the issues I am seeing.  One thing I am doing to test things, is have a PCB produced to run further testing on.  I'm not so sure that the Protoboards aren't causing some of my issues.  A PCB allows me to rule it out.  OshPark got the design last week, so I should have some boards in my hand next week and can try again then.

   

*Edits for my poor spelling....

0 Likes
user_284806
Level 2
Level 2
First like given

user_, I've not looked at your code, but your PWM jitter may be due to the "natural noise" on the ADC reading. In this case, I would say that adding a small hysteresis to your reading would be more effective than averaging out.

0 Likes

Seemed to be caused by the Prototyping Board the circuit was assembled on.  I designed a PCB and had OSHPark make it for me, and the circuit works fine with the 28pin device.  I am thinking of doing another board with the 8pin device just to check it out also.  Other requirements forced me to the larger device for functionality reasons.  I am now also looking at a 4200L device for memory reasons also.  L:ike most projects, once you fix the 'problem' someone else starts asking 'well, what about....' and things get bigger!

0 Likes