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

ExperimenterUK
Wed May 25 2016, 05:05 AM
@ Ramanjaneyulu, post in forum,explain your problem
Mon May 23 2016, 11:34 PM
Ramanjaneyulu
Hi, I Am using at89c4051 for my application, I want 5u sec dely.. Up to 1milli sec iam able to producing delay. Beyond the 1milli second, I am unable to produce the acceurate dely. Plz any one help me
Sat May 21 2016, 09:51 PM
A K
i want to mak an auto dialer using gsm and atmega 16. please helpe me how to write a code to auto dial a number saved in sim
Sat May 21 2016, 10:42 AM
Alec
Hi im trying to program my 89s51 with a usbasp so any ideas on the circuit?
Wed May 18 2016, 10:08 AM
Tashu joshi
anyone know how to develop
Wed May 18 2016, 10:07 AM
Tashu joshi
i'm working for resporatry system using 8051,
Wed May 18 2016, 10:06 AM
Tashu joshi
i'm developing a respiratory system using Arduino
Fri May 13 2016, 11:03 AM
MEGHANA
i need c code for counting frequency of two sensors and compare these frequencies and it has to give high/ low signal after comparision
ExperimenterUK
Tue May 10 2016, 05:02 PM
@Suren ..create a thread in the 8051 Discussion Forum to discuss your problem
Tue May 10 2016, 04:04 PM
Suren Avushyan
how can I increment address not the content of it, like 0x70 and get 0x71

Downloads

Comments

zaft93
Sun May 15 2016, 01:52 AM
CELEBI
Thu May 12 2016, 08:28 AM
Suro1996
Wed May 11 2016, 06:07 PM
yigithan
Sat May 07 2016, 09:09 PM
jaque
Fri May 06 2016, 07:51 PM
afzal42
Wed May 04 2016, 11:16 AM
pd
Sun May 01 2016, 01:35 AM
uk2308
Fri Apr 29 2016, 12:27 PM

Online

Guests: 41, Members: 0 ...

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

Members: 37765
Newest member: zaft93
Forum Activity
ExperimenterUK Avatar
Posted By ExperimenterUK
Sun May 15 2016, 10:58 PM
zaft93 Avatar
Posted By zaft93
Sun May 15 2016, 01:55 AM
ExperimenterUK Avatar
Posted By ExperimenterUK
Fri May 13 2016, 07:59 PM
If you want only one relay to be on at a time the ...
CELEBI Avatar
Posted By CELEBI
Fri May 13 2016, 06:16 AM
Yes. It must be as you said. It must be 1.5 second...
ExperimenterUK Avatar
Posted By ExperimenterUK
Thu May 12 2016, 08:35 PM
Here is one way.If you have the Keil compiler you ...
ExperimenterUK Avatar
Posted By ExperimenterUK
Thu May 12 2016, 05:20 PM
Sorry I don't understand what you want.Is that 1.5...
CELEBI Avatar
Posted By CELEBI
Thu May 12 2016, 08:53 AM
Hello Guys, I want to make a Project with 89s51 bu...
ExperimenterUK Avatar
Posted By ExperimenterUK
Wed May 11 2016, 09:28 PM
No this is all I've got, the algorithm I think is ...
Suro1996 Avatar
Posted By Suro1996
Wed May 11 2016, 09:27 PM
Is this all the code you have ?As it is, it will n...
Suro1996 Avatar
Posted By Suro1996
Wed May 11 2016, 07:31 PM
Hello, I am new to assembly programming and I am h...