|
|
View previous topic :: View next topic |
Author |
Message |
jjude
Joined: 12 Nov 2007 Posts: 37
|
16F616 PWM stopped |
Posted: Thu Feb 04, 2010 2:27 am |
|
|
Code "input_c();" stopped PWM?!?
PWM run on, but when I write code "input_c();"
then PWM not run!
Why?
(PWM output in C5, compiler PCWH 4.099) |
|
|
Ttelmah Guest
|
|
Posted: Thu Feb 04, 2010 3:48 am |
|
|
TRIS.
You are using standard_io mode (the default). In this mode, the compiler automatically sets the TRIS register according to what you ask. You are asking the compiler to _read_ the whole of port C. Hence it sets TRIS so that the whole port is an input - al bits '1'.
If you look in the data sheet for the PWM, you will find a line like:
"In Pulse Width Modulation (PWM) mode, the CCP1 pin
produces up to a 10-bit resolution PWM output. Since
the CCP1 pin is multiplexed with the PORTB data latch,
the TRISB<x> bit must be cleared to make the CCP1
pin an output."
So the TRIS bit for the PWM output, needs to be a '0' for the PWM to work, and this is being overriden by trying to read the whole port.
Multiple routes round this:
1) Use Fast_io, or fixed_io modes. These put the responsibility onto _you_ to setup the TRIS correctly, but once done, the TRIS setting won't be overriden by reading the port.
2) Don't use the input_c function, but read the port directly. So something like:
Code: |
#ifdef __PCM__
#byte PORTC=7
#else
#byte PORTC=0xF82
#endif
//Then to read the port
val=PORTC;
|
This directly reads the port register (for PIC16/PIC18 devices), and bypasses the TRIS control, so that the TRIS direction will be left as it was.
3) Remember that you can _temporarily_ change IO mode.
So if you have:
Code: |
#use fast_io(c)
val=input_c();
#use standard_io(c)
|
The compiler will switch IO modes, just for the single input instruction, leaving TRIS as it is,and reading the value.
Best Wishes |
|
|
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
Powered by phpBB © 2001, 2005 phpBB Group
|