Menu

Soft_PWM not work

Help
2013-01-15
2013-05-30
  • alejandro1957

    alejandro1957 - 2013-01-15
    #CHIP 16F877A,4
    #CONFIG OSC=XT,WDT_OFF,PWRTE_ON,CP_OFF,DEBUG_OFF,WRT_OFF,CPD_OFF,LVP_OFF,BODEN_ON
    SUB Impulso()#NR
    DIM Cuenta AS INTEGER
    Cuenta=12           ''For 300 us
    Ciclo_us:
      BSF    PORTD,2
      NOP
      NOP
      NOP
      NOP
      NOP
      NOP
      NOP
      NOP
      NOP
      BCF    PORTD,2
      NOP
      NOP
      NOP
      NOP
      NOP
      NOP
      NOP
      NOP
      NOP
      DECFSZ Cuenta,F
      GOTO   Ciclo_us
    END SUB
    Inicio:
       TRISA=b'000000'
       TRISB=b'00000000'
       TRISC=b'00000000'
       TRISD=b'00000000'
       TRISE=b'00000000'
       PORTA=b'000000'
       PORTB=b'00000000'
       PORTC=b'00000000'
       PORTD=b'00000000'
       PORTE=b'00000000'
       INTCON=b'00000000'
       CVRCON=b'00000000'
       CCP1CON=b'00000000'
       CCP2CON=b'00000000'                                                      
       ADCON0=b'00000000'
       ADCON1=b'10000110'
       SET PORTB.1 ON
       DO
         Impulso()
         WAIT 200 s
       LOOP
    

    work,but strangely using this soft pwm to 40 khz the ultrasonic sensor has less lift that when I use the PWM module hardware.

    SUB Impulso()#NR
    HPWM 2,40,127
    WAIT 300 us
    END SUB
    Inicio:
       .
       .
       CCP1CON=b'00001100'
       .
       .
       DO
         Impulso()
         WAIT 200 s
       LOOP
    
     
  • alejandro1957

    alejandro1957 - 2013-01-15

    the two modules pwm hardware are in use to control a l298a mode in LAP.

    sorry for my english

     
  • alejandro1957

    alejandro1957 - 2013-01-16

    now it works.
    even if you give me problems with the TMR1 interrupt.
    all right with the interrupt INT0.
    I'm thinking of a NE555 for a burst to 40Khz.

     
  • alejandro1957

    alejandro1957 - 2013-01-16

    this is the code

    #CHIP 16F877A,4
    #CONFIG OSC=XT,WDT_OFF,PWRTE_ON,CP_OFF,DEBUG_OFF,WRT_OFF,CPD_OFF,LVP_OFF,BODEN_ON
    On Interrupt ExtInt0 Call Interrupt_RB0
    SUB Impulso(Cuenta AS BYTE)#NR
    Ciclo_us:
         NOP
         NOP
         NOP
         NOP
         NOP
         NOP
         NOP
         NOP
         NOP
         BSF  PORTD,2
         NOP
         NOP
         NOP
         NOP
         NOP
         NOP
         NOP
         NOP
         NOP
         NOP
         BCF  PORTD,2
         DECFSZ Cuenta,F
         GOTO Ciclo_us
    END SUB
    SUB Interrupt_RB0()#NR
    IntOFF
    DO
    LOOP UNTIL PORTB.0=1
    IF Flag=0 THEN
       Flag=1
    ELSE
       Flag=0
    END IF 
    IntON
    END SUB
    Inicio:
       TRISA=b'000000'
       TRISB=b'00000001'
       TRISC=b'00000000'
       TRISD=b'00000000'
       TRISE=b'00000000'
       PORTA=b'000000'
       PORTB=b'00000000'
       PORTC=b'00000000'
       PORTD=b'00000000'
       PORTE=b'00000000'
       INTCON=b'10010000'
       OPTION_REG=b'11000000'
       CVRCON=b'00000000'
       CCP1CON=b'00000000'
       CCP2CON=b'00000000'                                                      
       ADCON0=b'00000000'
       ADCON1=b'10000110'
       Flag=0
       ALTO: 
            SET PORTB.1 OFF
       IF Flag=0 THEN GOTO ALTO
       SET PORTB.1 ON
       DO
          Impulso(0x0C)
       LOOP UNTIL Flag=0
       GOTO ALTO
    
     

Log in to post a comment.

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.