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

Sun Sep 25 2016, 04:41 AM
mira
hi sir, could you help me regarding simple multiplication calculator?it should be include with buzzer. i use dragonplus. please
ExperimenterUK
Sat Sep 24 2016, 05:49 PM
@Rus Ans .. what project ?
ExperimenterUK
Sat Sep 24 2016, 05:48 PM
@engr1931 depends on type of scanner
engr1931
Sat Sep 24 2016, 03:07 PM
Is it possible to send data from 2 barcode scanner to pc using serial port using 8051?
Wed Sep 21 2016, 02:22 AM
Rus Ana
can anyone help me for my project? T.T
Fri Sep 09 2016, 02:54 PM
Sarath babu
8051 a/c motor speed control
Tue Aug 30 2016, 05:03 PM
Kinzang
hello sir, can i know more in detail about the football substitution board project.
Tue Aug 30 2016, 06:06 AM
bhagyashri buddhewad
my project is automatic room light controller using visitor counter so i want coding in keil and circuit diagram can tell me and i want to use uc at89c51 thanks you
ExperimenterUK
Sun Aug 28 2016, 08:32 PM
Which project ?
Sun Aug 28 2016, 05:21 AM
Dipankar Baishya
Hi sir.... I want do this project but I have not this sercuit diagram..... can you give me full details and diagram...... Thank you

Downloads

Comments

Wotszat
Thu Sep 29 2016, 06:31 AM
ak_pan
Thu Sep 08 2016, 06:28 PM
martinsnc115877
Sat Aug 20 2016, 01:44 PM
rajavarmanslr
Thu Aug 18 2016, 12:24 PM
CASINODIGITAL
Mon Aug 15 2016, 09:04 PM
mariahcarey
Sat Aug 06 2016, 11:38 AM
dann11
Thu Jul 28 2016, 09:43 PM
adithyapaip
Thu Jul 21 2016, 05:45 PM

Online

Guests: 39, Members: 0 ...

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

Members: 37782
Newest member: Wotszat
Forum Activity
martinsnc115877 Avatar
Posted By martinsnc115877
Wed Sep 14 2016, 12:51 PM
sir, i did your led scrolling mass display, and it...
ExperimenterUK Avatar
Posted By ExperimenterUK
Fri Sep 09 2016, 11:45 PM
The Hex file for this project is a bit too big for...
rajavarmanslr Avatar
Posted By rajavarmanslr
Thu Aug 18 2016, 01:40 PM
I have two 8051 that interfaces with nRF24l01. One...
rajavarmanslr Avatar
Posted By rajavarmanslr
Thu Aug 18 2016, 12:31 PM
I have two 8051 that interfaces with nRF24l01. One...
ExperimenterUK Avatar
Posted By ExperimenterUK
Mon Aug 01 2016, 05:26 AM
is working nowugoo5000Great, thanks for letting u...
ugoo5000 Avatar
Posted By ugoo5000
Sat Jul 30 2016, 07:31 AM
is working noworg 00hmov p1,#11111111bmov p3,#1111...
ugoo5000 Avatar
Posted By ugoo5000
Sat Jul 30 2016, 06:40 AM
when i press a button in p3.0,the counter will st...
ugoo5000 Avatar
Posted By ugoo5000
Sat Jul 30 2016, 06:30 AM
proteus file Attachment ...
ExperimenterUK Avatar
Posted By ExperimenterUK
Fri Jul 29 2016, 11:34 PM
Your code does not count at all, it produces a one...
ugoo5000 Avatar
Posted By ugoo5000
Fri Jul 29 2016, 07:49 PM
i want the the counter to be counting in secs with...