I need to produce a Triangular wave in ARM/LPC 1768 microcontroller and compare it with a SIN wave, actually I am using PWM Inverter to control an AC motor
DAC is a useful but i dont want to see the triggering,i just want to compare the triangle wave with a sin wave in ARM , i want just 0 & 1 at the out put pin,
Referring to your answer to Diomadson, does it mean that you already have sine wave and tri-wave inputs and you some how want to compare these two to get 0 or 1 logic output then what you need is a simple comparator. Most of the modern microconotrllers do have at-least one comparator on chip in the analog section. Unfortunately LPC176X chips do not any on chip. That would have made your job easier. If needed you can add an external opamp.
Now if you do not want to use any external circuit then you will have to sample these signals using on-chip ADC and compare in the software - a software comparator that mimics the real op-amp!!!!!
Coming back to your original question, a compiler does not play any role in generating a wave or signal output. All you have to manage in your software code irrespective of the compiler and the programing language you write your code in.
However, you can discuss your exact scheme on feeding the sine and tri wave inputs to your LPC micro and I can help you further. Drop in a mail or use the RG message box.
TIMER 0->Counter clk: 10 MHz, Counts every: 100 ns which counts 0 to 1000 to make a 10KHZ triangular wave form
TIMER 1 -> Counter clk: 1 MHz, Counts every: 1000 ns which counts 0 to 20000 to make 50HZ (0.02sec period)
i compared 2 wave form with a simple if() , but when i delete second and third phase from the code, and i see in LOGIC ANALYZER the wave form is acceptable,but when i don't delete second and third phase from the code, all three wave form will destroy and it is so strange!!!
while(1)
{
rampc= LPC_TIM0->TC;
sinc= LPC_TIM1->TC;
//first phase**********
if (sin(100.0*3.14*(double)sinc/1000000.0)>(double)rampc/1000.0)
{
LPC_GPIO0->FIOSET=1;
}else
{
LPC_GPIO0->FIOCLR=1;
}
//second phase**********
if (sin(100.0*3.14*(double)sinc/1000000.0+(2*3.14/3))>(double)rampc/1000.0)
{
LPC_GPIO0->FIOSET=2;
}else
{
LPC_GPIO0->FIOCLR=2;
}
// third phase*********
if (sin(100.0*3.14*(double)sinc/1000000.0-(2*3.14/3))>(double)rampc/1000.0)
What you have observed is very apparent from your code. Please note that irrespective of you code written in C or Assembly it is a SET OF INSTRUCTIONS EXECUTED SEQUENTIALLY.
Thus, it is only one phase that will get executed at a given time since you are using the SAME TIMER0 to generate RAMP. This further means in a simple way that first your PHASE 1 will get generated, then PHASE 2 and then PHASE 3. This is expected as you have different PWM settings but you are using only one timer TIMER0 in this case.
So you can only test one phase and then the waveforms are acceptable to you but not all three phases.
Please again refer to the LPC176X product datasheet Rev.9.5 released 24 June 2014. Refer point 8.22 PWM Module, page 33. Read this section carefully - It states that although you have the SIX (6) channels of PWM output, the I/O pins are selectable but the PWM Block uses only ONE TIMER. I see this as a limiting factor in your application.
To run THREE PHASES simultaneous, you need three (3) independent timers and 3 different I/O pins in your Micro/LPC so that you can get continuous 3-phase output. For this you can consider the Motor Control PWM module that provides 3 phase outputs with its three channels. These channels have their own timers so you should have no difficulty in generating the tri-wave simultaneously. Refer to Chapter 25 of the NXP User Manual UM10360 for LPC176X.... Family micros.
Also, when you get the digital output on your PWM (I/O) pin you can use a R-C Low Pass filter to convert into respective SINE or TRI Wave. The R-C time constant you can choose to suit your highest PWM frequency.
Hope this is a satisfying answer to your present problem.
Thanks for your feedback and comments! I use Keil but for fun only. Just to evaluate the compiler software and during teaching and demonstration. I am an old fashioned guy still hanged to the beauty and purity of ASSEMBLY Language programming!
At first look high level languages and the Cross-Compilers seem to be attractive but in my experience they prove to be inefficient in the long run. Cost is another factor, question arises are we getting the proper returns on our investments in these tools?
ANy way I wish good luck to you in your project and do feel to contact me in case you need any further help.