Roberto C
Newbie level 1
- Joined
- Sep 13, 2014
- Messages
- 1
- Helped
- 0
- Reputation
- 0
- Reaction score
- 0
- Trophy points
- 1
- Activity points
- 7
Hi,
I am a newbie and i have a stm32 evaluation board (stm32 discovery) and i would like learn to program it. This board mount a stm32f100RB. I want generate a PWM wave on the output Port C, PC8 (there is a Led in this output) but i have a problem. I read the user manual and wrote the code but i don't have my PWM in output
Who could you help me please?
It's my code wrote with keil uVision:
What is my mistake ??
What is the right code ??
Thank you so much.
I am a newbie and i have a stm32 evaluation board (stm32 discovery) and i would like learn to program it. This board mount a stm32f100RB. I want generate a PWM wave on the output Port C, PC8 (there is a Led in this output) but i have a problem. I read the user manual and wrote the code but i don't have my PWM in output
Who could you help me please?
It's my code wrote with keil uVision:
Code:
#include <stm32f10x.h>
void setup(void);
int main() {
setup();
while(1){}
}
void setup(void){
/* CONFIGURATION CLOCK (Schema a blocchi da cui vedere i registri da configurare Pag 70)
Informazioni sul Registro RCC a pag 80 - AHB e APB1 Pag 85 */
RCC->CFGR=RCC_CFGR_SW_HSI ; // 1. Setto clock interno SYSCLK a 8MHz tramite uso del HSI High Speed Internal Ocillator
RCC->CFGR=RCC_CFGR_HPRE_DIV1; // 2. Nessuna divisione del SYSCLK, questo registro è il AHB (o HPRE)
RCC->CFGR=RCC_CFGR_PPRE1_DIV1; // 3. Nessuna divisione del SYSCLK, questo registro è l' APB1 prescaler
RCC->APB1ENR=RCC_APB1ENR_TIM3EN; // 4. Abilitazione TIMER 3
AFIO->MAPR=AFIO_MAPR_TIM3_REMAP_FULLREMAP; /* Imposto il timer3 al canale PC8!< Full remap (CH1/ETR/PA15, CH2/PB3, CH3/PB10, CH4/PB11) */
// RCC->CFGR=RCC_CFGR_SWS_HSI ; // Setto clock interno a 8MHz con HSI oscillator interno
/* Procedura per configurare il TIMER 4 per avere in uscita una PWM a 4Hz pag 274-287 manuale (schema a pag 276 e 294) */
TIM3->SMCR|=TIM_SMCR_SMS; // 1. Impostazione dell'internal trigger come Slave (importante !) Pag 306
TIM3->PSC=0xC350; // 2. Il clock principale è CK_INT=8MHz, setto il prescaler a 50000 ottenendo CK_CNT=160Hz PAG 279
TIM3->ARR|=((uint16_t)0x0050); // 3. ARR regola la Freq, setto il valore del autoreload a 80 ( per avere 2 periodi in 160 Hz perché ogni 80 ricomincia) Pag 277
TIM3->CCR1|=((uint16_t)0x0028); // 4. CCR regola il duty cicle, regolo il valore a 40 ( per avere un DC al 50%)
TIM3->CCMR1|=TIM_CCMR2_OC3M_1; // 5. Configurazione PWM in mode 1 OCxM=110 bit 2 a 1 Pag 295
TIM3->CCMR1|=TIM_CCMR2_OC3M_2; // 6. Configurazione PWM in mode 1 OCxM=110 bit 3 a 1 Pag 295
TIM3->CCMR1|=TIM_CCMR2_OC3PE ; // 7. Abilitazione preload register Pag 295
TIM3->CCER=TIM_CCER_CC3P; // 8. Setting della polarità positiva del registro OCx Pag 295
TIM3->EGR|= TIM_EGR_UG; // 9. Generazione dell'Update event che carica i registri Pag 295
TIM3->CR1|=TIM_CR1_CEN; // 10. TIM_CR1_CEN corrisponde a ((uint16_t)0x0001) Counter enable Pag 306
TIM3->CCER=TIM_CCER_CC3E; // 11. Abilitazione dell'uscita OC3 Pag 295
TIM3->CR1=TIM_CR1_ARPE; // 12. Abilitazione del autoload Register Pag 277
TIM3->CNT=TIM_CR1_CEN; // 13. Abilitazione del Counter CNT
}
What is my mistake ??
What is the right code ??
Thank you so much.