Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

[SOLVED] After stopping the Timers, the ports are at random position although they are forced

Status
Not open for further replies.

Pushpkant

Member level 1
Joined
May 17, 2014
Messages
39
Helped
2
Reputation
4
Reaction score
2
Trophy points
8
Location
India
Activity points
451
Hello,
I am using timer 0 and timer 1 for pwm waveform generation. Until the pwm is running all is well and good. But when I stop the pwm, the ports associated with pwm are land on some random position either low or high. I have given the code to low the ports but still the ports are at random position each time I stop the pwm.


Code C++ - [expand]
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
prints("Down called:");phline();
            
pwm_0.stop();
pwm_1.stop();
            
_delay_ms(1);
            
prints("Pwm stopped:");phline();
            
            
            
prints("Before reset");phline();
prints("PORTD =");
USARTWriteNumBinary(PIND);
phline();
prints("PORTB =");
USARTWriteNumBinary(PINB);
phline();
            
//_delay_ms(1000);
    
CLR_BIT(PORTD,PD5);
CLR_BIT(PORTD,PD6);
            
CLR_BIT(PORTB,PB1);
CLR_BIT(PORTB,PB2);
             
/*PORTD &= 0x9F;
PORTB &= 0xF9;*/
            
prints("The ports has been reset:");phline();
prints("PORTD =");
USARTWriteNumBinary(PIND);
phline();
prints("PORTB =");
USARTWriteNumBinary(PINB);
phline();



I have tried to give delay ranging from 1 ms to 1000 ms. Used different types of techniques for lowering the ports. But at each time the code executes the ports are at random positions. The ports are PD5, PD6, PB1 and PB2.
Thanks in advance for your help.
 

You didn't even mention the processor type...

We can just guess that you have setup PWM operation somehow, not shown in the posted code snippet. Stopping the timer doesn't release this connection, apparently neither a simple port write. A similar behavior would be observed with many processors implementing port mux, it's not surprising so far. You need to reprogram the port mode.
 
You are only showing part of the complete code. It is not clear if there is any other section of the program (eg interrupt handler) that might be reloading the duty-cycle value, and consequently returning those pins from general I/O to dedicated PWM outputs.
 

We can just guess that you have setup PWM operation somehow, not shown in the posted code snippet. Stopping the timer doesn't release this connection, apparently neither a simple port write. A similar behavior would be observed with many processors implementing port mux, it's not surprising so far. You need to reprogram the port mode.

Thanks FvM,

The processor is atmega328p microcontroller.
There is a problem with the "stop" method of "pwm" class. In the stop method only clock source has been disconnected from PWM but the ports are not reconnect to GPIO. I have changed the code and now it's working fine.
Thanks again
 

Status
Not open for further replies.

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top