Veketti
Full Member level 3
- Joined
- Sep 14, 2014
- Messages
- 164
- Helped
- 0
- Reputation
- 0
- Reaction score
- 0
- Trophy points
- 16
- Activity points
- 1,700
sbit Time_button at GP0_bit;
sbit Start_button at GP3_bit;
sbit Output at GP2_bit;
short times;
short i;
long milliseconds;
void InitMain(void) {
TRISIO.B2 = 0; // Set GP2 (pin 5) as output
TRISIO.B3 = 1; // Set GP3 as input. Not needed as it's input only?
TRISIO.B0 = 1; // Set GP0 as input
PWM1_Init(250); // Set 250hZ frequency
PWM1_set_duty(127); // set 50% duty cycle
}
void main(void) {
InitMain();
times = 1; // Variable how many times button pressed
while(1){
if(!Time_button) // When time button is pressed
{
if (times > 11) times = 1; // Maximum time for pulsing is 55seconds
for(i=0 ; i<times ; i++){ // Tell how many seconds * 5 it will pulse by switching solenoid on
Output = 1;
delay_ms(200);
Output = 0;
}
times++;
}
if(!Start_button) // When start button is pressed
{
milliseconds = 5*times*1000; // Convert time to milliseconds
PWM1_Start();
Vdelay_ms(milliseconds); // Pulse Output for given time
PWM1_Stop();
}
delay_ms(10); // Delay 10ms until next round
}
}
Do I have any benefits on using external crystal?the PIC12F683 has an internal precision 8Mhz (and 32KHz) oscillator - you can use this or an external crystal
your button can pull down to 0v or up to +5v so long as your program knows which is button pressed/not pressed
I mean that I'm not able to set any lower frequency for the PWM than 250Hz. This line:I don't understand what you mean by
Thirdly, I'm only able to go down to 250Hz on frequency for the PWM. Tried to search this from datasheet but didn't succeed. Is there any other way to have eg.30Hz as frequency?
Do I have any benefits on using external crystal?
I mean that I'm not able to set any lower frequency for the PWM than 250Hz. This line:
PWM1_Init(250); // Set 250hZ frequency
I would want to have it PWM1_Init(30); but I get compiler error that "Argument is out of range". Why so and any other way to have it 30?
Code C - [expand] 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 void main() { OSCCON = 0x31; //OSCTUNE = 0x0F; T2CON = 0x07; PR2 = 0x81; CCP1CON = 0b00001101; Delay_ms(200); TRISIO = 0x00; GPIO = 0x00; PWM1_Set_Duty(127); PWM1_Start(); while(1); }
Is there any harm in making the MCU clock to 0.5MHz (in MicroC Pro, Project settings - MCU Clock - frequency)?
sbit Time_button at GP0_bit;
sbit Start_button at GP3_bit;
sbit Output at GP2_bit;
sbit TimerLed at GP1_bit;
short times;
short i;
long milliseconds;
void InitMain(void) {
TRISIO.B2 = 0; // Set GP2 (pin 5) as Output
TRISIO.B1 = 0; // Set GP1 (pin 6) as Output
TRISIO.B3 = 1; // Set GP3 (pin 4) as input. Not needed as it's input only?
TRISIO.B0 = 1; // Set GP0 (pin 7) as input
PWM1_Init(500); // Set 500hZ frequency
PWM1_set_duty(127); // set 50% duty cycle
}
void main(void) {
InitMain();
times = 1; // Variable how many times button pressed
while(1){
if(!Time_button) // When time button is pressed
{
if (times > 11) times = 1; // Maximum time for pulsing is 55seconds
for(i=0 ; i<times ; i++){ // Tell how many seconds * 5 it will pulse by blinking led
TimerLed = 1;
delay_ms(250);
TimerLed = 0;
delay_ms(250);
}
times++;
}
if(!Start_button) // When start button is pressed
{
milliseconds = 5*times*1000; // Convert time to milliseconds
PWM1_Start();
Vdelay_ms(milliseconds); // Pulse Output for given time
PWM1_Stop();
}
delay_ms(10); // Delay 10ms until next round
}
}
Code C - [expand] 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 if(!Time_button) // When time button is pressed { Delay_ms(50); if(!Time_button) // If time button is still pressed { } } //or if(!Time_button) // When time button is pressed { Delay_ms(50); while(!Time_button); // wait here untill time button is released { } }
ANSEL = 0x00;
CMCON0 = 0x07;
GPIO = 0x00;
We use cookies and similar technologies for the following purposes:
Do you accept cookies and these technologies?
We use cookies and similar technologies for the following purposes:
Do you accept cookies and these technologies?