Continue to Site

Welcome to our site!

Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

  • Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

8051 PWM with keypad entry

Status
Not open for further replies.

LApprenti Sorcier

New Member
Hi!

I'm studying the 8051 microcontroller and I'm trying to build a circuit that will give me a PWModulated output. Something like a 100-micro-second period. To be modulated on 1% increments.
I also need to be able to give the 8051 a percentage by means of a numeric keypad. It would be nice to have an LCD display on which to read the current setting.

I have some experience on the 8051, but have never used a keypad or LCD display.

Anyone, a suggestion on where to start?
 
Use P89C51RD2 which has hardware PWM generator. Otherwise with software you won't get 100uS period.
For tutorials on 8051 visit www.8052.com
 
Hi!

Why can't I get a 100us period? I don't need it to be 100U sharp, just about that. But now that I think about it, I could use nything up on the ms range. 50ms is not bad...

What I need is to digitally (keypad input) control the pulse width, but after having processed that input

i.e. The input will be a speed in rpm, the microcontroller has to calculate the necessary PW based on known parameters, modify the pulse width and well... output it.

Later on I will need to use an ADC to read a voltage, input it to the 8051 and use that datum to recalculate the PW in real time. So I could use some help with that too.

Thanks!
 
Well,if you insist on applying a software real-time PWM,you may have to use timer interrupts and do something with its parameters and service subroutines.Keypads and LCDs are nothing really difficult to handle.If you wish to set 10 keys(0-10)plus some function keys,you better scan them in rows and columns,which requires the MCU to keep an eye on any event on the kepad.You may use some tricks like arranging an INT pin in the key array and use an external interrupt to report a key event.You will worry less about an LCD than about the keypad.There're lots of LCMs in the market,pick up one and do a web search for its driver chip.And you will get everything you need to know to interface it with your MCU.
 
What are you actually trying to use the PWM to do?.

As already suggested, using a processor with hardware PWM would make your job trivial - doing it in software makes it all dependent on what else the processor is doing. Even using interrupts to generate the PWM will require careful thought, in order not to introduce jitter in the PWM.

But again, what is the PWM for, and does a little jitter matter?.

Perhaps not much help, but a PIC16F628 would do the job easily in one small 18 pin package! - seven pins for LCD, seven for numeric keypad, one for PWM output - even one pin to spare!.
 
For example,I just finished building an 8 channel battery managing device for my own use.Each channel has a transistor for charging control and another one for discharging.Altogether,16 I/O ports were required to control this device.Current is regulated with PWM.Finding a chip with 16 channels of hardware is highly unlikely and totally unnecessary(batteries don't need high frequency during maintainance operation,and they don't care about jitter).So I used a 89S51 to generate multiple PWM signals with software,something mainly based on loops.This MCU works as a slave and the host transmits PWM parameters of each channel through the serial interface.When a serial interrupt occurs,the service subroutine shuts down all functioning I/O ports,switching off all transistors,and then PWM parameters are updated.During this period of time.there's no PWM output,and it is a little jitter.If your device doesn't mind temporary dissappearance of the PWM signal,you won't have too much to worry about then.But Nigel's suggestion is still the ideal one for this project.My example might work on a similar case should you come across one in your future works.
 
Well,

I'm driving a small DC motor (through a power transistor) with the PWM, obviously PWM will variate the speed.

How long does that jitter last for your system?

The problem is, I'm getting experience on the 8051, and know nothing else about the other stuff you've all told me about. I'm running out of time and need a real quick solution for this project. If you think I can manage it faster, please give me more details.

Thank you all!
 
Ok now,

:idea: I'm getting interested on the 89C51RD2. I'm studying the datasheet but can you answer a couple of questions for me?

Can you modify the duty cycle in real time with the integrated PWM? or do you need to stop it or something?

:?: Do you know where I can find some tutorial or something to help me master this faster?
I still have to go look at www.8052.com but if you can suggest me anything else...

Thanks again!
 
