View previous topic :: View next topic |
Author |
Message |
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Thu May 12, 2011 1:21 pm |
|
|
I tested the code below with vs. 4.093 and it works. I get a squarewave
on pins C2 and D5. The signal on D5 is in-phase with the signal on pin C2.
The frequency of both signals is 244 Hz. The duty cycle appears to be
approximately 50% on my scope. The pulses are high for about 2ms and
low for about 2ms.
The deadband zone is small, compared to the duty cycle. You have to
put the scope on x10 Mag to see it. I measured the deadband at 127us
on the scope. So it's working. This was tested on a PicDem2-Plus board
(non-Rohs version).
Code: |
#include <16F887.H>
#fuses INTRC_IO,NOWDT,BROWNOUT,PUT,NOLVP
#use delay(clock=4M)
#define P1B PIN_D5
void set_deadband(int8 deadband)
{
#byte PWM1CON = 0x9B
if(deadband > 127)
deadband == 127;
PWM1CON = deadband;
}
//======================================
void main()
{
setup_timer_2(T2_DIV_BY_16, 255, 1);
setup_ccp1(CCP_PWM_HALF_BRIDGE | CCP_PWM_H_L );
output_low(P1B);
set_pwm1_duty(125);
set_deadband(127);
while(1);
}
|
|
|
|
aliaj00
Joined: 11 May 2011 Posts: 24
|
|
Posted: Sat May 14, 2011 6:29 pm |
|
|
HI PCM
i tried this code for testing.
Code: |
#include "D:\documents and settings\Administrator\Application Data\PICC\Projects\soft-pwm.h"
//#include <pic.h>
void main()
{
char period;
char frequency;
setup_adc_ports(NO_ANALOGS|VSS_VDD);
setup_adc(ADC_CLOCK_DIV_2);
setup_spi(SPI_SS_DISABLED);
setup_timer_0(RTCC_INTERNAL|RTCC_DIV_1);
setup_timer_1(T1_DISABLED);
setup_timer_2(T2_DISABLED,0,1);
setup_ccp1(CCP_OFF);
setup_comparator(NC_NC_NC_NC);// This device COMP currently not supported by the PICWizard
//TODO: User Code
while (1)
{
/* putc("vendos perioden");
getc(period);
putc("vendos frekuencen");
getc(frequency);
*/
output_low(PIN_B6);
output_low(PIN_B5);
///
output_high(PIN_B5);
delay_ms (15);
output_low(PIN_B5);
delay_ms (2);
//
output_high(PIN_B6);
delay_ms(15);
output_low(PIN_B6);
delay_ms(2);
delay_ms(5);
}
}
|
it does the job as i need half bridge so dead time just a delay between turning on the pins. also this way i can set the time between repetitive strokes much bigger on the last command delay_ms(5);
i am having a issue. with the scope i am checking the off voltage on both pins and is not zero but 850mV. i am using darlington as driver so it is not big deal but still confusing me enough to ask. i have the darlington's with common ground with the PIC and there is not more than 4mV on the supply line.
Any idea???
thanks a lot for testing |
|
|
aliaj00
Joined: 11 May 2011 Posts: 24
|
|
Posted: Sat May 14, 2011 6:52 pm |
|
|
:P found it was the reverse diode at the 7805. :P. i should have seen it. |
|
|
aliaj00
Joined: 11 May 2011 Posts: 24
|
|
Posted: Sat May 14, 2011 6:56 pm |
|
|
also cleaned the code now it looks now:
Code: |
#include "D:\documents and settings\Administrator\Application Data\PICC\Projects\soft-pwm.h"
//#include <pic.h>
void main()
{
char period;
char frequency;
setup_adc_ports(NO_ANALOGS|VSS_VDD);
setup_adc(ADC_CLOCK_DIV_2);
setup_spi(SPI_SS_DISABLED);
setup_timer_0(RTCC_INTERNAL|RTCC_DIV_1);
setup_timer_1(T1_DISABLED);
setup_timer_2(T2_DISABLED,0,1);
setup_ccp1(CCP_OFF);
setup_comparator(NC_NC_NC_NC);// This device COMP currently not supported by the PICWizard
//TODO: User Code
output_low(PIN_B1);
output_low(PIN_B3);
while (1)
{
/* putc("vendos perioden");
getc(period);
putc("vendos frekuencen");
getc(frequency);
*/
//output_low(PIN_B6);
//output_low(PIN_B5);
///
output_high(PIN_B1);
delay_us (50);
output_low(PIN_B1);
delay_us (5);
//
output_high(PIN_B3);
delay_us(50);
output_low(PIN_B3);
//delay_us(2);
delay_us(75);
}
}
|
signal attached have some interference from both channels :( |
|
|
aliaj00
Joined: 11 May 2011 Posts: 24
|
|
Posted: Sat May 14, 2011 7:00 pm |
|
|
dont know how to attach screenshot here |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Sat May 14, 2011 7:28 pm |
|
|
Go to a free image hosting service such as http://www.imageshack.com
and post it there. Then post the link here. |
|
|
aliaj00
Joined: 11 May 2011 Posts: 24
|
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Sun May 15, 2011 12:27 pm |
|
|
Post your schematic. |
|
|
aliaj00
Joined: 11 May 2011 Posts: 24
|
|
Posted: Mon May 16, 2011 1:33 am |
|
|
It is just the pic debugger with the 16F887 on it. and on RB1 RB3 there are the darlington with 500 Ohm resistance on the base. I didn't made a schematic for it as it has fewer than 10 Elements. |
|
|
aliaj00
Joined: 11 May 2011 Posts: 24
|
|
Posted: Mon May 16, 2011 2:58 am |
|
|
Hi PCM programmer,
how can i insert a rs232 into the code to change the parameters but not to loop through it in the while statement, as i will be forced to enter an answer each time.
BR's
shpetim Aliaj |
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19505
|
|
Posted: Mon May 16, 2011 4:12 am |
|
|
Basic technique. Two 'modes' of operation.
'Normal' mode. Sit in your loop, and at one point do a 'kbhit'.
If this is true, read the single character from the serial. Then have a 'decision', so if (for example), the character 'C' is there, you switch to 'config' mode.
Then send a little prompt for the data you want, and read the return. With a bit of ingenuity (again kbhit, and a timer), you can have it that if no reply is seen in say 30 seconds, the code automatically returns to 'normal' mode.
On your circuit, what are the darlington's actually driving?. Is it inductive?. If so, what circuitry have you got to trap the energy stored in the inductor, when the transistors switch off?.
Best Wishes |
|
|
aliaj00
Joined: 11 May 2011 Posts: 24
|
|
Posted: Mon May 16, 2011 6:55 am |
|
|
the darlington are 2SD2390 each with 10 AMP of load or more. i attached the metallic radiator to them and also a cooler on each one of them as the heat generated was burning them "with only metallic radiator". i have tried with all loads, pure heater from old oven :P, Big COIL 2.5MM2 100 turns etc to test it. they have a diode from what i remember. i am not sure need to check. |
|
|
aliaj00
Joined: 11 May 2011 Posts: 24
|
|
Posted: Mon May 16, 2011 6:56 am |
|
|
i have tested in the 5.06Khz to 32 khz |
|
|
aliaj00
Joined: 11 May 2011 Posts: 24
|
|
Posted: Mon May 16, 2011 6:59 am |
|
|
can i put a push button on it and generate a interrupt so when i want to update the timing i can trigger the rs232 code and than to have it running without the rs232 routine.
BR's
Shpetim Aliaj |
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19505
|
|
Posted: Mon May 16, 2011 7:30 am |
|
|
No point in using an interrupt. Just have one instruction in your loop, testing if the input pin is in the 'active' state. If it is, switch to the config mode.
This is exactly like 'bootloader' code, where as the chip wakes up, an input pin is tested, and if it is in the active state, the code switches to the bootloader. Zero point (and several potential problems), trying to use an interrupt for this. Much simpler just to poll the pin.
Best Wishes |
|
|
|