wierd simulation in porteus (pwm & pic 16f876)

Discussion in 'Embedded Systems and Microcontrollers' started by Chaabane, Jan 8, 2010.

  1. Chaabane

    Thread Starter Member

    Nov 30, 2009
    37
    0
    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)
     
  2. Dragonblight

    Active Member

    Aug 19, 2009
    35
    0
    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.
     
  3. Markd77

    Senior Member

    Sep 7, 2009
    2,803
    594
    Moonspeak, pah. Makes perfect sense to me.
    The problem is here:
    ADRESL is in bank 1.
     
    Last edited: Jan 8, 2010
  4. Chaabane

    Thread Starter Member

    Nov 30, 2009
    37
    0
    Sorry mate,but if you really ready to help me and check the code,i'll translate it to english

    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

    Code ( (Unknown Language)):
    1.  
    2. next_test
    3.     bsf        STATUS,RP0
    4.     btfss    ADRESL,6
    5.     return
    6.    [B] bsf         STATUS,RP0[/B]
    7.     bsf    [COLOR=Red]CCP1CON[/COLOR],CCP1X
    8.     return                 
    9.  
    Thanks for your help.
    but can't understand what's wrong with proteus !! or my code
     
  5. Markd77

    Senior Member

    Sep 7, 2009
    2,803
    594
    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.
     
  6. Chaabane

    Thread Starter Member

    Nov 30, 2009
    37
    0
    Thanks Markd77

    Anyone have an idea about this problem ?
     
  7. Hulk

    New Member

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

    Thread Starter Member

    Nov 30, 2009
    37
    0
    you mean i should sue C,Basic .....
     
  9. retched

    AAC Fanatic!

    Dec 5, 2009
    5,201
    312
    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.
     
  10. Hulk

    New Member

    Jan 12, 2010
    5
    0
    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! :)
     
  11. Chaabane

    Thread Starter Member

    Nov 30, 2009
    37
    0
    i guess motor control is a complex stuff ,that's why i should use assembly language
     
Loading...