I bet you won't think about a software PWM any more when you have an MCU with hardware module.I've never used 89C51RD2,but on seing your reply,I downloaded and read its PDF document.It will work for you.So let's forget about how long that jitter lasts for my system.
A hardware PWM is easy to handle,don't fear it.You simply need to access several relative registers to set the desired parameters of the PWM,and start this function by enabling the timer and PWM output.It works almost the same way for all MCUs with hardware PWM.All you need to learn is how these registers affect the PWM's frequency and duty cycle.Refer to the PWM section of the datasheet of your MCU.It won't take you much time to master such technique. :)
 
Yes, they are simple to use - the main 'problem' is setting them up in the first place - then using it is as simple as writing the value you want to a single register (at least for a PIC and 8 bit resolution).
 
LApprenti Sorcier said:
Ok now,

:idea: I'm getting interested on the 89C51RD2. I'm studying the datasheet but can you answer a couple of questions for me?

Can you modify the duty cycle in real time with the integrated PWM? or do you need to stop it or something?

:?: Do you know where I can find some tutorial or something to help me master this faster?
I still have to go look at www.8052.com but if you can suggest me anything else...

Thanks again!
You can dynamically change the duty cycle of PWM by chaging the contents of one of the registers. You'll find the coding details in thin PCA CookBook from Intel.
http://www.ife.tugraz.at/datashts/intel/27085101.pdf

LCD tutorial at
**broken link removed**

Now that you have all the code snippets ready, put them together to complete your task. Get back if you are stuck.
 
Hi!

Question:

:?: How much more expensive than the starndard 89C51 do you think the 89C51RD2 can be?

I've been reading and all this Flash memory issue and additional thingies sound quite fancy (= expensive).

:?: Also, how common is it? (Hope it's not too difficult to find) Maybe this info won't work for Mexico, but at least as reference...

Does anyone know?

:arrow: Please also give me the price for a conventional 89C51, for example ATMEL's AT89C51 for comparison.

I live in Guadalajara, México. I buy AT89C51's by $50 - $60 pesos (something like $5 USDollars). I expect they are much more expensive than in the US... I just hope the 89C51RD2 won't be much more expensive than this one...

Thanks!
 
89C51RD2 is priced at about about 2.7 times the price of 89C51. But I think its worth for the features it provides and development time it saves.

Over here in India it is quite popular and available very easily.
The AT89C51 costs about 65 INR (~$1.5) while P89C51RD2 costs 180 INR (~$4.1$)
 
US$5!That's expensive.Here in China,an 89C51 used to cost about US$1.5.And it has ceased production if I'm not mistaking.Now I used 89S5x instead,with WDT and ISP features added.A 89S51 costs 8.5 yuan in DIP-40 package and 7 yuan in QFP package,both less than 1 usd.Never bought an RD2,but just refer to your local electronics dealers's price list.
 
Alex_rcpilot said:
US$5!That's expensive.Here in China,an 89C51 used to cost about US$1.5.And it has ceased production if I'm not mistaking.Now I used 89S5x instead,with WDT and ISP features added.A 89S51 costs 8.5 yuan in DIP-40 package and 7 yuan in QFP package,both less than 1 usd.Never bought an RD2,but just refer to your local electronics dealers's price list.
Who mentioned $5??? I said 89C51/89S51 costs approxmiately $1.5 not $5.
Who mentioned $5??? I said 89C51 cost $1.5. And yes the new 89S51 also costs the same.
 
LApprenti Sorcier said:
Hi!

Question:
I live in Guadalajara, México. I buy AT89C51's by $50 - $60 pesos (something like $5 USDollars).
Thanks!

kinjalgp said:
Who mentioned $5??? I said 89C51 cost $1.5. And yes the new 89S51 also costs the same.

Obviously our friend LApprenti Sorcier has mentioned $5,sometimes we do miss out some words,but it's okay.I was just wondering why it costs so much in Mexico.Is it because the 89C5x chips are going to be sold out?
I hope LApprenti Sorcier will get a good price for other MCUs.
 
sumit

i want to interface 89C51RD2 micro controller in my system and control motor using this micro controller. my system is like this first sensor sense the revolution of shaft i am using AS5030 magnetic rotary sensor this sensor generate PWM and i apply this PWM to 89V51RD2 so i want to help from your side which type of code i wrote in micro controller for PWM timing counting.
 
Status
Not open for further replies.

New Articles From Microcontroller Tips

Back
Top