Input Voltage Signal and Output PWM Signal?

Total Page:16

File Type:pdf, Size:1020Kb

Input Voltage Signal and Output PWM Signal?

input voltage signal and output PWM signal? http://www.avrfreaks.net/index.php? name=PNphpBB2&file=printview&t=131783&start=0 Mobz00 - Apr 16, 2013 - 12:51 PM Post subject: AVR-MT128: input voltage signal and output PWM signal? Hi

I finally got my AVR-MT128 board to work

Im trying to build a controller that takes voltage as input and outputs a PWM signal. Shouldn't be too hard but im very new to building electronic.

I need help with figuring out which pins I need to connect my input and output to? and property also how to read/write the input/output in the code.

I have read the whole Users Manual but didnt get my closer: https://www.olimex.com/Products/AVR/Dev ... -MT128.pdf

Thank for your help!

The controller is going to be used to control a homebuild 5KW wind turbine bobgardner - Apr 16, 2013 - 01:07 PM Post subject: RE: AVR-MT128: input voltage signal and output PWM signal? I have an MT128. Of course, you have downloaded the schematic? This shows which pin on the avr goes to which pin on the connectors. Mobz00 - Apr 16, 2013 - 01:15 PM Post subject: RE: AVR-MT128: input voltage signal and output PWM signal? Is it this you are talking about? https://www.olimex.com/Products/AVR/Dev ... -REV-A.pdf

I have looked at it but it doesn't tell me much dbrion0606 - Apr 16, 2013 - 02:01 PM Post subject: RE: AVR-MT128: input voltage signal and output PWM signal? Well, you have a 6 pîns connector named ADC, from the manual p 6 the schematics are in there, and it inputs 4 ADC channels, ADC0,1,2,3 (the 2 other AD channels are used for debugger). You might first choose one of these pins, try to convert and send (via the debugger or via a serial line or via the built in LCD) its value, to see if that part works (the other part is not likely to be more complicated, but you should try to have parts working without trouble hunting in lots of code). bobgardner - Apr 16, 2013 - 03:44 PM Post subject: RE: AVR-MT128: input voltage signal and output PWM signal? Yep. That's the MT128 schematic! Can you edit compile burn and run an led blinker using your compiler of choice? I'd recommend the Next Step as init uart1 to 38400 (thats a lo error baud rate with a 16mhz xtal) and send UUUUU in a loop. If you can see that in hyperterminal, you are ready to rock. Did you see the example programs graciously submitted by a great programmer up on the olimex site? dbrion0606 - Apr 16, 2013 - 04:27 PM Post subject: RE: AVR-MT128: input voltage signal and output PWM signal? Well, Bob Gardner is right pointing out to example programs : I saw one, called avr-mt128_Display.c, which uses the LCD (inside it, there is a function named LCDSendInt_Old, which is ready to display an 16 bits integer -might come out the ADC-); you get a software for uart, too (more complicated than sending Us -ie 0b01010101-) . There is also a test program, called AVR-MT-ICCAVR.zip, which tests every thing -execpt pwm- and countains a lot of well written functions..

And Holy Mex is accustomed to making very clear, good quality hardware -there makefiles and software are better than what I could do, too) , where pins are easy to locate (on their photo, page 5, the ADC connector is in the right of the PWR and there is even an arrow to show it).... bobgardner - Apr 16, 2013 - 06:38 PM Post subject: RE: AVR-MT128: input voltage signal and output PWM signal? Thanks for the nice complement. Mobz00 - Apr 16, 2013 - 07:50 PM Post subject: RE: AVR-MT128: input voltage signal and output PWM signal? Thank you two for your replies!

Bob Gardner; Yeah I found that example program made by you dbrion0606; Now I know which pins that I need to connect to! thx

I have stolen this code so far:

Code: //------//ADC initialisation // Conversion time: 112uS void adc_init(void){ ADCSRA = 0x00; //disable adc ADMUX = 0x00; //select adc input 0 ACSR = 0x80; ADCSRA = 0x87; }

//------int readadchan(char n){ //read ch n of internal 10 bit a/d

ADMUX=n; //select channel n ADCSRA |=0x40; //init conversion while((ADCSRA & 0x40) !=0){}; //wait for conv complete return ADC; }

Which chan should I use when I call the function "readadchan(char n)" ? Can I just choose from 0-3 (dependent on which pins I connect my DC signal to)? dbrion0606 - Apr 17, 2013 - 06:52 AM Post subject: RE: AVR-MT128: input voltage signal and output PWM signal? Yes you can... Mobz00 - Apr 17, 2013 - 03:09 PM Post subject: RE: AVR-MT128: input voltage signal and output PWM signal? I got it to work!! Thanks for the help!

I have a few questions: When I connect a DC signal to ex ADC0 and I read all 4 channels there are fluctuating values in all of them, is that normal? (by fluctuating I mean values going from 17 to 18 and then back to 17 again)

Is the maximum input voltage 5V? Mobz00 - Apr 17, 2013 - 03:50 PM Post subject: AVR-MT128: Output PWM signal? Hi again

I am completely new to programming microcontrollers (know how to program C and C++ tho)

