Discussion in "8051 Discussion Forum" started by    neil03    Aug 5, 2009.
Wed Aug 05 2009, 07:33 PM
#1
hi im working on a PWM signal output from a microcontroller using at89c2051.
The status of my project is that I successfully produce the desired PWM signal but, my problem is I cannot stop the process of stopping the PWM signal when I switch it to stop.
____________________________________________________________________
The algorithm of the program is simply like this

1. when switch 1 is pressed the microcontroller produce a PWM signal
2. when switch 2 is pressed the micrcontroller stop producing the signal or clearing the output pin of the MC.
____________________________________________________________________
Now as I have said above I successfully produce the desired PWM signal but when I switch it to stop. The PWM output pin remains to produce the PWM signal..Honestly this program is really working previously and I have used this program several times ago but now when I try to burn it on a new microcontroller it doesnt respond to its previous state.. I also try to change different at89c2051, 3 mc to be exact, but still im getting the same problem..
Im thinking that the maybe the programmer have a defect or something, but im not so sure and I dont want to take the risk of buying a new programmer cause it costs alot.

Can anybody help me to find what is the problem causing this and please teach me to resolve it..I have attach the program and the schematic of my project. please help me people thank you so much.
 switch1   EQU P1.2     ; switch for PWM
 switch2   EQU P1.3		; switch for stop PWM signal
 PWMPIN    EQU P3.4      ; PWM output pin 

ORG 00H
SJMP Main

org 0BH ;Vector address for Timer0
AJMP TIMER_0_INTERRUPT ;jump to ISR routine

;Main code
Main:
JB  P1.2, PWM_INI ; go to PWM setting 1
sjmp Main

PWM_INI:         ;initiate PWM
acall PWM_SETUP 
here:
JB   P1.3, STOP;
SJMP here ;

STOP:
clr PWMPIN
sjmp Main;


PWM_SETUP:
        MOV TMOD,#00H           ; Timer0 in Mode 0
        MOV R7, #240            ; Set pulse width control
        ; The value loaded in R7 is value X as
        ; discussed above.
        SETB EA         ; Enable Interrupts
        SETB ET0                ; Enable Timer 0 Interrupt
        SETB TR0                ; Start Timer
        RET

TIMER_0_INTERRUPT:
        JB F0, HIGH_DONE        ; If F0 flag is set then we just finished
                                ; the high section of the
LOW_DONE:                       ; cycle so Jump to HIGH_DONE
        SETB F0                 ; Make F0=1 to indicate start of high section
        SETB PWMPIN             ; Make PWM output pin High
        MOV A, #0FFH            ; Move FFH (255) to A
        CLR C                   ; Clear C (the carry bit) so it does
                                 ; not affect the subtraction
        SUBB A, R7              ; Subtract R7 from A. A = 255 - R7.
        MOV TH0, A              ; so the value loaded into TH0 + R7 = 255
		CLR TF0                 ; Clear the Timer 0 interrupt flag
        RETI                    ; Return from Interrupt to where
                                        ; the program came from
HIGH_DONE:
        CLR F0                  ; Make F0=0 to indicate start of low section
        CLR PWMPIN              ; Make PWM output pin low
        MOV TH0, R7             ; Load high byte of timer with R7
                                ; (pulse width control value)
        CLR TF0                 ; Clear the Timer 0 interrupt flag
        RETI                    ; Return from Interrupt to where
                                ; the program came from




END






[ Edited Wed Aug 05 2009, 07:35 PM ]
Wed Aug 05 2009, 07:51 PM
#2
well schematic is not so big to have a problem in it.

You can load a simple LED blink program to see if your controller is fine or not.

I think problem seems to be in program for making it non stop PWM. the reason is.. PWM works with timer so along with clearing of PWM pin, you should also clear TR0, and TF0 so that timer stops and interrupt flags can be cleared. and to start PWM again, you have the init function.

