Continue to Site

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.

  • 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.

Can someone help me with the PWM instruction

Status
Not open for further replies.

Winch

Member
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
 
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
 
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
 

Attachments

  • AAesp02.gif
    AAesp02.gif
    26.6 KB · Views: 378
Status
Not open for further replies.

Latest threads

New Articles From Microcontroller Tips

Back
Top