Can someone point me in the right direction when I want to make a PWM output on my AVR- MT128? dbrion0606 - Apr 17, 2013 - 03:59 PM Post subject: RE: AVR-MT128: input voltage signal and output PWM signal? Yes, it is normal. You can either live with that -IMO it is the simplest way - , or average, say, three samples (but that won't hide the 17.5 bits case) , or use such things as "median filter" (you order 2*N+1 samples, and you take the Nth one as being representative).

Quote: Is the maximum input voltage 5V?

If your power supply is 5v, yes (and it is more than likely with LCDs...) The maximum range is determined by Aref, which can be modified (but, by default, it is the power supply). You can go safely up to 5v+0.6v, but for a short time -and the converson will be wrong- mckeemj - Apr 17, 2013 - 04:14 PM Post subject: RE: AVR-MT128: Output PWM signal? Two things needed to start: requirements and the datasheet. What frequency and dutycycle range do you need for the PWM?

Then, look in the AtMega128 datasheet at the section on timers. There's lots of information there and it can be overwhelming, but take it slowly and it will come together. Understanding how the timers work, will make it easier to debug and modify later.

Also, a search of these fora should yield a truckload of examples of example timer example.

In a nutshell, though: configure the timer for the PWM mode, set the timer top value ( sometimes... depends on timer and mode ), start generation by setting the prescaler. Then set the dutycycle by setting the compare register value.

Martin Jay McKee dbrion0606 - Apr 17, 2013 - 04:31 PM Post subject: RE: AVR-MT128: Output PWM signal? Well, what do you want to do with PWM: output speech (fast PWM would not be that bad) drive motors (phase correct PWM would be better) or?

There is a good tutorial (at least )in AVRfreaks tutorial : http://www.avrfreaks.net/index.php?name=PNphpBB2& file=viewtopic&t=50106 and http://www.avrfreaks.net/index.php?name ... mp;t=68302

Have you got any testing equipment (scope, multimeter)? clawson - Apr 17, 2013 - 05:10 PM Post subject: RE: AVR-MT128: Output PWM signal? @Mobz00,

You appear to have started the same topic twice. I've no idea why you did that. Cross posting will not be tolerated here. I have merged the two threads (without any editing). Please don't do it again.

Moderator. Mobz00 - Apr 17, 2013 - 07:27 PM Post subject: RE: AVR-MT128: Output PWM signal? clawson: Sorry for the dobbelt topic, the reason was that I asked two questions in my first topic and I later realized that I should properly only ask one big question in one topic. That will ofc not happen again.

The output is going to drive a Solid State reply. The reply is powering the field coil in an alternator.

The Solid State reply has a max around 100hz so I guess my frequency of my PWM will be around that 100hz. The dutycycle range should (if possible?) be from 0% to 100%.

I have a multimeter at home and I have access to scopes down at the university

Guess I have a lot of reading to do bobgardner - Apr 17, 2013 - 07:46 PM Post subject: RE: AVR-MT128: Output PWM signal? Use a large prescaler to get a slow pwm. If the AVR is 8mhz and the prescaler is 256 and the timer0 mode is pwm fast 8 bit, the pwm rep rate is 122 Hz. mckeemj - Apr 17, 2013 - 09:52 PM Post subject: RE: AVR-MT128: Output PWM signal? Or, at only 100Hz, do the pwm in software. What is the resolution you need?

Martin Jay McKee Mobz00 - Apr 17, 2013 - 10:44 PM Post subject: RE: AVR-MT128: Output PWM signal? mckeemj: You mean that I just code the PWM myself using while loop with a delay?

I think 8 bit resolution would be fine but 10bit would be nice to have bobgardner - Apr 18, 2013 - 12:38 AM Post subject: RE: AVR-MT128: Output PWM signal? What clock speed are you using? dbrion0606 - Apr 18, 2013 - 07:16 AM Post subject: RE: AVR-MT128: Output PWM signal? Did you notice there was almost another thread with the same structure (Analog signal tested with a potentiometer --> PWM parameters) ongoing? http://www.avrfreaks.net/index.php?name ... highlight=

And I was surprised by your card, as there are two Xals (a 16 Mhz and a 32.768khz) Mobz00 - Apr 22, 2013 - 01:45 PM Post subject: RE: AVR-MT128: Output PWM signal? I got it to work!

Here is the code I used

Code: //------//ADC initialisation // Conversion time: 112uS void adc_init(void){ ADCSRA = 0x00; //disable adc ADMUX = 0x00; //select adc input 0 ACSR = 0x00; //0x80 ADCSRA = 0x87; }

//------int readadchan(char n){ //read ch n of internal 10 bit a/d

ADMUX = n; ADMUX |=0b01000000; ADCSRA |=0x40; //init conversion while((ADCSRA & 0x40) !=0){}; //wait for conv complete return ADC; } void PWM_init(void){

DDRB = 0b00100000; TCCR1A = 0b10000010; TCCR1B = 0b00011010; TCCR1C = 0b00000000;

} void PWM_duty(int duty_procent,int Hz){

ICR1 = (2000000)/(Hz); //min 31Hz OCR1A = (Top/100)*duty_procent;

}

Thank you all for your help All times are GMT + 1 Hour Powered by PN phpBB2 © 2003-2006 The PNphpBB Group

Recommended publications