Maker Pro
Maker Pro

PWM signal with 50ns freq. Step

Hi all , i am working with PSoC 5LP. I have continious changable Analog Signals. I convert it to Digital with help of ADC. From this Result i want to generate PWM (Output1 Forwards, Output2 Ruckwards). All in 16-Bits. So i have range upto 65536.
I have Analog Input 0,1 to 3,3v. So if i gave Input 1,6v than i have 50% Duty Cycle of generated PWM.
PWM Basic Configuration:
16-Bit UDB
PWM Mode: Two Outputs
Period: 65535
CMP Value1: 32767 CMP Value2: 32676
CMP Type 1: Less CMP Type 2: Greater
Dead Band: Disable
Interrupt: None
Clock with 12MHz freq.
Here is the code. In ADC_Result i have 12-bit ADC result. From this result i want to generate 2 PWM Outputs. I know that i have to use WritePeriod(), WriteCompare(), WriteDeadtime() APIs.
Code:
int32 ADC_Result;
uint16 i=0;
int pwmValue, pulseWidth;
int main()
{ 
  // Start the components
Sys_Init();
 
// CyGlobalIntEnable;  // Uncomment this line to enable global interrupts.
   // Start Clock & PWM
Clock_Start();
PWM_Start();
  while(1)
  {
  
pwmValue = ADC_Result  // Which equation i have to use.
PWM_WritePeriod(pwmValue);
PWM_WriteCompare1();
 
  } 
}
I read the PWM datasheet & also check the Example PWM Programms but still i am much confsed for this following questions.
1. Need i Dead Band?
2. Which equation for converting ADC result into PWM?
3. Need i Interrupt/Global Interrupt ?

Regards
Max
 
Hi all,
i want to generate PWM step with 50ns. For this i have input signal.
PWM clock freq. = 24MHz.
if input is 3,25v then PWM freq = 1 µs (microsec)
if input is 0,5v then PWM freq = 250ns (nanosec).
pls share ur ideas for doing this task.
Regards
Max
 
Hello Max
The period of 24 MHz is 41.6 ns. So this is going to be roughly the maximum time delay you can achieve minus the shorted pulse that the signal source can supply, whatever that might be. That is if you want your PWM signal as a percentage in relation to this 24 MHz .If however you are asking for a PWM with an on time of 1us when a certain signal is detected and 250ns on time when another signal level is detected then your frequency will be lower than 24 MHz . You would be better to use a micro processor of some description or a Pi / Arduino based development board.
Adam
 
I first misread you post and posted an entirely useless answer, which I hope you did not read.

If I understand you correctly, you want to produce a sine wave with periods (not frequencies) from 250ns to 1uS.

To get a period of 250nS you with a 24MHz clock you will have exactly 6 samples to make your sin wave, which will not make much of a sine wave. At 1uS you will have 24.

The way you do this is to make a table of 24 entries, covering one cycle of the sine wave. To get the lowest frequency you will step through this table 1 entry at a time, one for each PWM period. To get the highest frequency you will step through them 4 at time, which means you have covered the entire cycle in 6 PWM periods or 4MHz or 250nS period. I will leave the method for getting 500nS and 770nS as an exercise for the reader.

This is a homework problem, isn't it? In a real world problem it would not have worked out so nicely!

Bob
 
Last edited:
hi Adam,
thanks. I am using 20MHz clock freq. for PWM. So i get 50nS PWM step.
I explain u my whole tast. I Need PWM steps 50ns, 100ns, 150ns...
I have Deadtime as Input Signal from 0,5v to 3,25v.
I have 2 PWM signals (Forward & backward). For this both Signal i have to set 47% of Duty cycle.
I want to generate H-Bridge
Regards
Max
 
Last edited:

Harald Kapp

Moderator
Moderator
The term "PWM" is misleading. A PWM signal is a digital signal, not a sine wave and vice versa.
So what exactly do you need? A sine wave or a digital PWM signal? Or do you want to generate a sine wave by filtering a PWM signal?
Maybe a sketch of the waveforms required can clear things up.

Why did you post this question in the "microcontrollers and programming" forum? Does it involve a specific type of microcontroller? If so, which one? If not what is the background of the question so I can move the thread to the appropriate forum?
 
hi Adam,
thanks. I am using 20MHz clock freq. for PWM. So i get 50nS PWM step.
I explain u my whole tast. I Need PWM steps 50ns, 100ns, 150ns...
I have Deadtime as Input Signal from 0,5v to 3,25v.
I have 2 PWM signals (Forward & backward). For this both Signal i have to set 47% of Duty cycle.
I want to generate H-Bridge
Regards
Max

