- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hi
I am having problems changing a timer write period on the fly please see attached
Best Regards
David
- Labels:
-
PSoC 4 Architecture
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hi,
Only providing the part of function makes it difficult to understand the problem.
It would be better to provide some small working (or not working) whole project.
Having said that I tried to play with your code.
With some tweaks it seems working with "my" way...
============================
#include "project.h"
#include <stdio.h>
#include <stdlib.h>
/*****************************************
Notes
Freq (Hz)
A 220.000 440.000 880.000
A#/Bb 233.082 466.164 932.328
B 246.942 493.883 987.767
C 261.626 523.251 1046.502
C#/Db 277.183 554.365 1108.731
D 293.665 587.330 1174.659
D#/Eb 311.127 622.254 1244.508
E 329.628 659.255 1318.510
F 349.228 698.456 1396.913
F#/Gb 369.994 739.989 1479.978
G 391.995 783.991 1567.982
G#/Ab 415.305 830.609 1661.219
Period in us
A 4545.45 2272.73 1136.36
A#/Bb 4290.34 2145.17 1072.58
B 4049.54 2024.77 1012.38
C 3822.26 1911.13 955.56
C#/Db 3607.73 1803.86 901.93
D 3405.24 1702.62 851.31
D#/Eb 3214.12 1607.06 803.53
E 3033.73 1516.86 758.43
F 2863.46 1431.73 715.86
F#/Gb 2702.74 1351.37 675.69
G 2551.05 1275.53 637.76
G#/Ab 2407.87 1203.94 601.97
Cycle(s) for 500kHz clock
A 9091 4545 2273
A#/Bb 8581 4290 2145
B 8099 4050 2025
C 7645 3822 1911
C#/Db 7215 3608 1804
D 6810 3405 1703
D#/Eb 6428 3214 1607
E 6067 3034 1517
F 5727 2863 1432
F#/Gb 5405 2703 1351
G 5102 2551 1276
G#/Ab 4816 2408 1204
*****************************************/
int beep_delay = 1 ; // 1 ~ 12
int sound_current_diff = 1 ;
int sound_sequence = 0 ;
int bite_volume_first_note = 2273 ; /* 50% duty */
int bite_first_note = 4545 ; /* A 440Hz for 500kHz clock */
int bite_volume_second_note = 1137 ; /* 50% duty */
int bite_second_note = 2273 ; /* A 880Hz for 500kHz clock */
int sounder_running_flag = 0 ;
int sequence_flag = 0 ;
void SounderRoutine()
{
beep_delay = abs(sound_current_diff) ;
if (beep_delay >= 12) beep_delay = 12 ; // limit current diff
switch(sound_sequence) {
case 0:
SOUND_PWM_Stop() ;
case 1:
SOUND_PWM_WriteCompare(bite_volume_first_note) ; // Volume First Note
SOUND_PWM_WritePeriod(bite_first_note) ; // Frequency
SOUND_PWM_Start() ;
SOUNDER_SEQUENCE_Stop() ;
SOUNDER_SEQUENCE_WritePeriod(220 / beep_delay+1 ) ;
SOUNDER_SEQUENCE_WriteCounter(0) ;
SOUNDER_SEQUENCE_Start() ;
sound_sequence = 2 ;
break ;
case 2:
//if (beep_delay >= 8 && max_speed_sounder_pulse == SOUNDER_SINGLE) brea ;
SOUND_PWM_Stop() ;
case 3:
SOUND_PWM_WriteCompare(bite_volume_second_note) ;
SOUND_PWM_WritePeriod(bite_second_note) ;
SOUND_PWM_Start() ;
SOUNDER_SEQUENCE_Stop() ;
SOUNDER_SEQUENCE_WritePeriod(220 / beep_delay+1) ;
SOUNDER_SEQUENCE_WriteCounter(0) ;
SOUNDER_SEQUENCE_Start() ;
sound_sequence = 4 ;
break ;
case 4:
// SOUND_PWM_WriteCompare(0) ;
SOUNDER_SEQUENCE_Stop() ;
SOUNDER_SEQUENCE_WritePeriod(10) ;
SOUNDER_SEQUENCE_WriteCounter(0) ;
SOUND_PWM_Stop() ;
sound_sequence = 0 ;
sounder_running_flag = 0 ;
break ;
}
}
CY_ISR(sequence_isr)
{
SOUNDER_SEQUENCE_ClearInterrupt(SOUNDER_SEQUENCE_TC_INTERRUPT_MASK) ;
sequence_flag = 1 ;
}
int main(void)
{
char str[64] ;
CyGlobalIntEnable; /* Enable global interrupts. */
UART_Start() ;
sprintf(str, "Timer Test Program (%s %s) started\n", __DATE__, __TIME__) ;
UART_UartPutString(str) ;
SOUND_PWM_WriteCompare(0) ;
SOUND_PWM_Start() ;
Sounder_Sequence_int_StartEx(sequence_isr) ;
SOUNDER_SEQUENCE_Start() ;
sequence_flag = 1 ;
for(;;) {
if (sequence_flag) {
sprintf(str, "Sequence %d\n", sound_sequence) ;
UART_UartPutString(str) ;
SounderRoutine() ;
sequence_flag = 0 ;
}
}
}
/* [] END OF FILE */
============================
Attached is my trial with CY8CKIT-044.
After archiving the project, I noticed that I mis-spelled the project,
I meant pit (periodical interrupt timer) but it ended up to "pti",
but the name does not affect the function (I hope).
moto
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hi David,
Could you please share your project file focusing on the problem so that I can try to replicate the issue from my side.
Regards,
Bragadeesh
Bragadeesh
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
HI
Sorry the problem was not the timer it appears to be the UDB PWM and specifically waking up from deep sleep I notice there is a problem with this on the internet can anyone please supply me with a solution?.
Regards
David
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hi David,
Can you please elaborate your problem? Kindly create a new project file, copy and paste the code that is focusing the problem, so that we can find the issue quicker and resolve them.
Regards,
Bragadeesh
Bragadeesh