# wierd simulation in porteus (pwm & pic 16f876)

Thread Starter

#### Chaabane

Joined Nov 30, 2009
37
Hello,
I'm trying to generate a PWM signal using PIC16F876
the cirtuit&code is very simple
1: read the variable resistor ( AD converter )
2: configure the PWM duty cycle with this value

but when i simulate the code in proteus.i found everything works just fine when i'm increasing the resistor value (from 0 to 10K)
but the PWM signal turns off when i decrease the resistor value
i didn't put any condition in the code...
i can't figure out what's wrong with it
please. I need help
i have uploaded the code and the circuit (attachment file)

#### Attachments

• 21.3 KB Views: 42

#### Dragonblight

Joined Aug 19, 2009
35
I'm just going to let everyone know that the code comments are in a form of moonspeak.

I think it's french.

And it lost the hell out of me.

#### Markd77

Joined Sep 7, 2009
2,806
Moonspeak, pah. Makes perfect sense to me.
The problem is here:
next_test
bsf STATUS,RP0
btfss ADRESL,6
return
bcf STATUS,RP0
bsf ADRESL,CCP1Y
return
ADRESL is in bank 1.

Last edited:
Thread Starter

#### Chaabane

Joined Nov 30, 2009
37
I'm just going to let everyone know that the code comments are in a form of moonspeak.

I think it's french.

And it lost the hell out of me.
Sorry mate,but if you really ready to help me and check the code,i'll translate it to english

Moonspeak, pah. Makes perfect sense to me.
The problem is here:
Quote:
next_test
bsf STATUS,RP0
btfss ADRESL,6
return
bcf STATUS,RP0
bsf ADRESL,CCP1Y
return
ADRESL is in bank 1.
you're right,its my mistake ...but i don't use this part of code .its just the less significant bit (bit9&bit8) for the PWM duty cycle.
and the right code is like this

Rich (BB code):
next_test
bsf        STATUS,RP0
btfss    ADRESL,6
return
bsf         STATUS,RP0
bsf    CCP1CON,CCP1X
return
Thanks for your help.
but can't understand what's wrong with proteus !! or my code

#### Markd77

Joined Sep 7, 2009
2,806
Sorry, I hoped that would be the problem. I don't use Proteus so I'm not sure what the problem is.
There are a few cosmetic things, like GOTOs to the next line and using the BANK macros, but I can't see anything obvious.

Thread Starter

#### Chaabane

Joined Nov 30, 2009
37
Thanks Markd77

Anyone have an idea about this problem ?

#### Hulk

Joined Jan 12, 2010
5
why the hack do you use assembler ??!!! This langage should die! And it should not be taught at school!

Thread Starter

#### Chaabane

Joined Nov 30, 2009
37
you mean i should sue C,Basic .....

#### retched

Joined Dec 5, 2009
5,208
I would use C. Or even basic.

If you code is goind to be simple, ie if you are not 'DOing' much and you KNOW you are going to be nowhere near the limis of your uCs memory, use an easier to interpret language. It really helps in the flocharting in the head. (Because when is the last time you saw a kid draw a chart?) Or a senior programmer for that fact.

chart:

POWERUP and INIT
---
READ AND CONVERT the POT
STORE the answer in variable SPEED
PWM the SPEED
GO BACK and READ again

there is a thousand ways to code it. Just make sure each point is checked off. Whilst trying to debug your assembler code, its like trying to speak a non-fluent language.

#### Hulk

Joined Jan 12, 2010
5
there are at least 1 million reasons for not using the assembly langage... Here are the mains one:

1. Unreadable
2. You change the micro your code is worthless
3. Slower than C (not optimised)
4. No Code reuse
5. Takes longer to code
6. Easier to make mistake
7. Very difficult to debug
8. Makes you buy a lot of aspirin!

Thread Starter

#### Chaabane

Joined Nov 30, 2009
37
there are at least 1 million reasons for not using the assembly langage... Here are the mains one:

1. Unreadable
2. You change the micro your code is worthless
3. Slower than C (not optimised)
4. No Code reuse
5. Takes longer to code
6. Easier to make mistake
7. Very difficult to debug
8. Makes you buy a lot of aspirin!
i guess motor control is a complex stuff ,that's why i should use assembly language