1. Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.
    Dismiss Notice

Can someone help me with the PWM instruction

Discussion in 'Oshonsoft' started by Winch, Oct 2, 2014.

  1. Winch

    Winch New Member

    Joined:
    Sep 5, 2014
    Messages:
    24
    Likes:
    0
    Dear all,

    I want to bring out a PWM signal to gate 6 of a PIC 16F628A.
    I have the following code written.

    Can someone help me?

    P.S. this code is first written in Proton, I'm trying to convert it to oshonsoft.
    In proton you can use the PWM instruction for every port, I hope this is also the case with oshonsoft?

    HTML:

    'DEVICE 16F628A

    Define CONFIG = 0x3f50

    AllDigital                    'alle ports digital

    'port names
    Symbol pwm_signaal = PORTA.6                    'this port is the PWM signal
    Symbol higherkey = PORTB.0                    'key to increase
    Symbol lowerkey = PORTB.1                    'key to decrease

    'declaring variable
    Dim duty As Byte                    'This variable contains the duty (PWM duty value)

    '76543210
    PORTA = %00000000                    'make all the gates of PORTA low
    TRISA = %10111111                    'PORTA.6 is output for PWM signal

    ConfigPin PORTB = Input                    'pull-up to activate the buttons
    PWMon 1, 10

    'mainprogram

    main:                    'loop

            If higherkey = 0 And duty < 250 Then duty = duty + 1                    'as on 'Higher Key "is pressed and value is still more, then increase it
           If lowerkey = 0 And duty >
    0 Then duty = duty - 1                    'as on 'Lower Key' is pressed and value is still not zero, then decrease it
           
            PWMduty 1, duty
           
    Goto main

    End                                              
     
     
  2. ericgibbs

    ericgibbs Well-Known Member Most Helpful Member

    Joined:
    Jan 4, 2007
    Messages:
    21,174
    Likes:
    644
    Location:
    Ex Yorks' Hants UK
    ONLINE
    hi,
    Oshonsoft Basic uses the internal hardware PWM on RB3.
    E
    it has a number of bit count and freq options, 2 examples
    PWMon 1, 9 '8bit 15625 hz
    ''PWMon 1, 3 '10bit 3906

    PWMduty 1, duty
     
  3. Winch

    Winch New Member

    Joined:
    Sep 5, 2014
    Messages:
    24
    Likes:
    0
    So PWMon sends the code directly to the CCP1!
     
  4. dave

    Dave New Member

    Joined:
    Jan 12, 1997
    Messages:
    -
    Likes:
    0


     
  5. ericgibbs

    ericgibbs Well-Known Member Most Helpful Member

    Joined:
    Jan 4, 2007
    Messages:
    21,174
    Likes:
    644
    Location:
    Ex Yorks' Hants UK
    ONLINE

    Look at this page from the Oshonsoft manual.

    PWmon set the PWM module number [ 1 only on your PIC], second digit sets the options , see the image.

    so, PWmon 1, 9'' module 1 option 9

    PWMduty 1, duty ' sets the PWM duty cycle.

    E
     

    Attached Files:

  6. Winch

    Winch New Member

    Joined:
    Sep 5, 2014
    Messages:
    24
    Likes:
    0
    Thanks it's fixed now.
     

Share This Page