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] PWM signal duty cycle measurement with Capture module

Status
Not open for further replies.

Knife

Member level 2
Member level 2
Joined
Apr 26, 2009
Messages
43
Helped
1
Reputation
2
Reaction score
1
Trophy points
1,288
Visit site
Activity points
1,593
Hi everybody

I wanna measure PWM signal duty cycle with STM8S Capture Module. PWM signal duty is changing between 0% and 100%. System start 0%, 100% or any value between 0% and 100%.

I'm using capture interrupt and I'm measuring exact value of PWM duty. But I have a problem. If the system will start at 0% or %100, I can't handle that value. Because there isn't any changes of signal edge.

I have an idea. I can use one extra I/O port to control signal level. But I wanna ask you first, is there any software solution without using I/O pin ? Could we know capture pin level (high or low) ?
 

Assigning an alternate function to a pin (e.g. input capture) still allows you to read the input state through IDR, isn't it?
 

I haven't solved this problem yet. I tired to read IDR state before I asked here.

I used GPIO_ReadInputPin function. I used TIM1 Channel 1 so it is PC1 pin. GPIO_ReadInputPin(GPIOC, GPIO_PIN_1) function returns 0 when the PWM signal is 0% and 0x02 when the PWM signal is 100%. It should be 1 when the PWM signal is 100%, doesn't it ?



Code:
BitStatus GPIO_ReadInputPin(GPIO_TypeDef* GPIOx, GPIO_Pin_TypeDef GPIO_Pin)
{
    return ((BitStatus)(GPIOx->IDR & (uint8_t)GPIO_Pin));
}
 

First of all, thanks for your help. Yes, you are right. I figured out now. I was wrong because I used this code to check capture pin and It didn't work.

Code:
typedef enum {RESET = 0, SET = !RESET} FlagStatus, ITStatus, BitStatus, BitAction;

if(GPIO_ReadInputPin(GPIOC, GPIO_PIN_1) == SET)
PWM = 0xFFFF;

I changed the code this one and it works. I'm confiused because I think it is same.

Code:
if(GPIO_ReadInputPin(GPIOC, GPIO_PIN_1) != 0)
PWM = 0xFFFF;
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top