qwwe
Joined: 17 Sep 2017 Posts: 59
|
Why the function #USE pwm () does not work correctly |
Posted: Wed Nov 22, 2017 1:05 am |
|
|
Hi, I wrote the following program to create a wave pwm by activating the c7 pin on the pin output a2.
The wave is generated correctly, but when I deactivate the c7 pin, the output voltage level of the pin a2 is one.
This is while I want it to be zero.
I used disable_level=low, but again when off the pwm, the output level of the a2 pin is one.
Code: |
#include <16f1829.h>
#device *=16
#fuses HS //High speed Osc (> 4mhz for PCM/PCH)
#fuses NOWDT //NO Watch Dog Timer
#fuses PUT //Power Up Timer
#fuses NOLVP //No low voltage programing
#fuses NOCPD //No EE protection
#fuses NOPROTECT //Code not protected from reading
#fuses NOWRT //Program memory not write protected
#fuses NODEBUG //No Debug mode for ICD
#fuses NOBROWNOUT //No brownout reset
#USE DELAY (crystal=11059200)
#USE pwm(OUTPUT=PIN_A2,timer=2,FREQUENCY=500Hz,DUTY=99,disable_level=low)
#include <stdio.h>
#include <string.h>
void main()
{
set_tris_c(0b11111111);
set_tris_a(0b11111011);
while(TRUE)
{
if(input(PIN_C7)==1)
{
pwm_on();
}
if(input(PIN_C7)==0)
{
pwm_off();
}
}
}
|
Thank you for answering. |
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19515
|
|
Posted: Wed Nov 22, 2017 2:13 am |
|
|
When you turn the PWM off, it is disconnected from the pin.
The ECCP peripheral does support being overridden to a level. The CCP doesn't. You are using CCP3, which is a standard CCP.
Simply set the idle level on the pin. This then determines what appears when the PWM is turned off. |
|