[Topic moved to 8051 Discussion forum]
Thu Aug 06 2009, 02:07 AM
#3
You'll also have to make sure the SW1 switch is off else the pwm generation will start again.
better implement sth like this....
Main:
JNB  P1.2, Main;check if START is pressed
JNB P1.3,PWM_INI ; go to PWM setting 1 if STOP not pressed
sjmp Main

Get Social

Information

Powered by e107 Forum System

Conversation

ElectronicManiac
Tue Mar 31 2015, 03:33 PM
anyone?
ElectronicManiac
Tue Mar 31 2015, 03:33 PM
Please Reply me on Scrolling Dot Matrix LED Display using 8051
Tue Mar 31 2015, 10:32 AM
Akshayy
Can you please provide the proteus file
ajay_bhargav
Tue Mar 31 2015, 04:14 AM
@Peter james, we have many projects related to this, Please refer download section and tutorials or post in forum for specific questions.
Mon Mar 30 2015, 04:51 PM
Peter james
can any one provide me an assembly language program to interface with 16x2 LCD, 4X4 Keypad and a GSM Module to recieve message and display it.
ajay_bhargav
Mon Mar 23 2015, 04:22 AM
You can only simulate simple 8051. RD2 support is not there in proteus. However there are similar atmel varient which can be used instead.
Sun Mar 22 2015, 07:24 PM
Aryan Nath
How can i Simulate microcontroller project in Proteus that uses P89V51RD2
Thu Mar 19 2015, 02:45 PM
Peter Mann
I have tried to register on the site, but it keeps saying I've entered two different email adresses - but I haven't!
ajay_bhargav
Sun Mar 15 2015, 08:25 PM
I did not get new message indication.. strange..
ExperimenterUK
Sun Mar 15 2015, 08:18 PM
slight delay, my connection failed

Downloads

Comments

sund1212
Tue Mar 31 2015, 04:47 PM
ElectronicManiac
Tue Mar 31 2015, 03:21 PM
harix
Sun Mar 29 2015, 07:11 PM
marti
Fri Mar 27 2015, 03:07 PM
iamalien
Thu Mar 26 2015, 07:27 AM
Ankit30
Wed Mar 25 2015, 02:35 PM
wai1023
Wed Mar 25 2015, 06:27 AM
StrangerDanger
Tue Mar 24 2015, 12:40 PM

Online

Guests: 24, Members: 0 ...

most ever online: 182184
(Members: , Guests: 182184) on 06 Aug 2010: 05:37 AM

Members: 37613
Newest member: sund1212
Forum Activity
diana1234 Avatar
Posted By diana1234
Tue Mar 31 2015, 11:17 AM
Thank you sir for the reply,As you give the LED ex...
mayank058 Avatar
Posted By mayank058
Tue Mar 31 2015, 06:44 AM
Dear Iamalien, Thank you ...
mayank058 Avatar
Posted By mayank058
Tue Mar 31 2015, 06:33 AM
Thanks to all of u for showing your interest in my...
iamalien Avatar
Posted By iamalien
Tue Mar 31 2015, 04:43 AM
here you go a 227 variable array in the ram and st...
ajay_bhargav Avatar
Posted By ajay_bhargav
Tue Mar 31 2015, 04:33 AM
Can you post Keil compiler output?
iamalien Avatar
Posted By iamalien
Tue Mar 31 2015, 04:31 AM
i have already compiled the program in keil thats ...
ajay_bhargav Avatar
Posted By ajay_bhargav
Tue Mar 31 2015, 04:29 AM
Its in nature of resistor to reduce the current wh...
ajay_bhargav Avatar
Posted By ajay_bhargav
Tue Mar 31 2015, 04:10 AM
256 bytes ram for 200 char display... I think you ...
diana1234 Avatar
Posted By diana1234
Mon Mar 30 2015, 08:12 AM
Dear sir,How a resistor can be used as a current l...
ExperimenterUK Avatar
Posted By ExperimenterUK
Mon Mar 30 2015, 05:13 AM
The processor on the MCB2300 has a built in DAC.Cr...