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
Dear All,
On analog circuit thread I asked about injector pulser which I created by using 555 chip. Now I want to step to microcontroller world as I find it fascinating. I've done some c-programming (not embedded) about 14 years ago so why not give it a go. I ordered pickit 2 starter kit and few 12F683 chips. I was planning to create injector pulser which uses PWM and has variable on time selection by button. I have few doubts which I haven't found answer yet. Firstly I see that I should use external chrystal for oscillator. If I've understood right this chip does have one built in? This external chrystal does 4MHz work? This is what I don't quite understand what freq should it be..
Second, should the button pull input pin to ground to work or +5VDC?
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?
Last but not least as I'm not familiar with the embedded systems and handling those inputs and outputs are not fully clear to me, am I handling ports right here? I find it hard to understand port initializing like this way: TRISIO = 0x03; so I prefer TRISIO.B0 = 1;, hope it's ok? I'm not sure am I allowed to use all these B0,3 & 2 on this chip or not.
Here's the microC complier code
Sorry for the long post and thank you all in advance for helping me out.
On analog circuit thread I asked about injector pulser which I created by using 555 chip. Now I want to step to microcontroller world as I find it fascinating. I've done some c-programming (not embedded) about 14 years ago so why not give it a go. I ordered pickit 2 starter kit and few 12F683 chips. I was planning to create injector pulser which uses PWM and has variable on time selection by button. I have few doubts which I haven't found answer yet. Firstly I see that I should use external chrystal for oscillator. If I've understood right this chip does have one built in? This external chrystal does 4MHz work? This is what I don't quite understand what freq should it be..
Second, should the button pull input pin to ground to work or +5VDC?
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?
Last but not least as I'm not familiar with the embedded systems and handling those inputs and outputs are not fully clear to me, am I handling ports right here? I find it hard to understand port initializing like this way: TRISIO = 0x03; so I prefer TRISIO.B0 = 1;, hope it's ok? I'm not sure am I allowed to use all these B0,3 & 2 on this chip or not.
Here's the microC complier code
Code:
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
}
}
Sorry for the long post and thank you all in advance for helping me out.