View previous topic :: View next topic |
Author |
Message |
Damien
Joined: 03 Jun 2015 Posts: 2
|
problem PWM |
Posted: Wed Jun 03, 2015 9:07 am |
|
|
Hello, I have a problem with the function:
#use PWM
It doesn't work (i have no signal).
I work with the PIC 16f1459 and I have the version 5.007
My program is:
Code: |
#include <16F1459.h>
#device ADC=10
#Fuses INTRC_IO
#use delay(clock=8MHZ)
#use i2c(master, SCL=PIN_C1, SDA=PIN_C0)
#use PWM (OUTPUT=PIN_C5, TIMER=2, FREQUENCY=10kHz)
void main()
{
pwm_on();
pwm_set_frequency(10000);
pwm_set_duty_percent(500);
while (true);
}
|
|
|
|
asmboy
Joined: 20 Nov 2007 Posts: 2128 Location: albany ny
|
|
Posted: Wed Jun 03, 2015 12:15 pm |
|
|
what does the .LST file show for your code ??
or if you use PIN_C5? |
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19499
|
|
Posted: Wed Jun 03, 2015 12:42 pm |
|
|
I can confirm that the problem is the old compiler is not setting the PWM1CON bits. 5.010, which is the oldest I have kept also does not.
So:
Code: |
#include <16F1459.h>
#device ADC=10
#Fuses INTRC_IO
#use delay(clock=8MHZ)
#use i2c(master, SCL=PIN_C1, SDA=PIN_C0)
#use PWM (PWM1,OUTPUT=PIN_C5, TIMER=2, FREQUENCY=10kHz,STREAM=P1)
//tell it to use PWM1
#byte PWM1CON=getenv("SFR:PWM1CON")
//PWM1CON register
void main()
{
pwm_on(P1);
pwm_set_frequency(P1,10000);
pwm_set_duty_percent(P1,500);
PWM1CON=-0xC0; //enable output
while (true)
;
}
|
Appears to set everything up correctly...
Understand that 5.007, was _beta_ at best. |
|
|
Damien
Joined: 03 Jun 2015 Posts: 2
|
|
Posted: Thu Jun 04, 2015 9:08 am |
|
|
Thank you.
It don't work, i see the "watch" and PWM1CON=0xE0
not 0xC0 ...
I have a signal but it is a pulse inverse with approximately 100Hz and low signal 10us length and high signal approximately 10ms length. |
|
|
|