Pakingzzzzz's Posts
Nairaland Forum › Pakingzzzzz's Profile › Pakingzzzzz's Posts
1 2 3 4 5 6 7 8 ... 185 186 187 188 189 190 (of 190 pages)
In the image below is represented the output signal from the two pins:
|
This image from oscilloscope has 5ms/div , so you can see that each signal has a 10ms period. Another thing we can see here is time between switching pins.For that we reduce at 10us/div and the result is below:
|
As you can see we have in vector 314 elements and the program only 313 because at last we have the transition between pins, and on the oscilloscope we have a better frequency. The results are:
|
The value of OCR1A is determined from OCR1A=(f /f *N)-1 and OCR1A=509 . So Timer 1 start counting until reach OCR1A=509 then activate the interrupt with a frequency 31372Hz. To enable interrupts we need to set the OCIE1A=1 in TIMSk1 register and use ISR(TIMER1_COMPA_vect) (more details about interrupts here and here). To be sure there is no problem with interrupts we will use cli() ( stop interrupts) and sei() (enable interrupts). In ISR function we set the OCR0A and OCR0B with duty cycle values and change this values according to vector, also at the finish of each crossing of vector we change the enabled pin. Before sine wave we must see if it is everything ok so we have alternate the pins at a stable duty cycle OCR0A and OCR0B equals with 128. The program for that is below: int i=0; int x=0; int OK=0; int sinPWM[]={1,2,5,7,10,12,15,17,19,22,24,27,30,32,34,37,39,42, 44,47,49,52,54,57,59,61,64,66,69,71,73,76,78,80,83,85,88,90,92,94,97,99, 101,103,106,108,110,113,115,117,119,121,124,126,128,130,132,134,136,138,140,142,144,146, 148,150,152,154,156,158,160,162,164,166,168,169,171,173,175,177,178,180,182,184,185,187,188,190,192,193, 195,196,198,199,201,202,204,205,207,208,209,211,212,213,215,216,217,219,220,221,222,223,224,225,226,227, 228,229,230,231,232,233,234,235,236,237,237,238,239,240,240,241,242,242,243,243,244,244,245,245,246,246, 247,247,247,248,248,248,248,249,249,249,249,249,255,255,255,255,249,249,249,249,249,248, 248,248,248,247,247,247,246,246,245,245,244,244,243,243,242,242,241,240,240,239,238,237,237,236,235,234, 233,232,231,230,229,228,227,226,225,224,223,222,221,220,219,217,216,215,213,212,211,209,208,207,205,204, 202,201,199,198,196,195,193,192,190,188,187,185,184,182,180,178,177,175,173,171,169,168,166,164,162,160, 158,156,154,152,150,148,146,144,142,140,138,136,134,132,130,128,126,124,121,119,117,115,113,110,108,106, 103,101,99,97,94,92,90,88,85,83,80,78,76,73,71,69,66,64,61,59,57,54,52,49,47,44,42,39,37,34,32,30, 27,24,22,19,17,15,12,10,7,5,2,1}; void setup() { Serial.begin(9600); pinMode(5, OUTPUT); pinMode(6,OUTPUT); cli();// stop interrupts TCCR0A=0;//reset the value TCCR0B=0;//reset the value TCNT0=0;//reset the value //0b allow me to write bits in binary TCCR0A=0b10100001;//phase correct pwm mode TCCR0B=0b00000001; //no prescaler TCCR1A=0;//reset the value TCCR1B=0;//reset the value TCNT1=0;//reset the value OCR1A=509;// compare match value TCCR1B=0b00001001; //WGM12 bit is 1 and no prescaler TIMSK1 |=(1 << OCIE1A); sei();// enable interrupts } ISR(TIMER1_COMPA_vect){// interrupt when timer 1 match with OCR1A value if(i>313 && OK==0){// final value from vector for pin 6 i=0;// go to first value of vector OK=1;//enable pin 5 } if(i>313 && OK==1){// final value from vector for pin 5 i=0;//go to firs value of vector OK=0;//enable pin 6 } x=sinPWM[i];// x take the value from vector corresponding to position i(i is zero indexed) i=i+1;// go to the next position if(OK==0){ OCR0B=0;//make pin 5 0 OCR0A=128;//enable pin 6 to corresponding duty cycle } if(OK==1){ OCR0A=0;//make pin 6 0 OCR0B=128;//enable pin 5 to corresponding duty cycle } } void loop() { } |
But we want to alternate pins for each half cycle and make a variable duty cycle for each pulse. For this thing we use another timer( Timer 1 ) in CTC mode with interrupts. We generate a signal with the same frequency as frequency of pins 5 and 6 and after each pulse we change the duty cycle(values from the vector) with an interrupt. At the end of the vector we change pins(half cycle period) and start over. An interrupt is a part of a program that pause the loop function and execute another part of a program at a very specific time and after that start from where it was. For this application we use a interrupt that is enabled when Timer 1 match with the OCR1A value. To change the duty cycle at every pulse on pins 5 and 6 we must generate interrupts with a 31372Hz (to enable one interrupt at the same time with an pulse on pins 5 and 6). To generate that interrupt at every pulse we must set Timer 1 in CTC mode and for that we use TCCR1B register to make WGM12 =1 and CS10=1 (no prescaling), OC1A must be set in toggle mode in TCCR1A register( COM1A1,COM1A0,COM1B1,COM1B0 )see waveform generation mode bit description for Timer 1. Now we must calculate the value for OCR1A to generate a 31372Hz signal. For that we use the formula from the datasheet with a smal modification, number 2 dissapear f =f /N(1+OCR1A) . Explication is that the formula with number 2 is for pwm and to have a frequency to a signal, the signal must be high and low and we wait two counts until compare match, one count before signal became low and one count before signal became high again(picture below). At interrupts when timer hits the compare match value the interrupt is generate, so number 2 dissapear.
|
To write the duty cycles we will use OCR0A and OCR0B for timer 0(pins 5 and 6), that means for one half cycle, OCR0A will be equal with every component of vector myPWM and for other half cycle OCR0B will do that. With the program below we generate phase correct signal at a 31372 Hz and 100 duty cycle (this is between 0 and 255 on Timer 0). void setup() { pinMode(5, OUTPUT); pinMode(6,OUTPUT); TCCR0A=0;//reset the register TCCR0B=0;//reset tthe register TCCR0A=0b10100001;// phase correct pwm mode TCCR0B=0b00000001;// no prescaler OCR0A=100;//duty cycle } void loop() { // put your main code here, to run repeatedly } The picture below is a scope shot of the signal emanating from pin 6. So the result is only for pin 6, pin 5 is exactly like 6, but out of phase. Lagging with a degree of 180 deg:
|
Next we put the values in a vector like: int sinPWM[]={1,2,5,7,10,12,15,17,19,22,24,27,30,32,34,37,39,42,44,47,49,52,54,57,59,61,64,66,69,71,73,76,78,80,83,85,88,90,92,94,97,99,101,103,106,108,110,113,115,117,119,121,124,126,128,130,132,134,136,138,140,142,144,146,148,150,152,154,156,158,160,162,164,166,168,169,171,173,175,177,178,180,182,184,185,187,188,190,192,193, 195,196,198,199,201,202,204,205,207,208,209,211,212,213,215,216,217,219,220,221,222,223,224,225,226,227, 228,229,230,231,232,233,234,235,236,237,237,238,239,240,240,241,242,242,243,243,244,244,245,245,246,246, 247,247,247,248,248,248,248,249,249,249,249,249,250,250,250,250,249,249,249,249,249,248, 248,248,248,247,247,247,246,246,245,245,244,244,243,243,242,242,241,240,240,239,238,237,237,236,235,234, 233,232,231,230,229,228,227,226,225,224,223,222,221,220,219,217,216,215,213,212,211,209,208,207,205,204, 202,201,199,198,196,195,193,192,190,188,187,185,184,182,180,178,177,175,173,171,169,168,166,164,162,160, 158,156,154,152,150,148,146,144,142,140,138,136,134,132,130,128,126,124,121,119,117,115,113,110,108,106, 103,101,99,97,94,92,90,88,85,83,80,78,76,73,71,69,66,64,61,59,57,54,52,49,47,44,42,39,37,34,32,30, 27,24,22,19,17,15,12,10,7,5,2,1}; First value is 1 because we want to reduce the dead time betwen half cycles of sine signal. |
ARDUINO PWM PIN. As has been explained in the data sheet, some pins of the arduino can generate PWM signals at high frequencies, so we will utilize this and adapt it for sine equation. Let’s assume our frequency is 50Hz; meaning the time period is 20ms. So 10ms should be the half cycle period. In these 10ms we need to have many pulses with different duty cycles, starting with small duty cycles, in the middle of the signal we have maximum duty cycles and finish also with small duty cycles. To generate a sine wave we will use two pins one for positive half cycle and one for negative half cycle. In this tutorial, we use pins 5 and 6. That means Timer 0 . For a smooth signal we choose phase correct pwm at a frequency 31372 Hz.. One of the biggest problem is how to calculate the necessary duty cycle for each pulse. So, because our frequency is f=31372Hz the period for each pulse is T=1/31372=31.8 us, so number of pulses for a half cycle is N=10ms/31.8us=314 pulses. Now to calculate the duty cycle for each pulse we have y=sinx. But in this equation we need degrees.. So half cycle has 180deg for 314 pulses. So, for each pulse we have; 180/314=0.57deg/pulse. That means for every pulse we move forward with 0.57deg. Because it’s unpleasant to calculate each duty cycle by hand, below is a small program that calculate the duty cycle between 0 and 90 deg( on serial monitor) and between 90 and 180 deg, which is the mirror of the first 0-90 deg. The program is: float x=0; float y=0; const float pi=3.14; int z=0; float v=0; int w=0; void setup() { Serial.begin(9600); } // the loop function runs over and over again forever void loop() { if (w==0){ v=x*pi/180; // making deg in radians y=sin(v); //calculate sine z=y*250; // calculate duty cycle(250 not 255 because will help to turn off transistors) delay(100); x=x+0.57;// increase the angle } if (x>90){// we stop to calculate we have the duty cycle for angles smaller than 90deg // the other half is symetric x=0; w==1; } Serial.println(z);// on the serial monitor will appear duty cycles between 0 and 90 deg } |
Arduino board designs use a variety of microprocessors and controllers. The boards are equipped with sets of digital and analog, input/output (I/O) pins that may be interfaced to various expansion boards (shields ) and other circuits. The boards feature serial communications interfaces, including Universal Serial Bus (USB) on some models, which are also used for loading programs from personal computers. The microcontrollers are typically programmed using a dialect of features from the programming languages C and C++ . In addition to using traditional compiler toolchains, the Arduino project provides an integrated development environment (IDE) based on the Processing language project. The Arduino project started in 2003 as a program for students at the Interaction Design Institute Ivrea in Ivrea, Italy, aiming to provide a low-cost and easy way for novices and professionals to create devices that interact with their environment using sensors and actuators.. Common examples of such devices intended for beginner hobbyists include; simple robots, thermostats, led display, security alarm and motion detectors etc . The name Arduino comes from a bar in Ivrea, Italy, where some of the founders of the project used to meet. The bar was named after Arduin of Ivrea, who was the margrave of the March of Ivrea and King of Italy from 1002 to 1014. |
WHAT IS AN ARDUINO? Arduino is an open source computer hardware and software company. it is also a project and user community that designs and manufactures single-board microcontrollers and microcontroller kits for building digital devices and interactive objects that can sense and control objects in the physical world. The project's products are distributed as open-source hardware and software , which are licensed under the GNU Lesser General Public License (LGPL) or the GNU General Public License (GPL). This License permits the manufacture of Arduino boards and software distribution by anyone. Arduino boards are available commercially in preassembled form, or as do-it-yourself (DIY) kits. The picture below is an Arduino Uno board.
|
In a nutshell, I will be discussing in this post, how to generate a sine wave modulated from different PWM signals. With these technique, we can make pure sine inverters or generate sine signals with different frequencyes. As with anything programming, there are several methods which can be used to generate sinusoidal pulse width modulated signals using Arduino. But I shall settle for the method which I am going to explain in this post. Mind you, it does not really matter which method you use. What really matters most is the generation of the sinusoidal pulse width modulated signals at the output if the Arduino pins. The smart ones out there might end up successfully putting the piece of codes presented here together and have a working prototype. Some might want a thorough tutorial on it.. Any interested persons should contact me through the above number or email. I offer online tutorial or live tutorial.. I also sell E-book on the topic.. I will answer any questions you throw at me. But try and read through the explanations carefully so that you will ask a better question. By doing so, everyone will learn from it when I answer your questions. Please do not Pm me. Post your questions here, and I shall try to answer them as best as I can. |
I teach you how to build a pure sine wave inverter with arduino or (atmega328), in one month. The tutorial is in two stage, namely; the programming stage and the hardware build stage. In the programming stage, I will teach you the art of programming an Arduino so as to produce a sine wave signal. In the second stage, I will tech you how to build the electronic circuit for switching the low voltages and stepping it up to the required high voltage vise versa.. Be you a novice, beginner or intermediary in the field. Owing to the fact that the programming of an Arduino is so vast and broad a topic. I have put down a well laid down curriculum which chiefly selects the relevant topics which are instrumental to the successful programming of an Arduino to generate sine wave. At the end of the tutorial, you will be able to master the coding or programming of an Arduino to produce pure sine wave, also called; sinusoidal pulse width modulation (sPWM), to run on frequencies of your choice. |
tundemoney:Email kingsleyobinna26@yahoo.com or call 07029365083.. From the look of your criteria, you would need a sought if customized build. You should provide your full technical specifications for the prop. |
Nice project going.. |
DexterTech:Are you angry with the verbal use of the word coupling'? I guess you are also building your 3 axis gyro/ accelerometer from scratch, as well as the GPS module and other vital module that makes up a flight controller. Not to mention the electronics parts that you will be using, which I guess you are building from scratch as well.. Good luck bro to your scratch build. Or should I say, scratch less build... |
darediamond:You are dead right.. High frequency is the key. Radio frequency, resonance, high voltage couples up to multiply the effect unimaginable. |
Pharaoh94:Your input looks somewhat confusing at the beginning.. But I am remarkably happy at the last conclusion. There are things such as free energy! |
@ ogocology.....
Sorry if I messed your thread with lots of pics.. |
You can call me on: 08164679552
|
And these are you he models of heli I built then.
|
(1) Swash plate (2) Brushless motor (3)Main rotor Blades
|
(1) Tx (transmitter) (2) Rotorhead (3) ESC (4) Gears
|
(1) Flyberless system and Rx (receiver) (2) Servos. (3) Gyro (4) Lipo batteries. (No more available)
|
These are all the parts I used I have, put together.... The big black fiber blades to the left are for helicopter weighing 17-20kg
|
ogocology:I have lots of rc accessories which I used when I was building my rc helicopter.. I am putting them up for sale..Which one do you need Brother? |
I had shelved this project for the future |
400billionman:Hello 400billiinman. Are you still interested in the 3D house building machine. |