PWM and sleep

Tip / Sign in to post questions, reply, level up, and achieve exciting badges. Know more

cross mob
Pippolo
Level 1
Level 1
5 sign-ins First reply posted First question asked

Hi,
I would like to use the  PSoC® 4 PIN configured as analog PWM.
It all works very well until it goes to sleep. When the board wakes up from sleep, the PWM pin doesn’t works.
I have tried to re initialized the PWM pin with PWM2_Wakeup function (defined in the board library) but without success.

Any idea?
Thanks

0 Likes
1 Solution
Bob_Marlowe
Level 10
Level 10
First like given 50 questions asked 10 questions asked

The _Sleep() and _Wakeup are used when you send the device into sleep or deepsleep mode which you do not use. The CyDelay() function just suspends execution of the code by entering a loop. Interrupts will get handled in that time. Best would be to create a workspace bundle (Creator->File->) and attach this to your forum posts. will be much easier to understand what's going on.

 

Bob

View solution in original post

0 Likes
7 Replies
Bob_Marlowe
Level 10
Level 10
First like given 50 questions asked 10 questions asked

Did you use PWM_Sleep() function before the board enters sleep mode?

 

Bob

0 Likes
Pippolo
Level 1
Level 1
5 sign-ins First reply posted First question asked
I tried to do the following sequence:
setup () {
...
PWM_start ()
...
}

loop () {
PWM_wakeup ()
delay (2000)
....
PWM_sleep ()
}
In the first cycle the PWM works perfectly,
from the second it no longer works.
Do I need to reset something?
The timers?
Thanks

 

0 Likes

What timers are you referring to? Whenever you want a component to survive sleep use the apropiate _sleep() and _wakeup() functions in that order.

Bob

0 Likes
Pippolo
Level 1
Level 1
5 sign-ins First reply posted First question asked

Hmmm ...

maybe the problem is in the analogWrite () function.
The first time I measure a voltage equal to 3.25 V (correct), the following measurements are wrong.

 

void loop()
{
  printf("Analog write\n\r");
  analogWrite(PWM1255);
  delay(2000);
  printf("PWM sleeping...\n\r");
  PWM1_Sleep();
  delay(2000);
  Serial.println("PWM restarting...\n\r");
  PWM1_Wakeup();
  delay(2000);
}
0 Likes
Pippolo
Level 1
Level 1
5 sign-ins First reply posted First question asked

Update ....

I tried to do some other tests to understand where is the problem.
In the code below I try to activate and deactivate PWM in a loop cycle.
When index "i" equals 3 or 4, I write using the analogWrite () function.
It can be seen that the voltage measured on the PWM pin is correct (3.25V) only for the first writing (i = 4) with the second and subsequent writing it is wrong.

int i=0;
void loop()
{
  
  printf("i=%d\n",i);
  if(i==3 || i==4){
    printf("Try to PWM write...\n");
    //PWM1_WriteCompare(62500);
    analogWrite(PWM1,255);
  } 
  delay(2000);
  printf("PWM sleeping...\n");
  PWM1_Sleep();
  delay(3000);
  Serial.println("PWM restarting...\n");
  //Serial.println(PWM1_ReadCompare());
  pinMode(pinBOOSTOUTPUT);
  PWM1_Wakeup();
  i=i+1;
  delay(2000);
 
}

 

 

0 Likes
Bob_Marlowe
Level 10
Level 10
First like given 50 questions asked 10 questions asked

The _Sleep() and _Wakeup are used when you send the device into sleep or deepsleep mode which you do not use. The CyDelay() function just suspends execution of the code by entering a loop. Interrupts will get handled in that time. Best would be to create a workspace bundle (Creator->File->) and attach this to your forum posts. will be much easier to understand what's going on.

 

Bob

0 Likes

Thanks Bob, this is the first time I use PSOC 4. I have to study a little .....
I really thank you very much

0 Likes