Hi Max
Ok so myself and Bok were correct the first time? So It's not a sine-wave, it's a digital signal. You are confusing me a bit with saying you have a set 47% duty Cycle but then want steps??? What are you actually trying to do, what is the project? Are you controlling some motor or solenoid? Please explain in full so we can all help you and not go round in circles.
Thanks
Adam
 
So I guess he really want to generate a sign-wave, not a sine-wave. :eek:

And funny how the clock frequency and periods (whatever they mean) change from post to post.

I give up.

Bob
 
hi guys,
here is the complete exaplination of my whole Project.

I am working with PSoC 5LP. The Project is for Motor & have to implement H-Bridge.

I have deadtime as Input (in Volt from 0.5v to 3.25v).
I Need 40ns PWM Step, so i take Clock freq. 25MHz. I am fix with this clock freq.

So i have to generate PWM as
if Input = 0,5v = 250ns = 2 (2-256 Cycle)
if Input = 3,25v = 1 µs = 24 (2-256 Cycle).


Reply me soon.
Regards
Max
 
Each attempt you make to describe what you are trying to do is worse than the last one.

Sorry, but you will not get any help until you can coherently describe the problem.

Bob
 

Harald Kapp

Moderator
Moderator
PWM is not describes in terms of ns or µs but in terms of duty cycle.
You need to set the fundamental frequency of the PWM, then adjust the pulsewidth (and thereby the duty cycle).
For a purely digital implementation without using a microcontroller you will need:
  • An ADC to convert the analog signal to a digital value.
  • Probably you will need to scale the digitized signal to span the full PWM range fromj 0% to 100% at your resolution of 50ns.
  • A counter/divider to generate the fundamental PWM frequency
  • A digital comparator that sets or resets the PWM output when the counter has reached the scaled value from step 2.
Using a microcontroller (as may be available in your SOC) you can usually perform steps 2-4 from above using the µC and some software. If the SOC contains a PWM module, it will be even easier.
 
Thanks u Kapp.
It's really helpful for me.

Now i explain u what i had done & what i want.

I have Input Signal from 0,5v to 3,25v. But this Input is for Deadtime. i use ADC for convert. Now the main question is
1. In which form i Need this value in program?
2. How can i calculate period & Duty cycle(47%) from this Input.

Regards
Max
 

Harald Kapp

Moderator
Moderator
What is deadtime?
What resolution does your ADC have?
In which form you need the input value depends on your hardware and your software.
PWM has a fixed period (or frequency) that you define. Duty cycle is calculated from the ratio of on-time/period.

Sorry, but you will not get any help until you can coherently describe the problem.
 
Hi kapp,

ADC with 16-bit Resolution. Deadtime Input is in voltage from 0.5 to 3.25.
Fixed period with 300. Duty cycle should 47% of period.

Regards
Max
 

Harald Kapp

Moderator
Moderator
Sorry, that doesn't explain anything to me. What is a deadtime?

0.5 what? 0.5s, 0.5ms, 0.5µs ...?

If your duty cycle is fixed at 47%, you do not have PWM. The idea behind PWM is to vary the duty cycle to achieve different effective values of e.g. voltage or current.

I'm getting the impression (correct me if I'm wrong) that you haven't understood what PWM is about and what you really want to achieve with your project. Can you sketch a timing diagram and label it for explanation?
 
Hellp Kapp,
Deadtime is for 0,5v = 205ns & 3,25v = 1μs. (like 205ns, 250ns, 290ns, 330ns....1μs = 40ns Step).

I am really Sorry but i understand the requirment wrong. i want to give Deadtime as Input with vary duty cycle, nothing fix. It's PWM Signal.

So pls help me to give deadtime as Input.

Regards
Max
 
Last edited:

Harald Kapp

Moderator
Moderator
Deadtime is
I don't want to know how many µs the deadtime is, I want to know what the function of the deadtime in the signal (voltage vs. time is). That's why I asked you to draw a timing diagram with the respective lables so we can see what part of the timing you are talking about.

Sorry but i understand that i have to generate PWM but I have fixed Duty cycle at 47%, so it's not PWM. [This is my whole Task]
Sorry, what does this mean? You have to generate PWM with fixed duty cycle that is not PWM. This makes absolutely no sense. It is either PWM, then the duty cycle is not fixed. Or the duty cycle is fixed, then it is not PWM.

So pls help me first to give deadtime as Input.
I can't unless you explain what your "deadtime" is, see above.
 
Each attempt you make to describe what you are trying to do is worse than the last one.

Sorry, but you will not get any help until you can coherently describe the problem.

Bob
@Bob
Sorry but i also really confused for the Task.
just look my last reply n try to help me.
 
Top