PWM and TIMER1 problem in stm32f4
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2016-02-21 3:13 PM
Hello,
I need to generate sin wave using STM32 uC. Now here comes the problem. I am able to obtain the required sin wave with the required frequency and the required amplitude however there are other (more than one) frequency components.After spending some time, I think I have pinpointed my problem down to having something related to 'jitter' in the PWM or phase noise because of a mismatched PWM frequency and sample rate of the lookup table.What do you think? Any help would be appreciated!- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2016-02-21 4:47 PM
Ultimately the machine does what you tell it too, unfortunately I can't see from this what you're physically instructing the machine to do.
Instead of programming the timer, write all the data you generate to a file, and the plot and review that.Up vote any posts that you find helpful, it shows what's working..
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2016-02-23 1:55 PM
I have a sinusoidal lookup table that contains only a 50Hz that I'm using, however I don't know how its not only 50Hz on the capacitor of the lowpass filter. If you need details of the setup see my previous post.
Thanks!- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2016-02-23 5:17 PM
Ok, the key detail missing is the code, something I can compile and follow the logic, I'm not looking to recreate or resolve this for myself.
Up vote any posts that you find helpful, it shows what's working..
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2016-02-24 12:22 PM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2016-02-24 12:47 PM
Your update interrupt looks really dodgy
//update sin sample on overflow only if(htim8.Instance->CNT > 3000){ //... And 4200 is half of 8400 Needs to beif (__HAL_TIM_GET_IT_SOURCE(&htim8, TIM_IT_UPDATE))
{
__HAL_TIM_CLEAR_IT(&htim8, TIM_IT_UPDATE);
if (sin_index >= 200)
sin_index = 0;
__HAL_TIM_SetCompare(&htim8, TIM_CHANNEL_1, 4200 + sin_wave_50hz[sin_index++]); //4200 = PERIOD/2 = 8400/2
}
Up vote any posts that you find helpful, it shows what's working..
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2016-02-24 1:14 PM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2016-02-24 3:45 PM
I'm not sure how it is going to underflow, the update occurs once per period, ie at 10 KHz
Realistically this could be done with DMA and be completely autonomous.Up vote any posts that you find helpful, it shows what's working..
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2016-02-24 5:15 PM
Other thoughts, the Period should be N-1, the TIM8 will run at 168 MHz
Attached is a .HEX that drives PC6 (TIM8_CH1) and PA7 (TIM8_CH1N), this should generate a 50 Hz sine wave via a 10 KHz PWM. Please see if this generate the wave form you expect. ________________ Attachments : PWM8_50HZ_REL1.hex : https://st--c.eu10.content.force.com/sfc/dist/version/download/?oid=00Db0000000YtG6&ids=0680X000006I12Q&d=%2Fa%2F0X0000000bhN%2FAlv3B8cCDLf9hMbKFwEV.s6SQFd0RrtTqBJiz4KPsl8&asPdf=falseUp vote any posts that you find helpful, it shows what's working..
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2016-02-24 10:13 PM
Underflow can occur because I have my timer running in up-down mode counter.
